-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Tracking issue for RFC 2532, "Associated type defaults" #29661
Copy link
Copy link
Open
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)B-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.Blocker: Approved by a merged RFC but not yet implemented.B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-associated_type_defaults`#![feature(associated_type_defaults)]``#![feature(associated_type_defaults)]`S-tracking-needs-summaryStatus: It's hard to tell what's been done and what hasn't! Someone should do some investigation.Status: It's hard to tell what's been done and what hasn't! Someone should do some investigation.T-langRelevant to the language teamRelevant to the language teamT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)B-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.Blocker: Approved by a merged RFC but not yet implemented.B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-associated_type_defaults`#![feature(associated_type_defaults)]``#![feature(associated_type_defaults)]`S-tracking-needs-summaryStatus: It's hard to tell what's been done and what hasn't! Someone should do some investigation.Status: It's hard to tell what's been done and what hasn't! Someone should do some investigation.T-langRelevant to the language teamRelevant to the language teamT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
This is a tracking issue for the RFC "Associated type defaults" (rust-lang/rfcs#2532) under the feature gate
#![feature(associated_type_defaults)].The associated item RFC included the ability to provide defaults for associated types, with some tricky rules about how that would influence defaulted methods.
The early implementation of this feature was gated, because there is a widespread feeling that we want a different semantics from the RFC -- namely, that default methods should not be able to assume anything about associated types. This is especially true given the specialization RFC, which provides a much cleaner way of tailoring default implementations.
The new RFC, rust-lang/rfcs#2532, specifies that this should be the new semantics but has not been implemented yet. The existing behavior under
#![feature(associated_type_defaults)]is buggy and does not conform to the new RFC. Consult it for a discussion on changes that will be made.Steps:
associated_type_defaultsare unsound in the new solver trait-system-refactor-initiative#46Unresolved questions:
Test checklist
Originally created as a comment on #61812
type Foo = u8;)dyn Trait)dyn Trait<Foo = u16>to thatu8by invoking some method etcdyn Trait<Foo = u16>)dyn Trait<Foo = u16>to thatu8by invoking some method etctype Foo = u8; type Bar;)dyn Trait) -- errorFoois specified (dyn Trait<Foo = u16>) -- errorBaris specified (dyn Trait<Bar = u32>) -- ok, checkFoodefaults tou8dyn Trait<Foo = u16, Bar = u32>) -- oktype Foo = u8; type Bar = Vec<Self::Foo>)dyn Trait) -- errorFoois specified (dyn Trait<Foo = u16>) -- unclear, maybe an error?Baris specified (dyn Trait<Bar = u32>) -- unclear, maybe an error?dyn Trait<Foo = u16, Bar = u32>) -- oktype Foo = Self::Bar; type Bar = Self::Foo)dyn Trait)Foois specified (dyn Trait<Foo = u16>)Baris specified (dyn Trait<Bar = u32>)dyn Trait<Foo = u16, Bar = u32>)type Foo = Vec<Self::Bar>; type Bar = Box<Self::Foo>;)dyn Trait)Foois specified (dyn Trait<Foo = u16>)Baris specified (dyn Trait<Bar = u32>)dyn Trait<Foo = u16, Bar = u32>)type Foo = u8;(defaults-in-other-trait-items.rs)default type Foo = u8, cannot rely on that internally (defaults-specialization.rs)type Foo = u8, cannot rely on that internally (defaults-specialization.rs)type Foo = u8;)associated-types/associated-types-overridden-default.rs)impl Trait { }) (associated-types/issue-54182-2.rs)impl Trait { type Foo = u16; }) (issue-54182-1.rs)type Foo = u8; type Bar;)impl Trait { }) -- errorFoois specified (impl Trait { type Foo = u16; }) -- errorBaris specified (impl Trait { type Bar = u32; }) -- okimpl Trait { type Foo = u16; type Bar = u32; }) -- oktype Foo = u8; type Bar = Vec<Self::Foo>) --defaults-in-other-trait-items-pass.rs,defaults-in-other-trait-items-fail.rsimpl Trait { })Foois specified (impl Trait { type Foo = u16; })Baris specified (impl Trait { type Bar = u32; })impl Trait { type Foo = u16; type Bar = u32; })type Foo = Self::Bar; type Bar = Self::Foo) --defaults-cyclic-fail.rs,defaults-cyclic-pass.rsimpl Trait { })Foois specified (impl Trait { type Foo = u16; })Baris specified (impl Trait { type Bar = u32; })impl Trait { type Foo = u16; type Bar = u32; })type Foo = Vec<Self::Bar>; type Bar = Box<Self::Foo>;)impl Trait { })Foois specified (impl Trait { type Foo = u16; })Baris specified (impl Trait { type Bar = u32; })impl Trait { type Foo = u16; type Bar = u32; })Foois specifiedBaris specifiedFoois specifiedBaris specifieddefaults-cyclic-fail.rs,defaults-cyclic-pass.rsimpl Trait { })Foois specifiedBaris specifiedFoois specifiedBaris specifiedFoois specifiedBaris specifieddefaults-suitability.rs)typein trait body, bound appears on the itemtypein trait body, type not wftypein trait body, bound appears as trait where clausedefault typein impl, bound appears on the itemtypein impl, bound appears on the itemtypein default impl, bound appears on the itemtypein trait body, conditionally wf depending on another defaulttypein trait body, depends on another default whose bounds suffice