Skip to content

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

Open
@fmease

Description

@fmease

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

Metadata

Metadata

Assignees

Labels

A-dyn-traitArea: trait objects, vtable layoutA-lifetimesArea: Lifetimes / regionsC-bugCategory: This is a bug.F-inherent_associated_types`#![feature(inherent_associated_types)]`S-blockedStatus: Blocked on something else such as an RFC or other implementation work.T-typesRelevant to the types team, which will review and decide on the PR/issue.

Type

No type

Projects

Status

To Do

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions