Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Reject ?Trait bounds in various places where we unconditionally warned since 1.0 #135841

Merged
merged 1 commit into from
Feb 13, 2025

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Jan 21, 2025

fixes #135730
fixes #135809

Also a breaking change, so let's see what crater says.

This has been an unconditional warning since before 1.0

@rustbot
Copy link
Collaborator

rustbot commented Jan 21, 2025

r? @compiler-errors

rustbot has assigned @compiler-errors.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 Jan 21, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jan 21, 2025

HIR ty lowering was modified

cc @fmease

@oli-obk
Copy link
Contributor Author

oli-obk commented Jan 21, 2025

@bors try

bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 21, 2025
Reject `impl Trait` within `?Trait` generics or assoc ty bounds

fixes rust-lang#135730

Also a breaking change, so let's see what crater says.

This has been an unconditional warning since *before* 1.0
@bors
Copy link
Contributor

bors commented Jan 21, 2025

⌛ Trying commit 757c75f with merge 173780a...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Jan 21, 2025

☀️ Try build successful - checks-actions
Build commit: 173780a (173780a87744406b7489b28349c0176f14bb3881)

@oli-obk
Copy link
Contributor Author

oli-obk commented Jan 22, 2025

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-135841 created and queued.
🤖 Automatically detected try build 173780a
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 22, 2025
@craterbot
Copy link
Collaborator

🚧 Experiment pr-135841 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🎉 Experiment pr-135841 is completed!
📊 5 regressed and 4 fixed (571795 total)
📰 Open the full report.

⚠️ If you notice any spurious failure please add them to the denylist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Jan 25, 2025
@oli-obk oli-obk changed the title Reject impl Trait within ?Trait generics or assoc ty bounds Reject ?Trait bounds in various places where we unconditionally warned since 1.0 Jan 30, 2025
@oli-obk oli-obk added T-types Relevant to the types team, which will review and decide on the PR/issue. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 30, 2025
@oli-obk
Copy link
Contributor Author

oli-obk commented Jan 30, 2025

Hi @rust-lang/types, it turns out we've accepted ?Trait bounds in various places since 1.0 and just emitted an unconditional warning. I have been unable to find the reason for it, but since it doesn't do anything and emitted a warning, it seems no one actually wrote this (crater shows no regressions when turning it into a hard error). Therefor I propose to just turn it into a hard error and subsequently make our lives easier because we don't need to patch situations everywhere in the compiler.

One common source of problems with such bounds is that they can have generics or associated types/consts and all of these just get dropped on the floor and never evaluated, normalized, or otherwise processed in the type system. This leads to fun bugs like not evaluating constants or just ICEing because opaque types never got defined.

@rfcbot fcp merge

@rfcbot
Copy link

rfcbot commented Jan 30, 2025

Team member @oli-obk has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Jan 30, 2025
@lcnr
Copy link
Contributor

lcnr commented Jan 30, 2025

cc @rust-lang/lang for info

I think this is fine as a pure types team FCP. Allowing these bounds is causing bugs without any benefit.

@nikomatsakis
Copy link
Contributor

@rfcbot reviewed

@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Jan 30, 2025
@rfcbot
Copy link

rfcbot commented Jan 30, 2025

🔔 This is now entering its final comment period, as per the review above. 🔔

@compiler-errors compiler-errors added S-waiting-on-fcp Status: PR is in FCP and is awaiting for FCP to complete. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 6, 2025
@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Feb 9, 2025
@rfcbot
Copy link

rfcbot commented Feb 9, 2025

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

@rfcbot rfcbot added the to-announce Announce this issue on triage meeting label Feb 9, 2025
@oli-obk oli-obk added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-fcp Status: PR is in FCP and is awaiting for FCP to complete. labels Feb 9, 2025
Comment on lines 108 to 109
"relaxing a default bound only does something for `?Sized`; \
all other traits are not bound by default",
Copy link
Member

@fmease fmease Feb 12, 2025

Choose a reason for hiding this comment

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

I don't want to block this PR on surface level things like phrasing, so feel free to ignore this and I'll submit this as a follow-up PR. I've never liked how this specific diagnostic is formulated, it's super verbose.

Now with this being a hard error this sentence doesn't quite make sense anymore. I'd rather see a message that's straight to the point like `?` can only be applied to `Sized` (similar to `~const` can only be applied to `#[const_trait]` traits or `async` bound modifier only allowed on `Fn`/`FnMut`/`FnOnce` traits) and defer any further explanations to diagnostic note/help messages if at all (cc error codes).

If we wanted to feel fancy we could provide a structured suggestion for removing the entire bound.

Copy link
Member

Choose a reason for hiding this comment

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

How about we do this as a follow-up

@compiler-errors
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Feb 12, 2025

📌 Commit c294da3 has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 12, 2025
jhpratt added a commit to jhpratt/rust that referenced this pull request Feb 13, 2025
…ler-errors

Reject `?Trait` bounds in various places where we unconditionally warned since 1.0

fixes rust-lang#135730
fixes rust-lang#135809

Also a breaking change, so let's see what crater says.

This has been an unconditional warning since *before* 1.0
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 13, 2025
Rollup of 12 pull requests

Successful merges:

 - rust-lang#134090 (Stabilize target_feature_11)
 - rust-lang#135025 (Cast allocas to default address space)
 - rust-lang#135841 (Reject `?Trait` bounds in various places where we unconditionally warned since 1.0)
 - rust-lang#136217 (Mark condition/carry bit as clobbered in C-SKY inline assembly)
 - rust-lang#136699 (std: replace the `FromInner` implementation for addresses with private conversion functions)
 - rust-lang#136806 (Fix cycle when debug-printing opaque types from RPITIT)
 - rust-lang#136807 (compiler: internally merge `PtxKernel` into `GpuKernel`)
 - rust-lang#136818 (Implement `read*_exact` for `std:io::repeat`)
 - rust-lang#136927 (Correctly escape hashtags when running `invalid_rust_codeblocks` lint)
 - rust-lang#136937 (Update books)
 - rust-lang#136945 (Add diagnostic item for `std::io::BufRead`)
 - rust-lang#136947 (Reinstate nnethercote in the review rotation.)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 6b9b0a0 into rust-lang:master Feb 13, 2025
6 checks passed
@rustbot rustbot added this to the 1.86.0 milestone Feb 13, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Feb 13, 2025
Rollup merge of rust-lang#135841 - oli-obk:push-qxlnokwrkkym, r=compiler-errors

Reject `?Trait` bounds in various places where we unconditionally warned since 1.0

fixes rust-lang#135730
fixes rust-lang#135809

Also a breaking change, so let's see what crater says.

This has been an unconditional warning since *before* 1.0
bjorn3 pushed a commit to bjorn3/rust that referenced this pull request Feb 15, 2025
Rollup of 12 pull requests

Successful merges:

 - rust-lang#134090 (Stabilize target_feature_11)
 - rust-lang#135025 (Cast allocas to default address space)
 - rust-lang#135841 (Reject `?Trait` bounds in various places where we unconditionally warned since 1.0)
 - rust-lang#136217 (Mark condition/carry bit as clobbered in C-SKY inline assembly)
 - rust-lang#136699 (std: replace the `FromInner` implementation for addresses with private conversion functions)
 - rust-lang#136806 (Fix cycle when debug-printing opaque types from RPITIT)
 - rust-lang#136807 (compiler: internally merge `PtxKernel` into `GpuKernel`)
 - rust-lang#136818 (Implement `read*_exact` for `std:io::repeat`)
 - rust-lang#136927 (Correctly escape hashtags when running `invalid_rust_codeblocks` lint)
 - rust-lang#136937 (Update books)
 - rust-lang#136945 (Add diagnostic item for `std::io::BufRead`)
 - rust-lang#136947 (Reinstate nnethercote in the review rotation.)

r? `@ghost`
`@rustbot` modify labels: rollup
Copy link
Member

@fmease fmease left a comment

Choose a reason for hiding this comment

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

Note that this PR doesn't catch all occurrences of ?Trait, TraitSized because performing the validation in add_sized_bound is super backwards and because we don't reject maybe-bounds in ATB position (#135229).

Meaning the following code still compiles successfully and without warnings:

fn _f(_: impl Iterator<Item: ?Copy>) {}

I'll rewrite the way we validate and handle maybe-bounds because I wanted to do that anyway for the longest time (fixing #136944 in the process).

(Lastly, I'll make it so we don't error at all if the internal feature more_maybe_bounds (#121676) is enabled; while I'm personally not in favor of that internal feature, this PR did partially regress it)

(Re. ATBs / #135229, the crater run didn't show any regressions but GH search revealed users using them (mistakenly), so I'll either make it a FCW or hard error regardless (in yet another PR))

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-types Relevant to the types team, which will review and decide on the PR/issue. to-announce Announce this issue on triage meeting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

relaxing a non-Sized bounds is a hard-warning ICE could not unify ! with revealed type