Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix validation when lowering ? trait bounds #132209

Merged
merged 2 commits into from
Nov 1, 2024

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Oct 27, 2024

Pass the unlowered (rustc_hir) polarity to lower_poly_trait_ref.

This allows us to actually validate that generic args are actually valid on ?Trait paths. This actually regressed in #113671 because that PR changed the behavior where we were inadvertently re-lowering paths as BoundPolarity::Positive, which was also coincidentally the only place we were enforcing the generics on ?Trait paths were correct.

@rustbot
Copy link
Collaborator

rustbot commented Oct 27, 2024

r? @Nadrieril

rustbot has assigned @Nadrieril.
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 Oct 27, 2024
@rustbot
Copy link
Collaborator

rustbot commented Oct 27, 2024

HIR ty lowering was modified

cc @fmease

@compiler-errors
Copy link
Member Author

Funny enough, this code passes on nightly:

fn uwu<T: ?Sized<i32>>() {}

@@ -681,11 +681,20 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
Some(self_ty),
Copy link
Member Author

@compiler-errors compiler-errors Oct 27, 2024

Choose a reason for hiding this comment

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

^(a handful of lines above) we were probably also allowing ?std::ops::Fn<T> but i dont care to write a test for that.

@compiler-errors compiler-errors changed the title Improve lowering of poly trait refs Fix validation when lowering ? trait bounds, improve spans for const trait bounds Oct 27, 2024
@compiler-errors
Copy link
Member Author

Frankly I am of half a mind to say that we don't need to do the annoying and time-consuming dance of cratering the regression for (2.). If this actually ended up being "used" anywhere in the wild, then we will obviously catch this in the next beta crater and deal with it then, or I can crater this after it's landed.

@Nadrieril
Copy link
Member

The span change I can approve; the validation change looks good but I don't know that code, @fmease any objections?

@compiler-errors
Copy link
Member Author

Actually, I'll just split the span change out and just r=Nadrieril on that one first, since it's really kinda unrelated. My fault for putting this into one PR rbh.

@fmease fmease assigned fmease and unassigned Nadrieril Oct 27, 2024
jieyouxu added a commit to jieyouxu/rust that referenced this pull request Oct 28, 2024
… r=Nadrieril

Pass constness with span into lower_poly_trait_ref

Gives us a span to point at for ~const/const on non-const traits.

Split from rust-lang#132209. r? Nadrieril
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Oct 28, 2024
Rollup merge of rust-lang#132227 - compiler-errors:better-const-span, r=Nadrieril

Pass constness with span into lower_poly_trait_ref

Gives us a span to point at for ~const/const on non-const traits.

Split from rust-lang#132209. r? Nadrieril
@fmease fmease changed the title Fix validation when lowering ? trait bounds, improve spans for const trait bounds Fix validation when lowering ? trait bounds Oct 30, 2024
@fmease
Copy link
Member

fmease commented Oct 30, 2024

This actually regressed in #113671 because that PR changed the behavior where we were inadvertently re-lowering paths as BoundPolarity::Positive, which was also coincidentally the only place we were enforcing the generics on ?Trait paths were correct.

Omg, this is insane! 🙏 Thanks for catching this!

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.

I have one concern but otherwise looks pretty good to me!

Comment on lines 688 to 710
// No-op.
return arg_count;
Copy link
Member

@fmease fmease Oct 30, 2024

Choose a reason for hiding this comment

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

Doesn't this early return mean we don't validate associated item constraints which get lowered below this point in lower_assoc_item_constraint? E.g., isn't it still the case that ?Sized<Undefined = (), Undefined = ()> gets accepted under this PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

:'( yeah

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, so I made it so that we at least validate these associated type bounds, but not outright deny them. We may want to do that later.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 30, 2024
@compiler-errors
Copy link
Member Author

@rustbot ready

@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 Oct 31, 2024
@fmease
Copy link
Member

fmease commented Oct 31, 2024

@bors r+

@bors
Copy link
Contributor

bors commented Oct 31, 2024

📌 Commit 06a49b6 has been approved by fmease

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 Oct 31, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 31, 2024
Fix validation when lowering `?` trait bounds

Pass the unlowered (`rustc_hir`) polarity to `lower_poly_trait_ref`.

This allows us to actually *validate* that generic args are actually valid on `?Trait` paths. This actually regressed in rust-lang#113671 because that PR changed the behavior where we were inadvertently re-lowering paths as `BoundPolarity::Positive`, which was also coincidentally the only place we were enforcing the generics on `?Trait` paths were correct.
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 31, 2024
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#131168 (Fix `target_os` for `mipsel-sony-psx`)
 - rust-lang#132209 (Fix validation when lowering `?` trait bounds)
 - rust-lang#132357 (Improve missing_abi lint)
 - rust-lang#132385 (compiler: Move `rustc_target::spec::abi::Abi` to `rustc_abi::ExternAbi`)
 - rust-lang#132417 (macOS: Document the difference between Clang's `-darwin` and `-macosx` targets)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 1, 2024
…kingjubilee

Rollup of 9 pull requests

Successful merges:

 - rust-lang#131168 (Fix `target_os` for `mipsel-sony-psx`)
 - rust-lang#132209 (Fix validation when lowering `?` trait bounds)
 - rust-lang#132294 (Bump Fuchsia)
 - rust-lang#132357 (Improve missing_abi lint)
 - rust-lang#132385 (compiler: Move `rustc_target::spec::abi::Abi` to `rustc_abi::ExternAbi`)
 - rust-lang#132403 (continue `TypingMode` refactor)
 - rust-lang#132417 (macOS: Document the difference between Clang's `-darwin` and `-macosx` targets)
 - rust-lang#132421 (Remove `""` case from RISC-V `llvm_abiname` match statement)
 - rust-lang#132422 (llvm: Match new LLVM 128-bit integer alignment on sparc)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit e31988c into rust-lang:master Nov 1, 2024
6 checks passed
@rustbot rustbot added this to the 1.84.0 milestone Nov 1, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 1, 2024
Rollup merge of rust-lang#132209 - compiler-errors:modifiers, r=fmease

Fix validation when lowering `?` trait bounds

Pass the unlowered (`rustc_hir`) polarity to `lower_poly_trait_ref`.

This allows us to actually *validate* that generic args are actually valid on `?Trait` paths. This actually regressed in rust-lang#113671 because that PR changed the behavior where we were inadvertently re-lowering paths as `BoundPolarity::Positive`, which was also coincidentally the only place we were enforcing the generics on `?Trait` paths were correct.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

5 participants