Skip to content

missing_transmute_annotations suggests impl Future which is not allowed #14984

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

Open
matthiaskrgr opened this issue Jun 5, 2025 · 2 comments · May be fixed by #14996
Open

missing_transmute_annotations suggests impl Future which is not allowed #14984

matthiaskrgr opened this issue Jun 5, 2025 · 2 comments · May be fixed by #14996
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied T-async-await Type: Issues related to async/await

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Jun 5, 2025

Using the following flags

--force-warn clippy::missing_transmute_annotations

this code:

async fn empty() {}

async fn meow(a: [u8; 100]) {
	empty().await;
	dbg!(a);
}

fn main() {
	let v = meow([0; 100]);
	let e = [0u8; 202];
	let _ = || unsafe {
		use std::{mem, ptr};
		let mut copy = ptr::read(&v);
		ptr::write(&mut copy, mem::transmute(ptr::read(&e)));
		mem::forget(copy);
	};
}

caused the following diagnostics:

    Checking _110151 v0.1.0 (/tmp/icemaker_global_tempdir.t8dYaH8PqaqW/icemaker_clippyfix_tempdir.QCq7tmv8PvKz/_110151)
warning: transmute used without annotations
  --> src/main.rs:14:30
   |
14 |         ptr::write(&mut copy, mem::transmute(ptr::read(&e)));
   |                                    ^^^^^^^^^ help: consider adding missing annotations: `transmute::<[u8; 202], impl std::future::Future<Output = ()>>`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_transmute_annotations
   = note: requested on the command line with `--force-warn clippy::missing-transmute-annotations`

warning: `_110151` (bin "_110151") generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.14s

However after applying these diagnostics, the resulting code:

async fn empty() {}

async fn meow(a: [u8; 100]) {
	empty().await;
	dbg!(a);
}

fn main() {
	let v = meow([0; 100]);
	let e = [0u8; 202];
	let _ = || unsafe {
		use std::{mem, ptr};
		let mut copy = ptr::read(&v);
		ptr::write(&mut copy, mem::transmute::<[u8; 202], impl std::future::Future<Output = ()>>(ptr::read(&e)));
		mem::forget(copy);
	};
}

no longer compiled:

    Checking _110151 v0.1.0 (/tmp/icemaker_global_tempdir.t8dYaH8PqaqW/icemaker_clippyfix_tempdir.QCq7tmv8PvKz/_110151)
error[E0562]: `impl Trait` is not allowed in paths
  --> src/main.rs:14:53
   |
14 |         ptr::write(&mut copy, mem::transmute::<[u8; 202], impl std::future::Future<Output = ()>>(ptr::read(&e)));
   |                                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `impl Trait` is only allowed in arguments and return types of functions and methods

For more information about this error, try `rustc --explain E0562`.
error: could not compile `_110151` (bin "_110151") due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `_110151` (bin "_110151" test) due to 1 previous error

Version:

rustc 1.89.0-nightly (076ec59ff 2025-06-05)
binary: rustc
commit-hash: 076ec59ff1dcf538b9d3a0b8e0d7f4edd0559959
commit-date: 2025-06-05
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5

@matthiaskrgr matthiaskrgr added C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied T-async-await Type: Issues related to async/await labels Jun 6, 2025
@matthiaskrgr
Copy link
Member Author

simple example I think:

Using the following flags

--force-warn clippy::missing_transmute_annotations

this code:

//! Check that typeck can observe the size of an opaque type.
//@ check-pass
use std::mem::transmute;
fn foo() -> impl Sized {
    0u8
}

fn main() {
    unsafe {
        transmute::<_, u8>(foo());
    }
}

caused the following diagnostics:

    Checking _outside-of-defining-scope v0.1.0 (/tmp/icemaker_global_tempdir.o4hDRjvshrmO/icemaker_clippyfix_tempdir.ekcifGNUFKDC/_outside-of-defining-scope)
warning: transmute used without annotations
  --> src/main.rs:10:9
   |
10 |         transmute::<_, u8>(foo());
   |         ^^^^^^^^^^^^^^^^^^ help: consider adding missing annotations: `transmute::<impl Sized, u8>`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_transmute_annotations
   = note: requested on the command line with `--force-warn clippy::missing-transmute-annotations`

warning: `_outside-of-defining-scope` (bin "_outside-of-defining-scope") generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.12s

However after applying these diagnostics, the resulting code:

//! Check that typeck can observe the size of an opaque type.
//@ check-pass
use std::mem::transmute;
fn foo() -> impl Sized {
    0u8
}

fn main() {
    unsafe {
        transmute::<impl Sized, u8>(foo());
    }
}

no longer compiled:

    Checking _outside-of-defining-scope v0.1.0 (/tmp/icemaker_global_tempdir.o4hDRjvshrmO/icemaker_clippyfix_tempdir.ekcifGNUFKDC/_outside-of-defining-scope)
error[E0562]: `impl Trait` is not allowed in paths
  --> src/main.rs:10:21
   |
10 |         transmute::<impl Sized, u8>(foo());
   |                     ^^^^^^^^^^
   |
   = note: `impl Trait` is only allowed in arguments and return types of functions and methods

For more information about this error, try `rustc --explain E0562`.
error: could not compile `_outside-of-defining-scope` (bin "_outside-of-defining-scope" test) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `_outside-of-defining-scope` (bin "_outside-of-defining-scope") due to 1 previous error

Version:

rustc 1.89.0-nightly (cf423712b 2025-06-05)
binary: rustc
commit-hash: cf423712b9e95e9f6ec84b1ecb3d125e55ac8d56
commit-date: 2025-06-05
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5

@samueltardieu
Copy link
Contributor

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied T-async-await Type: Issues related to async/await
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants