Skip to content

IAT: Reject implicit lifetime bounds of trait object types passed to inherent projections as indeterminate in ItemCtxts #141997

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 Jun 4, 2025 · 1 comment
Assignees
Labels
A-dyn-trait Area: trait objects, vtable layout A-lifetimes Area: Lifetimes / regions C-bug Category: This is a bug. F-inherent_associated_types `#![feature(inherent_associated_types)]` 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 Jun 4, 2025

This is for future-proofing / an extension of my efforts to make object lifetime defaulting more predictable & consistent across generic containers (see also #129543).

Examples that currently compile but ought not to:

#![feature(inherent_associated_types)]

struct Self0;
impl Self0 { type Project<'a, T: 'a + ?Sized> = (); }

type Demo0<'r> = Self0::Project<'r, dyn Trait>;
//                                  ^^^^^^^^^ ought to be rejected

struct Self1<'a>(&'a ());
impl<'a> Self1<'a> { type Project<T: 'a + ?Sized> = (); }

type Demo1<'r> = Self1<'r>::Project<dyn Trait>;
//                                  ^^^^^^^^^ ought to be rejected

trait Trait {}

Note that this shouldn't/doesn't affect cases where the trait object types has own bounds that can be used as they take precedence (which The Reference gets wrong, cc rust-lang/reference#1407). Example of something that isn't affected:

#![feature(inherent_associated_types)]

trait Trait: 'static {}
//           ^^^^^^^ (!)

struct Zelf;
impl Zelf { type Project<'a, T: 'a + ?Sized> = (); }

type Demo0<'r> = Zelf::Project<'r, dyn Trait>;
//                                 ^^^^^^^^^ OK!
//                                           This elaborates to `dyn Trait + 'static`
//                                           due to the bound on `Trait` which takes
//                                           precedence over "`named_bound_var`".

We need to set the ambient object lifetime default for inherent projections to None in resolve_bound_vars, this way it'll be rejected later in ItemCtxts during HIR ty lowering.

"Problem" (the crux of the matter, actually): We don't have the resolution of TypeRelative paths in RBV, so arguably we should just do that for all unknown1 TypeRelative paths. I tried that already in #129543 and crater came back clean! I might just fix this issue in #129543 come to think about it.

Footnotes

  1. https://github.com/rust-lang/rust/pull/129543#issuecomment-2872926835

@fmease fmease converted this from a draft issue Jun 4, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 4, 2025
@fmease fmease added C-bug Category: This is a bug. F-inherent_associated_types `#![feature(inherent_associated_types)]` A-dyn-trait Area: trait objects, vtable layout A-lifetimes Area: Lifetimes / regions S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jun 4, 2025
@fmease fmease changed the title Reject implicit object lifetime bounds as indeterminate in ItemCtxts. IAT: Reject trait object types with implicit lifetime bound as indeterminate in ItemCtxts if passed to inherent projections Jun 4, 2025
@fmease
Copy link
Member Author

fmease commented Jun 4, 2025

Blocking this on #129543. Edit: I might just fix it in that PR (the first commit already fixes it but the latest commit undoes it to experiment with ad hoc resolution of trait associated types in RBV).

@fmease fmease self-assigned this Jun 4, 2025
@fmease fmease changed the title IAT: Reject trait object types with implicit lifetime bound as indeterminate in ItemCtxts if passed to inherent projections IAT: Reject trait object types with implicit lifetime bound as indeterminate in ItemCtxts if passed to inherent projection Jun 4, 2025
@fmease fmease added the T-types Relevant to the types team, which will review and decide on the PR/issue. label Jun 4, 2025
@fmease fmease changed the title IAT: Reject trait object types with implicit lifetime bound as indeterminate in ItemCtxts if passed to inherent projection IAT: Reject implicit lifetime bounds of trait object types passed to inherent projections in ItemCtxts as indeterminate Jun 4, 2025
@fmease fmease changed the title IAT: Reject implicit lifetime bounds of trait object types passed to inherent projections in ItemCtxts as indeterminate IAT: Reject implicit lifetime bounds of trait object types passed to inherent projections as indeterminate in ItemCtxts Jun 4, 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-inherent_associated_types `#![feature(inherent_associated_types)]` 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
Development

No branches or pull requests

2 participants