Skip to content

Conversation

Bryanskiy
Copy link
Contributor

First commit: the motivation has been discussed here.

Second commit: the only new places where new implicit DefaultAutoTrait bounds are generated are supertraits and trait object so ?Trait syntax should be extended to these places only.

r? @lcnr

@rustbot rustbot added 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. labels Aug 26, 2025
@rustbot
Copy link
Collaborator

rustbot commented Aug 26, 2025

HIR ty lowering was modified

cc @fmease

@@ -21,6 +21,20 @@ fn bar<T: ?Sized + ?Trait2 + ?Trait1 + ?Trait4>(_: &T) {}

// FIXME: `?Trait1` should be rejected, `Trait1` isn't marked `#[lang = "default_traitN"]`.
fn baz<T>() where T: Iterator<Item: ?Trait1> {}
//~^ ERROR this relaxed bound is not permitted here
Copy link
Member

Choose a reason for hiding this comment

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

Please remove the above FIXME

Copy link
Member

@fmease fmease Aug 26, 2025

Choose a reason for hiding this comment

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

Moreover this test is quite a mixed bag, it's unclear what the test intentions are. In #142693 I almost deleted it for that reason but I kept it to track bugs pertaining to more_maybe_bounds instead (as can be seen by the top-level FIXME).

I don't think we should test "this relaxed bound is not permitted here" in this file, I'd advise you to create a new one whose name is based on tests/ui/unsized/relaxed-bounds-invalid-places.rs (obv not inside unsized/; maybe have both test files in trait-bounds/ actually).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From my understanding there are 2 checks for relaxed bounds consistency:

  • Syntactic check during AST->HIR lowering (validate_relaxed_bound) to ensure that ?Trait bounds are in a right place.
  • Semantic check during HIR->ty lowering (check_and_report_invalid_relaxed_bounds) to ensure that ? modifier is applied to "right" traits. And this check has to be done regardless of the place and results of the first check.

This PR fixes the first check but not the second and therefore FIXME comments in this file are still relevant.

So, your suggestion is to keep these checks in separate files for readability reasons, right? In my opinion it isn't very useful because the invocation of second check implies that the first check has already been invoked. That is, the test that covers the second check also covers the first one.

@rustbot
Copy link
Collaborator

rustbot commented Aug 26, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants