Skip to content

Commit 9d862de

Browse files
committed
Note expr being cast when encounter NonScalar cast error
Signed-off-by: xizheyin <[email protected]>
1 parent a18d29f commit 9d862de

36 files changed

+85
-0
lines changed

compiler/rustc_hir_typeck/src/cast.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,15 @@ impl<'a, 'tcx> CastCheck<'tcx> {
408408
self.expr_ty,
409409
fcx.ty_to_string(self.cast_ty)
410410
);
411+
412+
if let Ok(snippet) = fcx.tcx.sess.source_map().span_to_snippet(self.expr_span) {
413+
err.note(format!(
414+
"casting expr `{}` as `{}`",
415+
snippet,
416+
fcx.ty_to_string(self.cast_ty)
417+
));
418+
}
419+
411420
let mut sugg = None;
412421
let mut sugg_mutref = false;
413422
if let ty::Ref(reg, cast_ty, mutbl) = *self.cast_ty.kind() {

tests/ui/cast/cast-from-nil.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0605]: non-primitive cast: `()` as `u32`
33
|
44
LL | fn main() { let u = (assert!(true) as u32); }
55
| ^^^^^^^^^^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
6+
|
7+
= note: casting expr `assert!(true)` as `u32`
68

79
error: aborting due to 1 previous error
810

tests/ui/cast/cast-to-bare-fn.stderr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ error[E0605]: non-primitive cast: `fn(isize) {foo}` as `extern "C" fn() -> isize
33
|
44
LL | let x = foo as extern "C" fn() -> isize;
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid cast
6+
|
7+
= note: casting expr `foo` as `extern "C" fn() -> isize`
68

79
error[E0605]: non-primitive cast: `u64` as `fn(isize) -> (isize, isize)`
810
--> $DIR/cast-to-bare-fn.rs:7:13
911
|
1012
LL | let y = v as extern "Rust" fn(isize) -> (isize, isize);
1113
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid cast
14+
|
15+
= note: casting expr `v` as `fn(isize) -> (isize, isize)`
1216

1317
error: aborting due to 2 previous errors
1418

tests/ui/cast/cast-to-nil.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0605]: non-primitive cast: `u32` as `()`
33
|
44
LL | fn main() { let u = 0u32 as (); }
55
| ^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
6+
|
7+
= note: casting expr `0u32` as `()`
68

79
error: aborting due to 1 previous error
810

tests/ui/cast/enum-to-numeric-cast.stderr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ error[E0605]: non-primitive cast: `NotUnitOnlyOrFieldless` as `isize`
44
LL | let _ = not_unit_only_or_fieldless as isize;
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ an `as` expression can be used to convert enum types to numeric types only if the enum type is unit-only or field-less
66
|
7+
= note: casting expr `not_unit_only_or_fieldless` as `isize`
78
= note: see https://doc.rust-lang.org/reference/items/enumerations.html#casting for more information
89

910
error[E0605]: non-primitive cast: `NotUnitOnlyOrFieldless` as `i32`
@@ -12,6 +13,7 @@ error[E0605]: non-primitive cast: `NotUnitOnlyOrFieldless` as `i32`
1213
LL | let _ = not_unit_only_or_fieldless as i32;
1314
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ an `as` expression can be used to convert enum types to numeric types only if the enum type is unit-only or field-less
1415
|
16+
= note: casting expr `not_unit_only_or_fieldless` as `i32`
1517
= note: see https://doc.rust-lang.org/reference/items/enumerations.html#casting for more information
1618

1719
error[E0605]: non-primitive cast: `NotUnitOnlyOrFieldless` as `usize`
@@ -20,6 +22,7 @@ error[E0605]: non-primitive cast: `NotUnitOnlyOrFieldless` as `usize`
2022
LL | let _ = not_unit_only_or_fieldless as usize;
2123
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ an `as` expression can be used to convert enum types to numeric types only if the enum type is unit-only or field-less
2224
|
25+
= note: casting expr `not_unit_only_or_fieldless` as `usize`
2326
= note: see https://doc.rust-lang.org/reference/items/enumerations.html#casting for more information
2427

2528
error[E0605]: non-primitive cast: `NotUnitOnlyOrFieldless` as `u32`
@@ -28,6 +31,7 @@ error[E0605]: non-primitive cast: `NotUnitOnlyOrFieldless` as `u32`
2831
LL | let _ = not_unit_only_or_fieldless as u32;
2932
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ an `as` expression can be used to convert enum types to numeric types only if the enum type is unit-only or field-less
3033
|
34+
= note: casting expr `not_unit_only_or_fieldless` as `u32`
3135
= note: see https://doc.rust-lang.org/reference/items/enumerations.html#casting for more information
3236

3337
error: aborting due to 4 previous errors

tests/ui/cast/fat-ptr-cast.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ error[E0605]: non-primitive cast: `Box<[i32]>` as `usize`
3535
|
3636
LL | b as usize;
3737
| ^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
38+
|
39+
= note: casting expr `b` as `usize`
3840

3941
error[E0606]: casting `*const [i32]` as `usize` is invalid
4042
--> $DIR/fat-ptr-cast.rs:15:5

tests/ui/cast/func-pointer-issue-140491.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0605]: non-primitive cast: `&for<'a, 'b> fn(&'a Event<'b>) {my_fn}` as `&
33
|
44
LL | ..._>) = &my_fn as _;
55
| ^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
6+
|
7+
= note: casting expr `&my_fn` as `&for<'a, 'b> fn(&'a Event<'b>)`
68

