-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Detect negative literal inferred to unsigned integer #146042
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
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 { | +++++ ```
trait_pred: ty::PolyTraitPredicate<'tcx>, | ||
err: &mut Diag<'_>, | ||
) -> bool { | ||
if let ObligationCauseCode::BinOp { lhs_hir_id, .. } = obligation.cause.code() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me after handling my comment
@bors 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 rust-lang#83413.
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
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.
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.