-
Notifications
You must be signed in to change notification settings - Fork 14k
misc coercion cleanups and handle safety correctly #148602
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
Open
BoxyUwU
wants to merge
6
commits into
rust-lang:main
Choose a base branch
from
BoxyUwU:coercion_cleanup_uncontroversial
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+717
−432
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8e8794f
non-behaviour changing cleanups
BoxyUwU 05b9fb6
remove normalize call
BoxyUwU a6462ac
explicit leak check enum
BoxyUwU 042b530
Properly handle closure<->closure and fndef<->fndef coerce-lubs
BoxyUwU cdbdcdb
account for safe target features in fndef<->closure and fndef<->fndef…
BoxyUwU d3e3eaa
remove redundant `lub`
BoxyUwU File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| // We have two function parameters with types: | ||
| // - `&?0` | ||
| // - `Box<for<'a> fn(<?0 as Trait<'a>>::Item)>` | ||
| // | ||
| // As the alias in the second parameter has a `?0` it is an ambig | ||
| // alias, and as it references bound vars it can't be normalized to | ||
| // an infer var. | ||
| // | ||
| // When checking function arguments we try to coerce both: | ||
| // - `&()` to `&?0` | ||
| // - `FnDef(f)` to `Box<for<'a> fn(<?0 as Trait<'a>>::Item)>` | ||
| // | ||
| // The first coercion infers `?0=()`. Previously when handling | ||
| // the second coercion we wound *re-normalize* the alias, which | ||
| // now that `?0` has been inferred allowed us to determine this | ||
| // alias is not wellformed and normalize it to some infer var `?1`. | ||
| // | ||
| // We would then see that `FnDef(f)` can't be coerced to `Box<fn(?1)>` | ||
| // and return a `TypeError` referencing this new variable `?1`. This | ||
| // then caused ICEs as diagnostics would encounter inferences variables | ||
| // from the result of normalization inside of the probe used be coercion. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add comment that regression test for #132765? |
||
|
|
||
|
|
||
| trait LendingIterator { | ||
| type Item<'q>; | ||
| fn for_each(&self, _f: Box<fn(Self::Item<'_>)>) {} | ||
| } | ||
|
|
||
| fn f(_: ()) {} | ||
|
|
||
| fn main() { | ||
| LendingIterator::for_each(&(), f); | ||
| //~^ ERROR: the trait bound `(): LendingIterator` is not satisfied | ||
| //~| ERROR: the trait bound `(): LendingIterator` is not satisfied | ||
| //~| ERROR: mismatched types | ||
| } | ||
46 changes: 46 additions & 0 deletions
46
tests/ui/coercion/hr_alias_normalization_leaking_vars.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| error[E0277]: the trait bound `(): LendingIterator` is not satisfied | ||
| --> $DIR/hr_alias_normalization_leaking_vars.rs:32:31 | ||
| | | ||
| LL | LendingIterator::for_each(&(), f); | ||
| | ------------------------- ^^^ the trait `LendingIterator` is not implemented for `()` | ||
| | | | ||
| | required by a bound introduced by this call | ||
| | | ||
| help: this trait has no implementations, consider adding one | ||
| --> $DIR/hr_alias_normalization_leaking_vars.rs:24:1 | ||
| | | ||
| LL | trait LendingIterator { | ||
| | ^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| error[E0308]: mismatched types | ||
| --> $DIR/hr_alias_normalization_leaking_vars.rs:32:36 | ||
| | | ||
| LL | LendingIterator::for_each(&(), f); | ||
| | ------------------------- ^ expected `Box<fn(...)>`, found fn item | ||
| | | | ||
| | arguments to this function are incorrect | ||
| | | ||
| = note: expected struct `Box<for<'a> fn(<() as LendingIterator>::Item<'a>)>` | ||
| found fn item `fn(()) {f}` | ||
| note: method defined here | ||
| --> $DIR/hr_alias_normalization_leaking_vars.rs:26:8 | ||
| | | ||
| LL | fn for_each(&self, _f: Box<fn(Self::Item<'_>)>) {} | ||
| | ^^^^^^^^ --------------------------- | ||
|
|
||
| error[E0277]: the trait bound `(): LendingIterator` is not satisfied | ||
| --> $DIR/hr_alias_normalization_leaking_vars.rs:32:36 | ||
| | | ||
| LL | LendingIterator::for_each(&(), f); | ||
| | ^ the trait `LendingIterator` is not implemented for `()` | ||
| | | ||
| help: this trait has no implementations, consider adding one | ||
| --> $DIR/hr_alias_normalization_leaking_vars.rs:24:1 | ||
| | | ||
| LL | trait LendingIterator { | ||
| | ^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| error: aborting due to 3 previous errors | ||
|
|
||
| Some errors have detailed explanations: E0277, E0308. | ||
| For more information about an error, try `rustc --explain E0277`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand that FIXME. Normalizing inside of a probe is totally fine as long as we don't leak the infer vars. This happens for errors of
commit_if_okbut I don't think not normalizing is the solution here.More specifically, we have to normalize here as the fn-sig is the unnnormalized one from a function definition