Skip to content

Added error for invalid char cast #143678

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Kivooeo
Copy link
Contributor

@Kivooeo Kivooeo commented Jul 9, 2025

fixes #143597

not really sure if I did it right, but according to cast-char test -- it is right, also this code gave me false positive result

for _ in 0..(256 as u8) {}

so this is why I added this check if lit_val <= 0xFF

Also I believe that error message could be improved, but I'm not sure how exactly

cc @hkBst

r? compiler

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 9, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@Kivooeo Kivooeo force-pushed the char-overflow branch 2 times, most recently from 84cd0b4 to 1260317 Compare July 9, 2025 12:36
@hkBst
Copy link
Member

hkBst commented Jul 9, 2025

I had a few more suggestions, but this is nearing completion: good work!

@Kivooeo Kivooeo force-pushed the char-overflow branch 2 times, most recently from 9cc1707 to 7b17511 Compare July 9, 2025 17:57
Copy link
Member

@hkBst hkBst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few nits left, but fundamentally done.

@hkBst
Copy link
Member

hkBst commented Jul 10, 2025

@fmease your turn ;P

Copy link
Member

@SparrowLii SparrowLii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine and only affects diagnostics.

@SparrowLii
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Jul 16, 2025

📌 Commit 81a6f18 has been approved by SparrowLii

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Jul 16, 2025

🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 16, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 16, 2025
Added error for invalid char cast

fixes rust-lang#143597

not really sure if I did it right, but according to cast-char test -- it is right, also this code gave me false positive result

```
for _ in 0..(256 as u8) {}
```

so this is why I added this check `if lit_val <= 0xFF`

Also I believe that error message could be improved, but I'm not sure how exactly

cc `@hkBst`

r? compiler
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 16, 2025
Added error for invalid char cast

fixes rust-lang#143597

not really sure if I did it right, but according to cast-char test -- it is right, also this code gave me false positive result

```
for _ in 0..(256 as u8) {}
```

so this is why I added this check `if lit_val <= 0xFF`

Also I believe that error message could be improved, but I'm not sure how exactly

cc ``@hkBst``

r? compiler
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 16, 2025
Added error for invalid char cast

fixes rust-lang#143597

not really sure if I did it right, but according to cast-char test -- it is right, also this code gave me false positive result

```
for _ in 0..(256 as u8) {}
```

so this is why I added this check `if lit_val <= 0xFF`

Also I believe that error message could be improved, but I'm not sure how exactly

cc ```@hkBst```

r? compiler
bors added a commit that referenced this pull request Jul 16, 2025
Rollup of 11 pull requests

Successful merges:

 - #143595 (add `const_make_global`; err for `const_allocate` ptrs if didn't call)
 - #143678 (Added error for invalid char cast)
 - #143793 (Opaque type collection: Guard against endlessly recursing free alias types)
 - #143820 (Fixed a core crate compilation failure when enabling the `optimize_for_size` feature on some targets)
 - #143829 (Trim `BorrowedCursor` API)
 - #143856 (Linting public reexport of private dependencies)
 - #143891 (Port `#[coverage]` to the new attribute system)
 - #143914 (Reword mismatched-lifetime-syntaxes text based on feedback)
 - #143922 (Improve path segment joining)
 - #143926 (Remove deprecated fields in bootstrap)
 - #143975 (type_id_eq: check that the hash fully matches the type)

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

overflowing_literals suggests invalid unicode character escape
7 participants