Rollup merge of #72380 - lcnr:const_context, r=estebank
Fix `is_const_context`, update `check_for_cast` A better version of #71477 Adds `fn enclosing_body_owner` and uses it in `is_const_context`. `is_const_context` now uses the same mechanism as `mir_const_qualif` as it was previously incorrect. Renames `is_const_context` to `is_inside_const_context`. I also updated `check_for_cast` in the second commit, so r? @estebank (I removed one lvl of indentation, so it might be easier to review by hiding whitespace changes)
This commit is contained in:
commit
298467ee9a
9 changed files with 236 additions and 253 deletions
|
|
@ -11,10 +11,6 @@ LL | | }
|
|||
| |_- in this macro invocation
|
||||
|
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
help: you can convert an `i32` to `isize` and panic if the converted value wouldn't fit
|
||||
|
|
||||
LL | $( $v = $s::V.try_into().unwrap(), )*
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/enum-discr-type-err.rs:18:21
|
||||
|
|
@ -29,10 +25,6 @@ LL | | }
|
|||
| |_- in this macro invocation
|
||||
|
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
help: you can convert an `i32` to `isize` and panic if the converted value wouldn't fit
|
||||
|
|
||||
LL | $( $v = $s::V.try_into().unwrap(), )*
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -3,11 +3,6 @@ error[E0308]: mismatched types
|
|||
|
|
||||
LL | X = Trait::Number,
|
||||
| ^^^^^^^^^^^^^ expected `isize`, found `i32`
|
||||
|
|
||||
help: you can convert an `i32` to `isize` and panic if the converted value wouldn't fit
|
||||
|
|
||||
LL | X = Trait::Number.try_into().unwrap(),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,11 @@ error[E0308]: mismatched types
|
|||
|
|
||||
LL | const C: i32 = 1i8;
|
||||
| ^^^ expected `i32`, found `i8`
|
||||
|
|
||||
help: change the type of the numeric literal from `i8` to `i32`
|
||||
|
|
||||
LL | const C: i32 = 1i32;
|
||||
| ^^^^
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/const-scope.rs:2:15
|
||||
|
|
@ -17,6 +22,11 @@ LL | let c: i32 = 1i8;
|
|||
| --- ^^^ expected `i32`, found `i8`
|
||||
| |
|
||||
| expected due to this
|
||||
|
|
||||
help: change the type of the numeric literal from `i8` to `i32`
|
||||
|
|
||||
LL | let c: i32 = 1i32;
|
||||
| ^^^^
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/const-scope.rs:6:17
|
||||
|
|
|
|||
|
|
@ -22,6 +22,9 @@ fn main() {
|
|||
let f = [0_usize; -1_isize];
|
||||
//~^ ERROR mismatched types
|
||||
//~| expected `usize`, found `isize`
|
||||
let f = [0; 4u8];
|
||||
//~^ ERROR mismatched types
|
||||
//~| expected `usize`, found `u8`
|
||||
struct G {
|
||||
g: (),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ LL | let e = [0; "foo"];
|
|||
| ^^^^^ expected `usize`, found `&str`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/repeat_count.rs:28:17
|
||||
--> $DIR/repeat_count.rs:31:17
|
||||
|
|
||||
LL | let g = [0; G { g: () }];
|
||||
| ^^^^^^^^^^^ expected `usize`, found struct `main::G`
|
||||
|
|
@ -39,24 +39,25 @@ error[E0308]: mismatched types
|
|||
|
|
||||
LL | let f = [0; -4_isize];
|
||||
| ^^^^^^^^ expected `usize`, found `isize`
|
||||
|
|
||||
help: you can convert an `isize` to `usize` and panic if the converted value wouldn't fit
|
||||
|
|
||||
LL | let f = [0; (-4_isize).try_into().unwrap()];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/repeat_count.rs:22:23
|
||||
|
|
||||
LL | let f = [0_usize; -1_isize];
|
||||
| ^^^^^^^^ expected `usize`, found `isize`
|
||||
|
|
||||
help: you can convert an `isize` to `usize` and panic if the converted value wouldn't fit
|
||||
|
|
||||
LL | let f = [0_usize; (-1_isize).try_into().unwrap()];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 8 previous errors
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/repeat_count.rs:25:17
|
||||
|
|
||||
LL | let f = [0; 4u8];
|
||||
| ^^^ expected `usize`, found `u8`
|
||||
|
|
||||
help: change the type of the numeric literal from `u8` to `usize`
|
||||
|
|
||||
LL | let f = [0; 4usize];
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to 9 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0308, E0435.
|
||||
For more information about an error, try `rustc --explain E0308`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue