-
Notifications
You must be signed in to change notification settings - Fork 13.3k
-Znext-solver: "normalize" signature before checking it mentions self in deduce_closure_signature
#135892
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
Merged
bors
merged 1 commit into
rust-lang:master
from
BoxyUwU:next_solver_deduce_sig_normalized
Jan 28, 2025
Merged
-Znext-solver: "normalize" signature before checking it mentions self in deduce_closure_signature
#135892
Changes from all commits
Commits
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 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 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 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 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 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 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
52 changes: 52 additions & 0 deletions
52
tests/ui/traits/next-solver/closure-signature-inference-hr-ambig-alias-naming-self.rs
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,52 @@ | ||
//@ check-pass | ||
//@ revisions: current next | ||
//@[next] compile-flags: -Znext-solver | ||
|
||
// When type checking a closure expr we look at the list of unsolved goals | ||
// to determine if there are any bounds on the closure type to infer a signature from. | ||
// | ||
// We attempt to discard goals that name the closure type so as to avoid inferring the | ||
// closure type to something like `?x = closure(sig=fn(?x))`. This test checks that when | ||
// such a goal names the closure type inside of an ambiguous alias and there exists another | ||
// potential goal to infer the closure signature from, we do that. | ||
|
||
trait Trait<'a> { | ||
type Assoc; | ||
} | ||
|
||
impl<'a, F> Trait<'a> for F { | ||
type Assoc = u32; | ||
} | ||
|
||
fn closure_typer1<F>(_: F) | ||
where | ||
F: Fn(u32) + for<'a> Fn(<F as Trait<'a>>::Assoc), | ||
{ | ||
} | ||
|
||
fn closure_typer2<F>(_: F) | ||
where | ||
F: for<'a> Fn(<F as Trait<'a>>::Assoc) + Fn(u32), | ||
{ | ||
} | ||
|
||
fn main() { | ||
// Here we have some closure with a yet to be inferred type of `?c`. There are two goals | ||
// involving `?c` that can be used to determine the closure signature: | ||
// - `?c: for<'a> Fn<(<?c as Trait<'a>>::Assoc,), Output = ()>` | ||
// - `?c: Fn<(u32,), Output = ()>` | ||
// | ||
// If we were to infer the argument of the closure (`x` below) to `<?c as Trait<'a>>::Assoc` | ||
// then we would not be able to call `x.into()` as `x` is some unknown type. Instead we must | ||
// use the `?c: Fn(u32)` goal to infer a signature in order for this code to compile. | ||
// | ||
// As the algorithm for picking a goal to infer the signature from is dependent on the ordering | ||
// of pending goals in the type checker, we test both orderings of bounds to ensure we aren't | ||
// testing that we just *happen* to pick `?c: Fn(u32)`. | ||
closure_typer1(move |x| { | ||
let _: u32 = x.into(); | ||
}); | ||
closure_typer2(move |x| { | ||
let _: u32 = x.into(); | ||
}); | ||
} |
Oops, something went wrong.
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.
This comment feels a bit detached from where closure signature inference is located xd