Skip to content

Make trait aliases eligible generic containers wrt. ambient object lifetime defaults #140710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
fmease opened this issue May 6, 2025 · 0 comments
Assignees
Labels
A-dyn-trait Area: trait objects, vtable layout A-lifetimes Area: Lifetimes / regions C-bug Category: This is a bug. F-trait_alias `#![feature(trait_alias)]` S-blocked Status: Blocked on something else such as an RFC or other implementation work. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@fmease
Copy link
Member

fmease commented May 6, 2025

Arguably, trait alias refs should bring along ambient object lifetime defaults (I would say "just like trait refs" but those are currently unintentionally broken (or have been since their introduction) which would get fixed in #129543).

TL;DR: This code should compile and doesn't currently:

#![feature(trait_alias)]

trait Container<'a, T: 'a + ?Sized> =;
trait Bound {}

fn f<'r, T>() where T: Container<'r, dyn Bound + 'r> { g::<'r, T>() }
fn g<'r, T>() where T: Container<'r, dyn Bound> {}
//                                   ^^^^^^^^^ we currently deduce `dyn Bound + 'static` since trait alias
//                                             `Container` is not considered an eligible generic container.
//                                             However, we should make it one and deduce `dyn Bound + 'r`.
error: lifetime may not live long enough
 --> src/lib.rs:7:56
  |
7 | fn f<'r, T>() where T: Container<'r, dyn Bound + 'r> { g::<'r, T>() }
  |      -- lifetime `'r` defined here      

Object lifetime defaults aren't a hot topic esp. due to the existence of inferred outlives-bounds which don't participate in their resolution, so this is generally P-low but I'm not marking this issue as such as it should still block the stabilization of trait_alias (or whatever features end up replacing it) since modifying the resolution of object lifetime default afterwards would be a breaking change.

Temporarily blocking this on my PR #129543 which touches a lot of code in that area.

@fmease fmease self-assigned this May 6, 2025
@fmease fmease added A-lifetimes Area: Lifetimes / regions C-bug Category: This is a bug. S-blocked Status: Blocked on something else such as an RFC or other implementation work. F-trait_alias `#![feature(trait_alias)]` T-types Relevant to the types team, which will review and decide on the PR/issue. A-dyn-trait Area: trait objects, vtable layout labels May 6, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 6, 2025
@fmease fmease removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-dyn-trait Area: trait objects, vtable layout A-lifetimes Area: Lifetimes / regions C-bug Category: This is a bug. F-trait_alias `#![feature(trait_alias)]` S-blocked Status: Blocked on something else such as an RFC or other implementation work. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants