Description
Note: The regression is valid/"allowed" (there's a hole in the typesystem being patched), I'm just filing this issue now so we can make sure that this regression is tracked in case it got "fixed" by accident. Feel free to close if it's a known quantity; I'm just worried that this got "accidentally" fixed in some other change.
My crate is being fixed to not face this problem, but in general there's a chance other crates are falling afoul of this as well; we should perhaps assess the impact and start off with it being a future incompatibility warning if necessary.
Code
I tried this code:
pub trait Yokeable<'a>: 'static {
type Output: 'a;
}
impl<'a, T: 'static + ?Sized> Yokeable<'a> for &'static T {
type Output = &'a T;
}
pub trait ZeroCopyFrom<C: ?Sized>: for<'a> Yokeable<'a> {
/// Clone the cart `C` into a [`Yokeable`] struct, which may retain references into `C`.
fn zero_copy_from<'b>(cart: &'b C) -> <Self as Yokeable<'b>>::Output;
}
impl<T> ZeroCopyFrom<[T]> for &'static [T] {
fn zero_copy_from<'b>(cart: &'b [T]) -> &'b [T] {
cart
}
}
(playpen)
I expected to see this happen: It compiles, like it does on stable, or at least throws a future incompatibility warning.
Instead, this happened: It errors:
error[E0310]: the parameter type `T` may not live long enough
--> src/lib.rs:17:5
|
17 | fn zero_copy_from<'b>(cart: &'b [T]) -> &'b [T] {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider adding an explicit lifetime bound `T: 'static`...
= note: ...so that the type `[T]` will meet its required lifetime bounds
For more information about this error, try `rustc --explain E0310`.
error: could not compile `playground` due to previous error
Version it worked on
It most recently worked on: Rust 1.56.0
Version with regression
1.58.0-beta.2
(2021-12-04 0e07bcb68b82b54c0c4e)