Repository navigation
Open
Labels
B-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-trivial_bounds`#![feature(trivial_bounds)]``#![feature(trivial_bounds)]`S-tracking-impl-incompleteStatus: The implementation is incomplete.Status: The implementation is incomplete.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 team
Description
This is a tracking issue for the RFC "Allow trivial constraints to appear in where clauses " (rust-lang/rfcs#2056).
Steps:
- Implement the RFC – Implement RFC 2056 trivial constraints in where clauses #48557
- As noted in Tracking issue for RFC #2056: Allow trivial constraints to appear in where clauses (
feature(trivial_bounds)) #48214 (comment), the new trait solver might solve a few issues with this feature, so this is currently blocked on the new trait solver (-Znext-solver)
- As noted in Tracking issue for RFC #2056: Allow trivial constraints to appear in where clauses (
- Adjust documentation (see instructions on forge)
- Stabilization PR (see instructions on forge)
Unresolved questions:
- Should the lint error by default instead of warn?
Reacted by Shane F. Carr, Ellie Pratt, Squirrel, Andrei Silviu Dragnea, Chris, acheron, Klas Segeljakt, Finn Bear, Stepan Koltsov, Felipe S. S. Schneider and 10 more
Reacted by Stanislav Tkach, Marin Veršić, acheron and Felipe S. S. Schneider
Metadata
Metadata
Assignees
Labels
B-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-trivial_bounds`#![feature(trivial_bounds)]``#![feature(trivial_bounds)]`S-tracking-impl-incompleteStatus: The implementation is incomplete.Status: The implementation is incomplete.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 team
Activity
matthewjasper commentedon Feb 18, 2018
I'm working on this.
nikomatsakis commentedon Feb 19, 2018
@matthewjasper ok. I've not thought hard about what it will take to support this. I had thought about doing it after making some more progress on general trait refactoring, but if it can be easily supported today seems fine.
nikomatsakis commentedon Feb 19, 2018
Oh, I meant to add, please ping me on IRC/gitter with any questions! I can try to carve out some time to think about it as well.
Auto merge of #48557 - matthewjasper:allow-trvial-bounds, r=nikomatsakis
Auto merge of #50782 - matthewjasper:wheres-main, r=matthewjasper
Auto merge of #51042 - matthewjasper:reenable-trivial-bounds, r=nikom…
matthewjasper commentedon Jun 10, 2018
So with #51042 merged this feature is implemented on nightly, but the implementation isn't particularly clean and there are some edge cases that don't work as one would expect:
Since Chalk might be able to fix some of these issues, I think that this feature is now waiting for Chalk to be integrated.
edit: As of 2018-12-28
-Zchalkdoes not currently solve this issue.RalfJung commentedon Oct 13, 2019
As another concrete example where trivially false constraints arise due to macros, see taiki-e/pin-project#102 (comment). That crate now carries a weird hack to work around this limitation.
What is the current status of this feature?
matthewjasper commentedon Oct 13, 2019
Not much has changed since my last comment.
Systemcluster commentedon Nov 14, 2019
The current implementation generates a warning when using the pre-existing impl trait syntax, which, reading the RFC, I assume is a false-positive.
This code generates the warning
warning: Trait bound impl T: T does not depend on any type or lifetime parameters. (playground link)37 remaining items
stegaBOB commentedon Apr 13, 2025
Wow this was definitely not obvious to me. For all where clause bounds that don't contain any lifetimes it looks like you should be able to emulate this 1:1 by inserting a higher-rank trait bound:
Edit: Seems like this has been realized already actually haha: #48214 (comment)
ais523 commentedon Oct 9, 2025
I just realised that the
for<'a>trick (which I've also used myself) is in effect an accidental stabilisation – writingfor<'a>on stable gives you the same effect as writing#![feature(trivial_bounds)]on nightly (including the bugs). The compiler also points people who attempt it to use the feature without the feature gate to this issue, which means that quite a lot of people may have discovered the workaround by now (and it's probably also possible to figure it out on your own without looking at the bug report – I have vague memories of experimenting with that the first time I ran into this problem).Is that something that needs attention? (On the other hand, is that a reason to just stabilise this anyway, despite the bugs? Having the feature gate doesn't seem useful given that there's a way around it.)
conditionally require Clone:
[3/n] [daft-derive] attempt to better annotate semantic errors
Darksonn commentedon Feb 9, 2026
What are the bugs, exactly?
ais523 commentedon Feb 10, 2026
@Darksonn: the main one I'm thinking about is #128682: although it's a bit unclear what's going on there (it doesn't have a MCVE), it appears to have constructed a situation where the typesystem thinks a trait is implemented but it actually isn't (leading to a linking failure).
That said, that bug currently isn't well-understood-enough to be certain that it's a bug in trivial_bounds rather than somewhere else.
theemathas commentedon Feb 20, 2026
The feature gating of this seems to not be working on structs. See #152872
matteomonti commentedon Feb 23, 2026
I hope I am not out of place contributing here, but I wanted to flag that some (e.g., me 😄) might be using the fact that trivial constraints are not allowed as a feature, not a limitation!
For example, say I need to derive an
Encodetrait for a struct likethat has several fields, only some of which depend on the generic parameters. To implement
Encode, all fields must implementEncode. What I usually derive is:Now, this is perfect:
whereclause simply restricts which genericsEncodegets implemented for;StringinMyStruct), the type not implementingEncodeis a hard error.I know in principle the correct thing to do would be to traverse every field type to determine whether or not a generic parameter appears anywhere inside it, but taking the lazy route has always worked for me, at least until I noticed this issue. If trivial constraints were allowed in where clauses, all of a sudden my code (and that of every lazy deriver like me) would behave unexpectedly:
Encodeon a concrete struct whose fields do not implementEncodewould compile just fine..Encodesimply would not be implemented.As an aside: yes, I did figure out the
for<'dummy>trick as well! I suspect many might be using it do differentiate between "I want this trivial where to cause an error if not satisfied" and "I simply want the trait not to be implemented, don't throw an error".RalfJung commentedon Feb 23, 2026
It seems entirely reasonable to have a lint against unsatisfiable bounds. But forbidding them entirely is not a great state IMO.
Rollup merge of rust-lang#153034 - arferreira:fix-trivial-bound-diagn…
Rollup merge of rust-lang#153034 - arferreira:fix-trivial-bound-diagn…
Rollup merge of rust-lang#153034 - arferreira:fix-trivial-bound-diagn…
Rollup merge of rust-lang#153034 - arferreira:fix-trivial-bound-diagn…
Unrolled build for #153034
[-]Tracking issue for RFC #2056: Allow trivial constraints to appear in where clauses [/-][+]Tracking issue for RFC #2056: Allow trivial constraints to appear in where clauses (`feature(trivial_bounds)`)[/+]