You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fnmain(){let a = &true;let b = &false;assert!(a as*const _ == b as*const _);}
test.rs:5:30: 5:43 warning: trivial cast: `&bool` as `*const bool`, #[warn(trivial_casts)] on by default
test.rs:5 assert!(a as *const _ == b as *const _);
^~~~~~~~~~~~~
<std macros>:1:1: 5:46 note: in expansion of assert!
test.rs:5:5: 5:45 note: expansion site
But removing the second cast doesn't compile:
fnmain(){let a = &true;let b = &false;assert!(a as*const _ == b);}
test.rs:5:30: 5:31 error: mismatched types:
expected `*const _`,
found `&bool`
(expected *-ptr,
found &-ptr) [E0308]
test.rs:5 assert!(a as *const _ == b);
^
<std macros>:1:1: 5:46 note: in expansion of assert!
test.rs:5:5: 5:33 note: expansion site
error: aborting due to previous error
The lint runs when a cast can be replaced by a coercion, not when a cast can be removed. So, this is not bogus, although it is kind of annoying to fix without type ascription.
You could add a type annotation to the declaration of b so that it has the expected type, or introduce a temporary variable (b_as_raw or something). You could also turn the lint off until type ascription lands (hopefully soon) which will give you a nice way to do this.
But removing the second cast doesn't compile:
cc @nrc
The text was updated successfully, but these errors were encountered: