-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #129059 - compiler-errors:subtyping-correct-type, r=lcnr
Record the correct target type when coercing fn items/closures to pointers Self-explanatory. We were previously not recording the *target* type of a coercion as the output of an adjustment. This should remedy that. We must also modify the function pointer casts in MIR typeck to use subtyping, since those broke since #118247. r? lcnr
- Loading branch information
Showing
8 changed files
with
55 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 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 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,18 @@ | ||
// MIR for `main` after built | ||
|
||
fn main() -> () { | ||
let mut _0: (); | ||
let _1: for<'a> fn(&'a (), &'a ()); | ||
scope 1 { | ||
debug x => _1; | ||
} | ||
|
||
bb0: { | ||
StorageLive(_1); | ||
_1 = foo as for<'a> fn(&'a (), &'a ()) (PointerCoercion(ReifyFnPointer)); | ||
FakeRead(ForLet(None), _1); | ||
_0 = const (); | ||
StorageDead(_1); | ||
return; | ||
} | ||
} |
This file contains 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,12 @@ | ||
// skip-filecheck | ||
|
||
// Validate that we record the target for the `as` coercion as `for<'a> fn(&'a (), &'a ())`, | ||
// and not `for<'a, 'b>(&'a (), &'b ())`. We previously did the latter due to a bug in | ||
// the code that records adjustments in HIR typeck. | ||
|
||
fn foo<'a, 'b>(_: &'a (), _: &'b ()) {} | ||
|
||
// EMIT_MIR build_correct_coerce.main.built.after.mir | ||
fn main() { | ||
let x = foo as for<'a> fn(&'a (), &'a ()); | ||
} |
This file contains 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,10 @@ | ||
//@ check-pass | ||
|
||
// Check that we use subtyping when reifying a closure into a function pointer. | ||
|
||
fn foo(x: &str) {} | ||
|
||
fn main() { | ||
let c = |_: &str| {}; | ||
let x = c as fn(&'static str); | ||
} |
This file contains 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 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 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