79
error: aborting due to 1 previous error
810

tests/ui/cast/issue-106883-is-empty.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ error[E0605]: non-primitive cast: `String` as `bool`
1616
LL | let _ = String::from("foo") as bool;
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
1818
|
19+
= note: casting expr `String::from("foo")` as `bool`
1920
note: this expression `Deref`s to `str` which implements `is_empty`
2021
--> $DIR/issue-106883-is-empty.rs:17:13
2122
|
@@ -33,6 +34,7 @@ error[E0605]: non-primitive cast: `Foo` as `bool`
3334
LL | let _ = Foo as bool;
3435
| ^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
3536
|
37+
= note: casting expr `Foo` as `bool`
3638
note: this expression `Deref`s to `[u8]` which implements `is_empty`
3739
--> $DIR/issue-106883-is-empty.rs:20:13
3840
|

tests/ui/cast/issue-10991.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0605]: non-primitive cast: `()` as `usize`
33
|
44
LL | let _t = nil as usize;
55
| ^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
6+
|
7+
= note: casting expr `nil` as `usize`
68

79
error: aborting due to 1 previous error
810

tests/ui/cast/issue-84213.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ error[E0605]: non-primitive cast: `Something` as `*const Something`
44
LL | let _pointer_to_something = something as *const Something;
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid cast
66
|
7+
= note: casting expr `something` as `*const Something`
78
help: consider borrowing the value
89
|
910
LL | let _pointer_to_something = &something as *const Something;
@@ -15,6 +16,7 @@ error[E0605]: non-primitive cast: `Something` as `*mut Something`
1516
LL | let _mut_pointer_to_something = something as *mut Something;
1617
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid cast
1718
|
19+
= note: casting expr `something` as `*mut Something`
1820
help: consider borrowing the value
1921
|
2022
LL | let _mut_pointer_to_something = &mut something as *mut Something;

tests/ui/cast/issue-88621.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ error[E0605]: non-primitive cast: `Kind2` as `u8`
44
LL | let _ = Kind2::Foo() as u8;
55
| ^^^^^^^^^^^^^^^^^^ an `as` expression can be used to convert enum types to numeric types only if the enum type is unit-only or field-less
66
|
7+
= note: casting expr `Kind2::Foo()` as `u8`
78
= note: see https://doc.rust-lang.org/reference/items/enumerations.html#casting for more information
89

910
error: aborting due to 1 previous error

tests/ui/cast/issue-89497.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ error[E0605]: non-primitive cast: `*const i32` as `&'static i32`
44
LL | let _reference: &'static i32 = unsafe { pointer as *const i32 as &'static i32 };
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid cast
66
|
7+
= note: casting expr `pointer as *const i32` as `&'static i32`
78
help: consider borrowing the value
89
|
910
LL - let _reference: &'static i32 = unsafe { pointer as *const i32 as &'static i32 };

tests/ui/closures/closure-no-fn-3.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ error[E0605]: non-primitive cast: `{closure@$DIR/closure-no-fn-3.rs:6:28: 6:30}`
44
LL | let baz: fn() -> u8 = (|| { b }) as fn() -> u8;
55
| ^^^^^^^^^^^^^^^^^^^^^^^^ invalid cast
66
|
7+
= note: casting expr `(|| { b })` as `fn() -> u8`
78
note: closures can only be coerced to `fn` types if they do not capture any variables
89
--> $DIR/closure-no-fn-3.rs:6:33
910
|

tests/ui/coercion/coerce-to-bang-cast.stderr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ error[E0605]: non-primitive cast: `i32` as `!`
33
|
44
LL | let y = {return; 22} as !;
55
| ^^^^^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
6+
|
7+
= note: casting expr `{return; 22}` as `!`
68

79
error[E0605]: non-primitive cast: `i32` as `!`
810
--> $DIR/coerce-to-bang-cast.rs:9:13
911
|
1012
LL | let y = 22 as !;
1113
| ^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
14+
|
15+
= note: casting expr `22` as `!`
1216

1317
error: aborting due to 2 previous errors
1418

tests/ui/coercion/issue-73886.stderr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ error[E0605]: non-primitive cast: `&&[i32; 1]` as `&[_]`
33
|
44
LL | let _ = &&[0] as &[_];
55
| ^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
6+
|
7+
= note: casting expr `&&[0]` as `&[_]`
68

79
error[E0605]: non-primitive cast: `u32` as `Option<_>`
810
--> $DIR/issue-73886.rs:4:13
911
|
1012
LL | let _ = 7u32 as Option<_>;
1113
| ^^^^^^^^^^^^^^^^^
1214
|
15+
= note: casting expr `7u32` as `Option<_>`
1316
= note: an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
1417
help: consider using the `From` trait instead
1518
|

tests/ui/coercion/non-primitive-cast-135412.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ error[E0605]: non-primitive cast: `u32` as `Option<_>`
44
LL | let _ = 7u32 as Option<_>;
55
| ^^^^^^^^^^^^^^^^^
66
|
7+
= note: casting expr `7u32` as `Option<_>`
78
= note: an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
89
help: consider using the `From` trait instead
910
|
@@ -17,6 +18,7 @@ error[E0605]: non-primitive cast: `&'static str` as `Arc<str>`
1718
LL | let _ = "String" as Arc<str>;
1819
| ^^^^^^^^^^^^^^^^^^^^
1920
|
21+
= note: casting expr `"String"` as `Arc<str>`
2022
= note: an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
2123
help: consider using the `From` trait instead
2224
|

tests/ui/const-generics/generic_const_exprs/opaque_type.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ error[E0605]: non-primitive cast: `usize` as `Foo`
1515
|
1616
LL | let _: [u8; (N / 2) as Foo] = [0; (N / 2) as usize];
1717
| ^^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
18+
|
19+
= note: casting expr `(N / 2)` as `Foo`
1820

1921
error: aborting due to 2 previous errors
2022

tests/ui/dyn-star/dyn-to-rigid.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0605]: non-primitive cast: `(dyn* Tr + 'static)` as `usize`
33
|
44
LL | x as usize
55
| ^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
6+
|
7+
= note: casting expr `x` as `usize`
68

79
error: aborting due to 1 previous error
810

tests/ui/dyn-star/unsize-into-ref-dyn-star.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0605]: non-primitive cast: `i32` as `&dyn* Debug`
33
|
44
LL | let i = 42 as &dyn* Debug;
55
| ^^^^^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
6+
|
7+
= note: casting expr `42` as `&dyn* Debug`
68

79
error: aborting due to 1 previous error
810

tests/ui/error-codes/E0605.stderr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ error[E0605]: non-primitive cast: `u8` as `Vec<u8>`
33
|
44
LL | x as Vec<u8>;
55
| ^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
6+
|
7+
= note: casting expr `x` as `Vec<u8>`
68

79
error[E0605]: non-primitive cast: `*const u8` as `&u8`
810
--> $DIR/E0605.rs:6:5
911
|
1012
LL | v as &u8;
1113
| ^^^^^^^^ invalid cast
1214
|
15+
= note: casting expr `v` as `&u8`
1316
help: consider borrowing the value
1417
|
1518
LL - v as &u8;

tests/ui/error-emitter/error-festival.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ error[E0605]: non-primitive cast: `u8` as `Vec<u8>`
6868
|
6969
LL | x as Vec<u8>;
7070
| ^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
71+
|
72+
= note: casting expr `x` as `Vec<u8>`
7173

7274
error[E0054]: cannot cast `{integer}` as `bool`
7375
--> $DIR/error-festival.rs:35:24

tests/ui/force-inlining/cast.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ error[E0605]: non-primitive cast: `fn(isize) -> usize {callee}` as `fn(isize) ->
1919
|
2020
LL | let _ = callee as fn(isize) -> usize;
2121
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid cast
22+
|
23+
= note: casting expr `callee` as `fn(isize) -> usize`
2224

2325
error[E0308]: cannot coerce functions which must be inlined to function pointers
2426
--> $DIR/cast.rs:21:9

tests/ui/issues/issue-16048.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ impl<'a> NoLifetime for Foo<'a> {
2323
//~| NOTE lifetimes do not match method in trait
2424
return *self as T;
2525
//~^ ERROR non-primitive cast: `Foo<'a>` as `T`
26+
//~| NOTE casting expr `*self` as `T`
2627
//~| NOTE an `as` expression can only be used to convert between primitive types
2728
}
2829
}

tests/ui/issues/issue-16048.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ error[E0605]: non-primitive cast: `Foo<'a>` as `T`
1313
LL | return *self as T;
1414
| ^^^^^^^^^^ help: consider using the `From` trait instead: `T::from(*self)`
1515
|
16+
= note: casting expr `*self` as `T`
1617
= note: an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
1718

