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
warning: transmute from a reference to a pointer
--> src/main.rs:10:14
|
10 | unsafe { transmute(foobar) }
| ^^^^^^^^^^^^^^^^^ help: try: `foobar as *mut Foo<'a> as *mut Foo<'static>`
|
= note: #[warn(clippy::useless_transmute)] on by default
= help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.212/index.html#useless_transmute
error[E0308]: mismatched types
--> src/main.rs:8:14
|
8 | unsafe { foobar as *mut Foo<'a> as *mut Foo<'static> }
| ^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
|
= note: expected type `*mut Foo<'static>`
found type `*mut Foo<'a>`
note: the lifetime 'a as defined on the function body at 7:12...
--> src/main.rs:7:12
|
7 | fn convert<'a>(foobar: &mut Foo<'a>) -> *mut Foo<'static> {
| ^^
= note: ...does not necessarily outlive the static lifetime
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.
This could be considered a rustc bug since casting between raw pointers should always succeed.
What happened here was that, in the outer cast, rustc first tried to do the cast as a coercion, which succeeded, so it doesn't bother checking for the other kinds of casts, but the coercion generated the obligation that 'a: 'static, which later caused the compile to fail.
Note that foobar as *mut Foo<'a> as *mut u8 as *mut Foo<'static> works.
If you (ab)use
std::mem::transmute
like this:Clippy 0.0.212 complains:
But Clippy's suggestion,
does not compile:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=55287e186a312efc65617fbd87ff288a
The text was updated successfully, but these errors were encountered: