diff --git a/library/core/src/convert/mod.rs b/library/core/src/convert/mod.rs index a57f3d58e3998..c21c743672014 100644 --- a/library/core/src/convert/mod.rs +++ b/library/core/src/convert/mod.rs @@ -863,6 +863,28 @@ const impl AsMut for str { } } +#[stable(feature = "never_type", since = "CURRENT_RUSTC_VERSION")] +#[expect( + clippy::explicit_auto_deref, + reason = "https://github.com/rust-lang/rust-clippy/issues/17713" +)] +impl AsRef for ! { + fn as_ref(&self) -> &T { + *self + } +} + +#[stable(feature = "never_type", since = "CURRENT_RUSTC_VERSION")] +#[expect( + clippy::explicit_auto_deref, + reason = "https://github.com/rust-lang/rust-clippy/issues/17713" +)] +impl AsMut for ! { + fn as_mut(&mut self) -> &mut T { + *self + } +} + //////////////////////////////////////////////////////////////////////////////// // THE NO-ERROR ERROR TYPE //////////////////////////////////////////////////////////////////////////////// diff --git a/tests/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.pre2021.stderr b/tests/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.pre2021.stderr index dc566ad50153a..54ea4882c4669 100644 --- a/tests/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.pre2021.stderr +++ b/tests/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.pre2021.stderr @@ -1,16 +1,11 @@ -error[E0277]: the trait bound `!: AsRef<(dyn for<'a> Fn(&'a ()) + 'static)>` is not satisfied +error[E0277]: the trait bound `(): AsRef<(dyn for<'a> Fn(&'a ()) + 'static)>` is not satisfied --> $DIR/generic-with-implicit-hrtb-without-dyn.rs:7:13 | LL | fn ice() -> impl AsRef { - | ^^^^^^^^^^^^^^^^^^^ the trait `AsRef<(dyn for<'a> Fn(&'a ()) + 'static)>` is not implemented for `!` + | ^^^^^^^^^^^^^^^^^^^ the trait `AsRef<(dyn for<'a> Fn(&'a ()) + 'static)>` is not implemented for `()` ... -LL | todo!() - | ------- return type was inferred to be `!` here - | -help: `!` can be coerced to any type; consider casting it to a concrete type that implements the trait - | -LL | todo!() as /* Type */ - | +++++++++++++ +LL | () + | -- return type was inferred to be `()` here error: aborting due to 1 previous error diff --git a/tests/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.rs b/tests/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.rs index 64311a474cade..6c538e8c8ee16 100644 --- a/tests/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.rs +++ b/tests/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.rs @@ -5,10 +5,10 @@ #![allow(warnings)] fn ice() -> impl AsRef { - //[pre2021]~^ ERROR: the trait bound `!: AsRef<(dyn for<'a> Fn(&'a ()) + 'static)>` is not satisfied [E0277] + //[pre2021]~^ ERROR: the trait bound `(): AsRef<(dyn for<'a> Fn(&'a ()) + 'static)>` is not satisfied [E0277] //[edition2021]~^^ ERROR: expected a type, found a trait [E0782] //[edition2021]~| ERROR: expected a type, found a trait [E0782] - todo!() + () } fn main() {}