Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions library/core/src/convert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,20 @@ const impl AsMut<str> for str {
}
}

#[stable(feature = "never_type", since = "CURRENT_RUSTC_VERSION")]
impl<T: ?Sized> AsRef<T> for ! {
fn as_ref(&self) -> &T {
match *self {}
}
}

#[stable(feature = "never_type", since = "CURRENT_RUSTC_VERSION")]
impl<T: ?Sized> AsMut<T> for ! {
fn as_mut(&mut self) -> &mut T {
match *self {}
}
}

////////////////////////////////////////////////////////////////////////////////
// THE NO-ERROR ERROR TYPE
////////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Fn(&())> {
| ^^^^^^^^^^^^^^^^^^^ 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

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#![allow(warnings)]

fn ice() -> impl AsRef<Fn(&())> {
//[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() {}
Loading