1819
error: aborting due to 2 previous errors

tests/ui/issues/issue-22289.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ error[E0605]: non-primitive cast: `i32` as `&(dyn Any + 'static)`
44
LL | 0 as &dyn std::any::Any;
55
| ^^^^^^^^^^^^^^^^^^^^^^^ invalid cast
66
|
7+
= note: casting expr `0` as `&(dyn Any + 'static)`
78
help: consider borrowing the value
89
|
910
LL | &0 as &dyn std::any::Any;

tests/ui/issues/issue-22312.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ error[E0605]: non-primitive cast: `Self` as `&dyn Index<usize, Output = <Self as
44
LL | let indexer = &(*self as &dyn Index<usize, Output = <Self as Index<usize>>::Output>);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid cast
66
|
7+
= note: casting expr `*self` as `&dyn Index<usize, Output = <Self as Index<usize>>::Output>`
78
help: consider borrowing the value
89
|
910
LL | let indexer = &(&*self as &dyn Index<usize, Output = <Self as Index<usize>>::Output>);

tests/ui/issues/issue-2995.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ error[E0605]: non-primitive cast: `*const isize` as `&isize`
44
LL | let _q: &isize = p as &isize;
55
| ^^^^^^^^^^^ invalid cast
66
|
7+
= note: casting expr `p` as `&isize`
78
help: consider borrowing the value
89
|
910
LL - let _q: &isize = p as &isize;

tests/ui/mismatched_types/cast-rfc0401.stderr

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ error[E0605]: non-primitive cast: `*const u8` as `&u8`
2626
LL | let _ = v as &u8;
2727
| ^^^^^^^^ invalid cast
2828
|
29+
= note: casting expr `v` as `&u8`
2930
help: consider borrowing the value
3031
|
3132
LL - let _ = v as &u8;
@@ -37,24 +38,32 @@ error[E0605]: non-primitive cast: `*const u8` as `E`
3738
|
3839
LL | let _ = v as E;
3940
| ^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
41+
|
42+
= note: casting expr `v` as `E`
4043

4144
error[E0605]: non-primitive cast: `*const u8` as `fn()`
4245
--> $DIR/cast-rfc0401.rs:31:13
4346
|
4447
LL | let _ = v as fn();
4548
| ^^^^^^^^^ invalid cast
49+
|
50+
= note: casting expr `v` as `fn()`
4651

4752
error[E0605]: non-primitive cast: `*const u8` as `(u32,)`
4853
--> $DIR/cast-rfc0401.rs:32:13
4954
|
5055
LL | let _ = v as (u32,);
5156
| ^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
57+
|
58+
= note: casting expr `v` as `(u32,)`
5259

5360
error[E0605]: non-primitive cast: `Option<&*const u8>` as `*const u8`
5461
--> $DIR/cast-rfc0401.rs:33:13
5562
|
5663
LL | let _ = Some(&v) as *const u8;
5764
| ^^^^^^^^^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
65+
|
66+
= note: casting expr `Some(&v)` as `*const u8`
5867

5968
error[E0606]: casting `*const u8` as `f32` is invalid
6069
--> $DIR/cast-rfc0401.rs:35:13

tests/ui/mismatched_types/issue-26480.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ LL | ($x:expr) => ($x as ())
2929
LL | cast!(2);
3030
| -------- in this macro invocation
3131
|
32+
= note: casting expr `2` as `()`
3233
= note: this error originates in the macro `cast` (in Nightly builds, run with -Z macro-backtrace for more info)
3334

3435
error: aborting due to 2 previous errors

tests/ui/nonscalar-cast.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ error[E0605]: non-primitive cast: `Foo` as `isize`
44
LL | println!("{}", Foo { x: 1 } as isize);
55
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using the `From` trait instead: `isize::from(Foo { x: 1 })`
66
|
7+
= note: casting expr `Foo { x: 1 }` as `isize`
78
= note: an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
89

910
error: aborting due to 1 previous error

tests/ui/reachable/expr_cast.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ error[E0605]: non-primitive cast: `()` as `!`
1818
|
1919
LL | let x = {return} as !;
2020
| ^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
21+
|
22+
= note: casting expr `{return}` as `!`
2123

2224
error: aborting due to 2 previous errors
2325

tests/ui/rfcs/rfc-1623-static/rfc1623-3.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ error[E0605]: non-primitive cast: `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8 {non
2828
|
2929
LL | &(non_elidable as fn(&u8, &u8) -> &u8);
3030
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid cast
31+
|
32+
= note: casting expr `non_elidable` as `for<'a, 'b> fn(&'a u8, &'b u8) -> &u8`
3133

3234
error: aborting due to 3 previous errors
3335

0 commit comments

Comments
 (0)