Skip to content

Conversation

fmease
Copy link
Member

@fmease fmease commented Oct 15, 2025

Follow-up to #142693, #135331 and #135841.
Fixes #143122.

  • Reject relaxed bounds ?Trait in the bounds of trait aliases.
    Just like trait Trait {} doesn't mean trait Trait: Sized {} and we therefore reject trait Trait: ?Sized {}, trait Trait =; (sic!) doesn't mean trait Trait = Sized; (never did!) and as logical consequence trait Trait = ?Sized; is meaningless and should be forbidden.
  • Don't permit ?Sized in more places (e.g., supertrait bounds, trait object types) if feature more_maybe_bounds is enabled.
    That internal feature is only meant to allow the user to define & use new default traits (that have fewer rules to follow for now to ease experimentation).
  • Slightly improve diagnostics.
  • Unconditionally check that the Trait in ?Trait is a default trait.
    Previously, we would only perform this check in selected places which was very brittle and led to bugs slipping through.

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

fmease commented Oct 15, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Oct 15, 2025
Further tighten up relaxed bounds
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 15, 2025
@rust-log-analyzer

This comment was marked as resolved.

@rust-bors
Copy link

rust-bors bot commented Oct 15, 2025

☀️ Try build successful (CI)
Build commit: 9ed9a73 (9ed9a7337cbbb431708bcd7085fadfe1719c28c3, parent: 28d0a4a205f9e511ad2f51ee79a4aa19a704a455)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (9ed9a73): 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 -3.8%)

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

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-3.8% [-6.7%, -1.0%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -3.8% [-6.7%, -1.0%] 2

Cycles

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

Binary size

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

Bootstrap: 474.854s -> 475.36s (0.11%)
Artifact size: 388.09 MiB -> 388.06 MiB (-0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 15, 2025
@fmease fmease force-pushed the tighten-relaxed branch 2 times, most recently from 2453034 to 5fab794 Compare October 16, 2025 14:19
@fmease fmease added the rla-silenced Silences rust-log-analyzer postings to the PR it's added on. label Oct 16, 2025
@fmease
Copy link
Member Author

fmease commented Oct 16, 2025

@bors rollup-

@fmease fmease removed the rla-silenced Silences rust-log-analyzer postings to the PR it's added on. label Oct 16, 2025
@fmease fmease force-pushed the tighten-relaxed branch 2 times, most recently from 79993ba to 86cd4b0 Compare October 16, 2025 17:20
Copy link
Member Author

@fmease fmease Oct 16, 2025

Choose a reason for hiding this comment

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

"Completely" unrelated to feature sized_hierarchy. Well, it must've once ICE'd during the development of sized_hierarchy and the PR that introduced it did affect stable behavior.

In any case, since ?Sized is now illegal inside trait alias bounds, this is now covered by test tests/ui/traits/alias/relaxed-bounds.rs.

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, we did not have any UI test for trait Empty =; prior.

Copy link
Member Author

Choose a reason for hiding this comment

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

Superseded by tests/ui/traits/alias/effectively-empty-trait-object-type.rs.

Copy link
Member Author

Choose a reason for hiding this comment

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

Moved into tests/ui/unsized/relaxed-bounds-invalid-places.rs.

Copy link
Member Author

Choose a reason for hiding this comment

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

Superseded by tests/ui/traits/alias/relaxed-bounds.rs.

Comment on lines +8 to +10
//~| ERROR bound modifier `?` can only be applied to `Sized`
//~| ERROR bound modifier `?` can only be applied to `Sized`
//~| ERROR bound modifier `?` can only be applied to `Sized`
Copy link
Member Author

Choose a reason for hiding this comment

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

Duplicate diagnostics (under -Zdeduplicate-diagnostics=no) because we lower the supertraits multiple times during HIR ty lowering likely under different predicate filters (HIR ty lowering needs to do this sort of thing in a bunch of situations to avoid query cycles).

Copy link
Member Author

@fmease fmease Oct 16, 2025

Choose a reason for hiding this comment

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

(This test is just a mixed bag, always has been, and that's fine, the feature is internal and still evolving)

trait_ref.path.segments.split_last().unwrap().1.iter(),
GenericsArgsErrExtend::None,
);
let [leading_segments @ .., segment] = trait_ref.path.segments else { bug!() };
Copy link
Member Author

Choose a reason for hiding this comment

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

Drive-by refactoring

@fmease fmease marked this pull request as ready for review October 16, 2025 17:54
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 16, 2025
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Oct 16, 2025
@rustbot

This comment was marked as outdated.

@fmease
Copy link
Member Author

fmease commented Oct 16, 2025

r? compiler

@rustbot rustbot assigned petrochenkov and unassigned SparrowLii Oct 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

We don't fully validate relaxed trait bounds on the RHS of trait aliases (should we actually reject them outright?)

6 participants