Trait aliases: Also imply default trait bounds on type params other than Self#152688
Trait aliases: Also imply default trait bounds on type params other than Self#152688fmease wants to merge 1 commit intorust-lang:mainfrom
Self#152688Conversation
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
[WIP] Trait aliases: Imply default trait bounds
This comment has been minimized.
This comment has been minimized.
eff5e38 to
fdb25e1
Compare
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (ffd787c): comparison URL. Overall result: no relevant changes - no action neededBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. @bors rollup=never Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results (primary 2.6%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 0.2%, secondary 2.6%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 482.657s -> 481.709s (-0.20%) |
Self
fdb25e1 to
7269e75
Compare
7269e75 to
f61aed1
Compare
SelfSelf
There was a problem hiding this comment.
My change only affects trait aliases since implied_predicates_with_filter is only ever called with filter PredicateFilter::All for trait aliases (namely in explicit_implied_predicates_of). Consequently, my PR won't affect stable behavior.
| ) -> Vec<(ty::Clause<'tcx>, Span)> { | ||
| let mut bounds = Vec::new(); | ||
|
|
||
| if let PredicateFilter::All = filter { |
There was a problem hiding this comment.
Predicates where the bounded type is a HIR type param obviously never qualify for PredicateFilter::{SelfOnly, SelfTraitThatDefines, SelfAndAssociatedTypeBounds, SelfConstIfConst}.
Regarding PredicateFilter::{SelfConstIfConst, ConstIfConst}, (1) these shouldn't be collected here anyway (const conditions are gathered elsewhere), (2) we don't have any default const or const-if-const trait bounds at the time of writing. Sure, we might have const Sized and const MetaSized in the future (open RFC 3729 | Sized Hierarchy) but then that should be dealt with when that part gets implemented imo.
As a result, PredicateFilter::All is the only filter that makes sense.
| trait B1<T: ?Sized> =; // has a default `T: MetaSized` bound | ||
| fn g1<T: std::marker::PointeeSized>() where (): B1<T> {} | ||
|
|
||
| // For completeness, let's also check default trait bounds on `Self`. |
There was a problem hiding this comment.
We do have tests that exercise add_implicit_sizedness_bounds in implied_predicates_with_filter, namely tests/ui/sized-hierarchy/bound-on-assoc-type-projection.rs and
tests/ui/sized-hierarchy/elaboration-simple.rs. However a trait alias specific one doesn't hurt imo.
|
r? types |
There was a problem hiding this comment.
Would you like me to add negative behavior tests as well? For double-checking that the default trait bounds aren't dropped but simply implied? I was thinking of instantiating these functions with types that don't fulfill the necessary bound, under a separate test revision of course.
SelfSelf
Trait aliases already correctly imply default trait bounds on
Selftype params. However, due to an oversight, they didn't do that for normal type params.Fixes #152687.