Detect negative literal inferred to unsigned integer#146042
Merged
bors merged 2 commits intorust-lang:masterfrom Sep 1, 2025
Merged
Detect negative literal inferred to unsigned integer#146042bors merged 2 commits intorust-lang:masterfrom
bors merged 2 commits intorust-lang:masterfrom
Conversation
```
error[E0277]: the trait bound `usize: Neg` is not satisfied
--> $DIR/negative-literal-infered-to-unsigned.rs:2:14
|
LL | for x in -5..5 {
| ^^ the trait `Neg` is not implemented for `usize`
|
help: consider specifying an integer type that can be negative
|
LL | for x in -5isize..5 {
| +++++
```
Collaborator
lcnr
reviewed
Aug 31, 2025
| trait_pred: ty::PolyTraitPredicate<'tcx>, | ||
| err: &mut Diag<'_>, | ||
| ) -> bool { | ||
| if let ObligationCauseCode::BinOp { lhs_hir_id, .. } = obligation.cause.code() |
Contributor
There was a problem hiding this comment.
while you're here, can you change ObligationCauseCode to not just be BinOp 😅 that's horribly confusing.
Looking at the way it's used I think it'd be better to just split it into ObligationCauseCode::UnOp and ObligationCauseCode::BinOp
lcnr
reviewed
Aug 31, 2025
Contributor
Author
|
@bors r=lcnr |
Collaborator
Zalathar
added a commit
to Zalathar/rust
that referenced
this pull request
Sep 1, 2025
Detect negative literal inferred to unsigned integer
```
error[E0277]: the trait bound `usize: Neg` is not satisfied
--> $DIR/negative-literal-infered-to-unsigned.rs:2:14
|
LL | for x in -5..5 {
| ^^ the trait `Neg` is not implemented for `usize`
|
help: consider specifying an integer type that can be negative
|
LL | for x in -5isize..5 {
| +++++
```
Applying this suggestion will always end up in another E0308 error at the point where the unsigned inference comes from, which should help with understanding what the actual problem is.
Fix rust-lang#83413.
bors
added a commit
that referenced
this pull request
Sep 1, 2025
Rollup of 6 pull requests Successful merges: - #145421 (`dump_mir` cleanups) - #145968 (Add `Bound::copied`) - #146004 (resolve: Refactor `struct ExternPreludeEntry`) - #146042 (Detect negative literal inferred to unsigned integer) - #146046 (Suggest method name with maybe ty mismatch) - #146051 (Change std f32 test to pass under Miri) r? `@ghost` `@rustbot` modify labels: rollup
rust-timer
added a commit
that referenced
this pull request
Sep 1, 2025
Rollup merge of #146042 - estebank:issue-83413, r=lcnr Detect negative literal inferred to unsigned integer ``` error[E0277]: the trait bound `usize: Neg` is not satisfied --> $DIR/negative-literal-infered-to-unsigned.rs:2:14 | LL | for x in -5..5 { | ^^ the trait `Neg` is not implemented for `usize` | help: consider specifying an integer type that can be negative | LL | for x in -5isize..5 { | +++++ ``` Applying this suggestion will always end up in another E0308 error at the point where the unsigned inference comes from, which should help with understanding what the actual problem is. Fix #83413.
Kobzol
pushed a commit
to Kobzol/rustc_codegen_cranelift
that referenced
this pull request
Dec 29, 2025
Rollup of 6 pull requests Successful merges: - rust-lang/rust#145421 (`dump_mir` cleanups) - rust-lang/rust#145968 (Add `Bound::copied`) - rust-lang/rust#146004 (resolve: Refactor `struct ExternPreludeEntry`) - rust-lang/rust#146042 (Detect negative literal inferred to unsigned integer) - rust-lang/rust#146046 (Suggest method name with maybe ty mismatch) - rust-lang/rust#146051 (Change std f32 test to pass under Miri) r? `@ghost` `@rustbot` modify labels: rollup
christian-schilling
pushed a commit
to christian-schilling/rustc_codegen_cranelift
that referenced
this pull request
Jan 27, 2026
Rollup of 6 pull requests Successful merges: - rust-lang/rust#145421 (`dump_mir` cleanups) - rust-lang/rust#145968 (Add `Bound::copied`) - rust-lang/rust#146004 (resolve: Refactor `struct ExternPreludeEntry`) - rust-lang/rust#146042 (Detect negative literal inferred to unsigned integer) - rust-lang/rust#146046 (Suggest method name with maybe ty mismatch) - rust-lang/rust#146051 (Change std f32 test to pass under Miri) r? `@ghost` `@rustbot` modify labels: rollup
christian-schilling
pushed a commit
to christian-schilling/rustc_codegen_cranelift
that referenced
this pull request
Jan 27, 2026
Rollup of 6 pull requests Successful merges: - rust-lang/rust#145421 (`dump_mir` cleanups) - rust-lang/rust#145968 (Add `Bound::copied`) - rust-lang/rust#146004 (resolve: Refactor `struct ExternPreludeEntry`) - rust-lang/rust#146042 (Detect negative literal inferred to unsigned integer) - rust-lang/rust#146046 (Suggest method name with maybe ty mismatch) - rust-lang/rust#146051 (Change std f32 test to pass under Miri) r? `@ghost` `@rustbot` modify labels: rollup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Applying this suggestion will always end up in another E0308 error at the point where the unsigned inference comes from, which should help with understanding what the actual problem is.
Fix #83413.