Repository navigation
Closed
Labels
A-trait-systemArea: Trait systemArea: Trait systemB-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.Blocker: Approved by a merged RFC but not yet implemented.B-RFC-implementedBlocker: Approved by a merged RFC and implemented but not stabilized.Blocker: Approved by a merged RFC and implemented but not stabilized.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_bounds`#![feature(associated_type_bounds)]``#![feature(associated_type_bounds)]`S-tracking-impl-incompleteStatus: The implementation is incomplete.Status: The implementation is incomplete.S-types-trackedStatus: Being actively tracked by the types teamStatus: Being actively tracked by the types teamT-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.
Description
This is a tracking issue for the RFC "Associated type bounds of form MyTrait<AssociatedType: Bounds>" (rust-lang/rfcs#2289). The feature gate is #![feature(associated_type_bounds)].
Steps:
- Implement the RFC - Implementation of RFC 2289 (associated_type_bounds) #57428
- Adjust documentation (see instructions on forge)
- Stabilization PR (see instructions on forge)
Unresolved questions:
-
Does allowing this for
dyntrait objects introduce any unforeseen issues? This can be resolved during stabilization.- Use for trait objects has been forbidden in Remove support for
associated_type_boundnested indyntypes #120719
- Use for trait objects has been forbidden in Remove support for
-
Resolve exact desugaring in the context of putting bounds on an associated type of a trait. See discussion in the RFC.
-
Consider nested lifetimes, https://gist.github.com/Centril/b0e62d31d4ae1849535c3e506e1fad64.
TODO:
Reacted by Eyal Kalderon, runiq, Jonathas Conceição, Proc, Rodrigo, Michael Crapse, Ron Lobo, Vladislav, Ludwig Stecher, Johannes Willbold and 64 more
Reacted by Lukas Kalbertodt, Jon Gjengset, Esteban Kuber, Ron Lobo, Isak Sunde Singh, Ken, Andrew Hlynskyi, Brandon H. Gomes, ChosunOne, Tomáš Jašek and 15 more
Reacted by ben
Reacted by t4lz, Max von Hippel and zohnannor
Metadata
Metadata
Assignees
Labels
A-trait-systemArea: Trait systemArea: Trait systemB-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.Blocker: Approved by a merged RFC but not yet implemented.B-RFC-implementedBlocker: Approved by a merged RFC and implemented but not stabilized.Blocker: Approved by a merged RFC and implemented but not stabilized.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_bounds`#![feature(associated_type_bounds)]``#![feature(associated_type_bounds)]`S-tracking-impl-incompleteStatus: The implementation is incomplete.Status: The implementation is incomplete.S-types-trackedStatus: Being actively tracked by the types teamStatus: Being actively tracked by the types teamT-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.
Activity
kennytm commentedon Jul 24, 2018
😕 How does it work? For instance while
dyn Iterator<Item = T>is object-safe,dyn Iterator<Item: Debug>should not since its.next()returns...impl Debug(but dynamic)?Centril commentedon Jul 24, 2018
@kennytm I think that while
dyn Iterator<Item: Debug>make syntactic sense to parse (to keep the parser simpler), it doesn't make much sense semantically for the reasons you've noted. Nicely spotted. :)kennytm commentedon Jul 24, 2018
So I suppose we could parse
dyn Trait<Assoc: Bound>into AST, but will reject it during HIR lowering or typeck.Centril commentedon Jul 24, 2018
@kennytm sounds reasonable. 👍
LukasKalbertodt commentedon Mar 17, 2019
I haven't found any discussion about this: what about super trait bounds? In particular: whether other code can "rely" on it. Example (current Rust, Playground):
This errors. While
foocan assume thatTalso implementsColor(the direct super trait bound) and thusT::Channelworks,foocannot assume thewherebound of the trait to be true, and thus::clonedoesn't work. The compiler says "the trait bound<T as Color>::Channel: std::clone::Cloneis not satisfied". I can't quite remember what this is called, but I once heard a term that describes what things other code can rely on and what not (maybe something fancy like "projection"?).My question is: how would the following code behave?
Would it behave as the first code example or would other code now be able to deduce
T::Channel: ClonefromT: CloneColor?(I hope I'm not missing something obvious here)
Centril commentedon Mar 17, 2019
#44491 will likely change this :) (cc @scalexm)
Same as:
Depends on whether you have implied bounds or not :)
LukasKalbertodt commentedon Mar 17, 2019
@Centril Thanks for the quick explanation! I didn't know implied bounds would change this too -- that's great!
Nemo157 commentedon Mar 21, 2019
How does this interact with HRLB? I just discovered that trait aliases allow you to write the constraints required for working with async functions/closures, but could this be another way to do so?
You can currently write:
and presumably once this is implemented it could be:
but can you go all the way to:
Centril commentedon Mar 21, 2019
@Nemo157 When you write:
where Foo: for<'a> Bar<'a, Assoc: Bound>it should desugar into:
where Foo: for<'a> Bar<'a>, for<'a> <Foo as Bar<'a>>::Assoc: Bound,However, rustc is generally unhappy with
for<'a> <Foo as Bar<'a>>::Assoc: Boundtoday as I found out when writing tests for #57428. Chalk will hopefully makes things better in the future and throw out some of the bugs.43 remaining items
mimoo commentedon Oct 11, 2022
clarfonthey commentedon Oct 25, 2022
I assume that fully implementing this feature isn't very high priority, but what do people think in terms of marking this flag as incomplete, given the comment I posted earlier this year?
I would offer to help with this but I'm not sure I'm aware of what's involved to do this. I'm also not sure where this is on the road map, but my assumption is it's lower than other planned features and no one's going to be working ensure this doesn't ambiguify (?) the existing trait behaviour for a while.
first design
joshtriplett commentedon Oct 17, 2023
maia-s commentedon Jan 22, 2024
gui1117 commentedon Mar 3, 2024
oli-obk commentedon Mar 3, 2024
Tracking issues are impractical for discussions. I'm locking this issue. Please open new issues for problems and discuss the feature on zulip instead
Rollup merge of rust-lang#122055 - compiler-errors:stabilize-atb, r=o…
Auto merge of rust-lang#122055 - compiler-errors:stabilize-atb, r=oli…
Auto merge of rust-lang#122055 - compiler-errors:stabilize-atb, r=oli…