-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Do leak check after function pointer coercion #97206
Conversation
// want the coerced type to be the actual supertype of these two, | ||
// but for now, we want to just error to ensure we don't lock | ||
// ourselves into a specific behavior with NLL. | ||
self.leak_check(false, snapshot)?; |
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 will admit that I have no idea if this should be false
or true
.
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.
The name is not very good. It only affects diagnostics. I think the idea is that you say true if the "placeholders" result from the "actual type" and false if they come from the expected type.
In this instance, B is the expected type, I think, and the placeholders would come from B, so I guess that makes false the proper value. (i.e., the value you are supplying is insufficiently polymorphic to be cast to the type required).
@@ -11,23 +11,20 @@ fn b<'a, 'b>(x: &mut &'a isize, y: &mut &'b isize) { | |||
// Illegal now because there is no `'b:'a` declaration. | |||
*x = *y; | |||
//[base]~^ ERROR E0623 | |||
//[nll]~^^ ERROR lifetime may not live long enough |
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 think these errors disappear because they are borrowck errors, but we now error and bail in typeck.
@@ -11,23 +11,20 @@ fn b<'a, 'b>(x: &mut &'a isize, y: &mut &'b isize) { | |||
// Illegal now because there is no `'b:'a` declaration. | |||
*x = *y; | |||
//[base]~^ ERROR lifetime mismatch [E0623] | |||
//[nll]~^^ ERROR lifetime may not live long enough |
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.
Same here.
found fn pointer `for<'r, 's, 't0> fn(&'r mut &isize, &'s mut &isize, &'t0 mut &isize)` | ||
found fn item `for<'r, 's, 't0> fn(&'r mut &isize, &'s mut &isize, &'t0 mut &isize) {a::<'_, '_, '_>}` |
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 is nice.
note: function defined here | ||
--> $DIR/regions-fn-subtyping-return-static-fail.rs:24:4 | ||
| | ||
LL | fn want_G(f: G) {} | ||
| ^^^^^^ ---- |
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 too.
8a1dc74
to
a9decbe
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
📌 Commit 719ef0d has been approved by |
Do leak check after function pointer coercion cc rust-lang#73154 I still need to clean diagnostics just a tad, but figured I would put this up anyways. This change is made in order to make match arm coercion order-independent. Basically, any time we do function pointer coercion, we follow it by doing a leak check. This is necessary because the LUB code doesn't handler higher-ranked things correctly, leading us to "coerce", but use the wrong type. A proper fix is to actually fix that code (so the type returned by `unify_and` is a supertype of both `a` and `b` if `Ok`). However, that requires a more in-depth fix, likely heavily overlapping with the new subtyping changes. Here, I've been conservative and error early if we generate unsatisfiable constraints. Note, this should *mostly* only affect NLL, since migrate mode falls back to the LUB implementation (followed by leak check), whereas NLL only does sub. There could be other coercion code that has an order-dependence where a leak check in the coercion code might be useful. However, this is more of a spot-fix for rust-lang#73154 than a "permanent" fix, since we likely want to go the other way long-term, and allow this pattern without error. r? `@nikomatsakis`
☔ The latest upstream changes (presumably #97239) made this pull request unmergeable. Please resolve the merge conflicts. |
@bors r+ |
📌 Commit baf1966b3c75fff6174c31da4a0574793bc2ace8 has been approved by |
📌 Commit baf1966b3c75fff6174c31da4a0574793bc2ace8 has been approved by |
@bors r=nikomatsakis |
💡 This pull request was already approved, no need to approve it again.
|
📌 Commit baf1966b3c75fff6174c31da4a0574793bc2ace8 has been approved by |
Oh thanks @lcnr :) missed that |
⌛ Testing commit baf1966b3c75fff6174c31da4a0574793bc2ace8 with merge 66e5c5953352dd6ce2a6cbae77dd187880e38510... |
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
@bors r=nikomatsakis |
📌 Commit 683a9c8 has been approved by |
Rollup of 5 pull requests Successful merges: - rust-lang#97043 (Move some tests to more reasonable directories) - rust-lang#97206 (Do leak check after function pointer coercion) - rust-lang#97275 (small change) - rust-lang#97277 (Avoid accidentally enabling unstable features in compilers (take 2)) - rust-lang#97280 (Quote replace target in bootstrap configure) Failed merges: - rust-lang#97214 (Finish bumping stage0) r? `@ghost` `@rustbot` modify labels: rollup
Move remaining tests with NLL differences to revisions Based on rust-lang#97206 I've already filed issues for any important differences that I've spotted: rust-lang#97252 rust-lang#97253 rust-lang#97256 rust-lang#97267 There is a lot here, but each commit is self-contained as a separate directory. I can split into separate PRs as wanted or needed.
cc #73154
I still need to clean diagnostics just a tad, but figured I would put this up anyways.
This change is made in order to make match arm coercion order-independent.
Basically, any time we do function pointer coercion, we follow it by doing a leak check. This is necessary because the LUB code doesn't handler higher-ranked things correctly, leading us to "coerce", but use the wrong type. A proper fix is to actually fix that code (so the type returned by
unify_and
is a supertype of botha
andb
ifOk
). However, that requires a more in-depth fix, likely heavily overlapping with the new subtyping changes.Here, I've been conservative and error early if we generate unsatisfiable constraints. Note, this should mostly only affect NLL, since migrate mode falls back to the LUB implementation (followed by leak check), whereas NLL only does sub.
There could be other coercion code that has an order-dependence where a leak check in the coercion code might be useful. However, this is more of a spot-fix for #73154 than a "permanent" fix, since we likely want to go the other way long-term, and allow this pattern without error.
r? @nikomatsakis