Open conradludgate opened 1 year ago
Reduced:
pub fn check<'a>(r: &'a &'a ()) {
- pub type Borrow<'a, T : 'a> = &'a T;
+ pub type Borrow<'a, T> = &'a T;
type DynSend<'a> = Borrow<'a, dyn Send>;
let _: DynSend<'a> = r;
}
removes the lint but leads to a compile failure.
I did some more exploration here (and playground). More generally, using an alias will apply the dyn
lifetime defaults (RFC 0599, RFC 1156) based on the alias bounds (or lack of bounds), be they stronger or looser than the aliased type.
So they definitely have semantic impact. I don't think they're checked (enforced) per se, though.
pub type Lt<'a, 'b: 'a> = (&'a (), &'b ());
// Compiles
fn check<'a, 'b>(r: &'a &'b ()) {
let _: Lt<'a, 'b> = (*r, *r);
let _: Lt<'b, 'a> = (*r, *r);
}
@QuineDot is correct, the outlives-bounds T: 'a
on the (eager) type alias Borrow
influences the default object lifetime of dyn Foo
.
Bounds on lazy type aliases (feature lazy_type_alias
) on the other hand are enforced and they are checked for well-formedness. Lazy type aliases will become the default in Rust 202X (the plan is Rust 2024 but the implementation stills needs to be completed by me). CC #112792. I don't know how to proceed with this issue? Should I close it or keep it open?
If nothing else this should be documented somewhere. Based on some light testing, it seems lazy_type_alias
preserves this behavior, correct? That also seems reasonable to me.
I tried this code:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=c358b7f20cd1b96bf3919a4339288971
I expected to see this happen:
Borrow<'a, dyn Foo>
should default todyn Foo + 'static
and theT: 'a
should be ignored.Instead, this happened:
If you follow the guidance from the warning, it no longer compiles due to
dyn Foo
being static-ish, as mentioned