-
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 #78901 - arora-aman:fix_closure_coerce, r=estebank
diagnostics: Note capturing closures can't be coerced to fns Fixes #72457, fixes #71895 r? `@estebank`
- Loading branch information
Showing
10 changed files
with
121 additions
and
1 deletion.
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
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,8 @@ | ||
fn main() { | ||
let b = 2; | ||
let _: fn(usize) -> usize = match true { | ||
true => |a| a + 1, | ||
false => |a| a - b, | ||
//~^ ERROR `match` arms have incompatible types | ||
}; | ||
} |
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,24 @@ | ||
error[E0308]: `match` arms have incompatible types | ||
--> $DIR/closure-no-fn-4.rs:5:18 | ||
| | ||
LL | let _: fn(usize) -> usize = match true { | ||
| _________________________________- | ||
LL | | true => |a| a + 1, | ||
| | --------- this is found to be of type `fn(usize) -> usize` | ||
LL | | false => |a| a - b, | ||
| | ^^^^^^^^^ expected fn pointer, found closure | ||
LL | | | ||
LL | | }; | ||
| |_____- `match` arms have incompatible types | ||
| | ||
= note: expected fn pointer `fn(usize) -> usize` | ||
found closure `[closure@$DIR/closure-no-fn-4.rs:5:18: 5:27]` | ||
note: closures can only be coerced to `fn` types if they do not capture any variables | ||
--> $DIR/closure-no-fn-4.rs:5:26 | ||
| | ||
LL | false => |a| a - b, | ||
| ^ `b` captured here | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
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 @@ | ||
// When providing diagnostics about not being able to coerce a capturing-closure | ||
// to fn type, we want to report only upto 4 captures. | ||
|
||
fn main() { | ||
let a = 0u8; | ||
let b = 0u8; | ||
let c = 0u8; | ||
let d = 0u8; | ||
let e = 0u8; | ||
let bar: fn() -> u8 = || { a; b; c; d; e }; | ||
//~^ ERROR mismatched types | ||
} |
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,23 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/closure-no-fn-5.rs:10:27 | ||
| | ||
LL | let bar: fn() -> u8 = || { a; b; c; d; e }; | ||
| ---------- ^^^^^^^^^^^^^^^^^^^^ expected fn pointer, found closure | ||
| | | ||
| expected due to this | ||
| | ||
= note: expected fn pointer `fn() -> u8` | ||
found closure `[closure@$DIR/closure-no-fn-5.rs:10:27: 10:47]` | ||
note: closures can only be coerced to `fn` types if they do not capture any variables | ||
--> $DIR/closure-no-fn-5.rs:10:32 | ||
| | ||
LL | let bar: fn() -> u8 = || { a; b; c; d; e }; | ||
| ^ ^ ^ ^ `d` captured here | ||
| | | | | ||
| | | `c` captured here | ||
| | `b` captured here | ||
| `a` captured here | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
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