Open
Description
Using the following flags
--force-warn clippy::as-underscore
this code:
fn main() {
bidirectional_subtyping();
}
fn bidirectional_subtyping() {
// Test that transmuting between subtypes of dyn traits is fine, even in the
// "wrong direction", i.e. going from a lower-ranked to a higher-ranked dyn trait.
// Note that compared to the `dyn-transmute-inner-binder` test, the `for` is on the
// *outside* here!
trait Trait<U: ?Sized> {}
impl<T, U: ?Sized> Trait<U> for T {}
struct Wrapper<T: ?Sized>(T);
// This lowers to a ptr-to-ptr cast (which behaves like a transmute)
// and not an unsizing coercion:
let x: *const dyn for<'a> Trait<&'a ()> = &();
let _y: *const Wrapper<dyn Trait<&'static ()>> = x as _;
}
caused the following diagnostics:
Checking _a v0.1.0 (/tmp/icemaker_global_tempdir.ori2g64BWizp/icemaker_clippyfix_tempdir.KTXcvQqSrHoX/_a)
warning: using `as _` conversion
--> src/main.rs:19:54
|
19 | let _y: *const Wrapper<dyn Trait<&'static ()>> = x as _;
| ^^^^^-
| |
| help: consider giving the type explicitly: `*const bidirectional_subtyping::Wrapper<dyn bidirectional_subtyping::Trait<&()>>`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#as_underscore
= note: requested on the command line with `--force-warn clippy::as-underscore`
warning: `_a` (bin "_a") generated 1 warning (run `cargo clippy --fix --bin "_a"` to apply 1 suggestion)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.14s
However after applying these diagnostics, the resulting code:
fn main() {
bidirectional_subtyping();
}
fn bidirectional_subtyping() {
// Test that transmuting between subtypes of dyn traits is fine, even in the
// "wrong direction", i.e. going from a lower-ranked to a higher-ranked dyn trait.
// Note that compared to the `dyn-transmute-inner-binder` test, the `for` is on the
// *outside* here!
trait Trait<U: ?Sized> {}
impl<T, U: ?Sized> Trait<U> for T {}
struct Wrapper<T: ?Sized>(T);
// This lowers to a ptr-to-ptr cast (which behaves like a transmute)
// and not an unsizing coercion:
let x: *const dyn for<'a> Trait<&'a ()> = &();
let _y: *const Wrapper<dyn Trait<&'static ()>> = x as *const bidirectional_subtyping::Wrapper<dyn bidirectional_subtyping::Trait<&()>>;
}
no longer compiled:
Checking _a v0.1.0 (/tmp/icemaker_global_tempdir.ori2g64BWizp/icemaker_clippyfix_tempdir.KTXcvQqSrHoX/_a)
error[E0433]: failed to resolve: function `bidirectional_subtyping` is not a crate or module
--> src/main.rs:19:66
|
19 | let _y: *const Wrapper<dyn Trait<&'static ()>> = x as *const bidirectional_subtyping::Wrapper<dyn bidirectional_subtyping::Trait<&()>>;
| ^^^^^^^^^^^^^^^^^^^^^^^ function `bidirectional_subtyping` is not a crate or module
error[E0433]: failed to resolve: function `bidirectional_subtyping` is not a crate or module
--> src/main.rs:19:103
|
19 | let _y: *const Wrapper<dyn Trait<&'static ()>> = x as *const bidirectional_subtyping::Wrapper<dyn bidirectional_subtyping::Trait<&()>>;
| ^^^^^^^^^^^^^^^^^^^^^^^ function `bidirectional_subtyping` is not a crate or module
For more information about this error, try `rustc --explain E0433`.
error: could not compile `_a` (bin "_a" test) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
error: could not compile `_a` (bin "_a") due to 2 previous errors
Version:
rustc 1.90.0-nightly (de031bbcb 2025-07-06)
binary: rustc
commit-hash: de031bbcb161b0b7fc0eb16f77b02ce9fbdf4c9e
commit-date: 2025-07-06
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.7