Skip to content

Trait aliases: Also imply default trait bounds on type params other than Self#152688

Open
fmease wants to merge 1 commit intorust-lang:mainfrom
fmease:implied-preds-default-bounds
Open

Trait aliases: Also imply default trait bounds on type params other than Self#152688
fmease wants to merge 1 commit intorust-lang:mainfrom
fmease:implied-preds-default-bounds

Conversation

@fmease
Copy link
Member

@fmease fmease commented Feb 16, 2026

Trait aliases already correctly imply default trait bounds on Self type params. However, due to an oversight, they didn't do that for normal type params.

Fixes #152687.

@fmease fmease added the T-types Relevant to the types team, which will review and decide on the PR/issue. label Feb 16, 2026
@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Feb 16, 2026
@fmease fmease added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Feb 16, 2026
@fmease
Copy link
Member Author

fmease commented Feb 16, 2026

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 16, 2026
rust-bors bot pushed a commit that referenced this pull request Feb 16, 2026
[WIP] Trait aliases: Imply default trait bounds
@rust-log-analyzer

This comment has been minimized.

@fmease fmease force-pushed the implied-preds-default-bounds branch 2 times, most recently from eff5e38 to fdb25e1 Compare February 16, 2026 02:21
@fmease fmease added the rla-silenced Silences rust-log-analyzer postings to the PR it's added on. label Feb 16, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 16, 2026

☀️ Try build successful (CI)
Build commit: ffd787c (ffd787cdc83d953ee66126e6f9b32b4465636845, parent: 139651428df86cf88443295542c12ea617cbb587)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (ffd787c): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking 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
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This 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.

mean range count
Regressions ❌
(primary)
2.6% [2.6%, 2.6%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.6% [2.6%, 2.6%] 1

Cycles

Results (primary 0.2%, secondary 2.6%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.6% [2.6%, 2.6%] 1
Regressions ❌
(secondary)
2.6% [2.6%, 2.6%] 1
Improvements ✅
(primary)
-2.2% [-2.2%, -2.2%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.2% [-2.2%, 2.6%] 2

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 482.657s -> 481.709s (-0.20%)
Artifact size: 397.96 MiB -> 395.94 MiB (-0.51%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 16, 2026
@fmease fmease changed the title [WIP] Trait aliases: Imply default trait bounds [WIP] Trait aliases: Imply default trait bounds on type params other than Self Feb 16, 2026
@fmease fmease force-pushed the implied-preds-default-bounds branch from fdb25e1 to 7269e75 Compare February 16, 2026 15:18
@fmease fmease force-pushed the implied-preds-default-bounds branch from 7269e75 to f61aed1 Compare February 16, 2026 15:19
@fmease fmease changed the title [WIP] Trait aliases: Imply default trait bounds on type params other than Self Trait aliases: Imply default trait bounds on type params other than Self Feb 16, 2026
@fmease fmease added F-trait_alias `#![feature(trait_alias)]` and removed rla-silenced Silences rust-log-analyzer postings to the PR it's added on. labels Feb 16, 2026
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link
Member Author

@fmease fmease Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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`.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@fmease
Copy link
Member Author

fmease commented Feb 16, 2026

r? types

@fmease fmease marked this pull request as ready for review February 16, 2026 15:35
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 16, 2026
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@fmease fmease changed the title Trait aliases: Imply default trait bounds on type params other than Self Trait aliases: Also imply default trait bounds on type params other than Self Feb 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

F-trait_alias `#![feature(trait_alias)]` S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler 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

Successfully merging this pull request may close these issues.

Trait aliases don't imply default trait bounds on type params other than Self

5 participants