Skip to content
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

object lifetime bound defaults in trait bindings are incompletely implemented #63618

Open
nikomatsakis opened this issue Aug 15, 2019 · 2 comments
Labels
A-lifetimes Area: Lifetimes / regions A-trait-objects Area: trait objects, vtable layout A-trait-system Area: Trait system A-type-system Area: Type system T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@nikomatsakis
Copy link
Contributor

nikomatsakis commented Aug 15, 2019

In #63376, we fixed the behavior of default object lifetime bounds in "binding arguments", as described in this gist. For example the following type;

dyn Foo<Bar = dyn Baz>

will now default dyn Baz to dyn Baz + 'static.

However, the rules were incompletely implemented. If the trait has a lifetime parameter, we currently require an explicit lifetime bound. The expected behavior is to use the bounds declared on the associated type to set the default. So, given Foo like so:

trait Foo<'a> {
  type Bar: 'a + ?Sized;
}

then dyn Foo<'x, Bar = dyn Baz> would default to dyn Baz + 'a. Presently, however, it gives an error.

NB. There is one "design decision" to be made; does a where clause like where Self::Bar: 'x adjust the default? And how does that work when extended to GATs? My personal opinion is that we should limit ourselves to bounds declared on the associated type itself (and hence where Self::Bar: 'x would not count towards the default object lifetime bound), but this merits a bit of further discussion. This is largely because the complexity to specify and implement the behavior around where clauses and with GATs is kind feels out of proportion with the benefit.

@nikomatsakis nikomatsakis added A-type-system Area: Type system A-trait-system Area: Trait system T-lang Relevant to the language team, which will review and decide on the PR/issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 15, 2019
@nikomatsakis
Copy link
Contributor Author

(Note also: PR #63376 has not landed yet and this behavior is not finalized as of this writing. I just wanted an issue I could link to.)

@Centril
Copy link
Contributor

Centril commented Aug 18, 2019

When considering object lifetime bound defaults holistically, I think we should also consider the interactions with associated type defaults and trait objects. cc #29661.

@fmease fmease added T-types Relevant to the types team, which will review and decide on the PR/issue. A-trait-objects Area: trait objects, vtable layout A-lifetimes Area: Lifetimes / regions labels Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions A-trait-objects Area: trait objects, vtable layout A-trait-system Area: Trait system A-type-system Area: Type system T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. 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

3 participants