-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #77035 - mibac138:fn-fat-arrow-return, r=davidtwco
Gracefully handle mistyping -> as => in function return type Fixes #77019
- Loading branch information
Showing
14 changed files
with
255 additions
and
25 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
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,28 @@ | ||
// run-rustfix | ||
#![allow(unused)] | ||
fn a() -> usize { 0 } | ||
//~^ ERROR return types are denoted using `->` | ||
|
||
fn b()-> usize { 0 } | ||
//~^ ERROR return types are denoted using `->` | ||
|
||
fn bar(_: u32) {} | ||
|
||
fn baz() -> *const dyn Fn(u32) { unimplemented!() } | ||
|
||
fn foo() { | ||
match () { | ||
_ if baz() == &bar as &dyn Fn(u32) => (), | ||
() => (), | ||
} | ||
} | ||
|
||
fn main() { | ||
let foo = |a: bool| -> bool { a }; | ||
//~^ ERROR return types are denoted using `->` | ||
dbg!(foo(false)); | ||
|
||
let bar = |a: bool|-> bool { a }; | ||
//~^ ERROR return types are denoted using `->` | ||
dbg!(bar(false)); | ||
} |
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,28 @@ | ||
// run-rustfix | ||
#![allow(unused)] | ||
fn a() => usize { 0 } | ||
//~^ ERROR return types are denoted using `->` | ||
|
||
fn b(): usize { 0 } | ||
//~^ ERROR return types are denoted using `->` | ||
|
||
fn bar(_: u32) {} | ||
|
||
fn baz() -> *const dyn Fn(u32) { unimplemented!() } | ||
|
||
fn foo() { | ||
match () { | ||
_ if baz() == &bar as &dyn Fn(u32) => (), | ||
() => (), | ||
} | ||
} | ||
|
||
fn main() { | ||
let foo = |a: bool| => bool { a }; | ||
//~^ ERROR return types are denoted using `->` | ||
dbg!(foo(false)); | ||
|
||
let bar = |a: bool|: bool { a }; | ||
//~^ ERROR return types are denoted using `->` | ||
dbg!(bar(false)); | ||
} |
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,26 @@ | ||
error: return types are denoted using `->` | ||
--> $DIR/fn-recover-return-sign.rs:3:8 | ||
| | ||
LL | fn a() => usize { 0 } | ||
| ^^ help: use `->` instead | ||
|
||
error: return types are denoted using `->` | ||
--> $DIR/fn-recover-return-sign.rs:6:7 | ||
| | ||
LL | fn b(): usize { 0 } | ||
| ^ help: use `->` instead | ||
|
||
error: return types are denoted using `->` | ||
--> $DIR/fn-recover-return-sign.rs:21:25 | ||
| | ||
LL | let foo = |a: bool| => bool { a }; | ||
| ^^ help: use `->` instead | ||
|
||
error: return types are denoted using `->` | ||
--> $DIR/fn-recover-return-sign.rs:25:24 | ||
| | ||
LL | let bar = |a: bool|: bool { a }; | ||
| ^ help: use `->` instead | ||
|
||
error: aborting due to 4 previous errors | ||
|
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 @@ | ||
// Separate test file because `Fn() => bool` isn't getting fixed and rustfix complained that | ||
// even though a fix was applied the code was still incorrect | ||
|
||
fn foo() => impl Fn() => bool { | ||
//~^ ERROR return types are denoted using `->` | ||
//~| ERROR expected one of `+`, `->`, `::`, `;`, `where`, or `{`, found `=>` | ||
unimplemented!() | ||
} |
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,14 @@ | ||
error: return types are denoted using `->` | ||
--> $DIR/fn-recover-return-sign2.rs:4:10 | ||
| | ||
LL | fn foo() => impl Fn() => bool { | ||
| ^^ help: use `->` instead | ||
|
||
error: expected one of `+`, `->`, `::`, `;`, `where`, or `{`, found `=>` | ||
--> $DIR/fn-recover-return-sign2.rs:4:23 | ||
| | ||
LL | fn foo() => impl Fn() => bool { | ||
| ^^ expected one of `+`, `->`, `::`, `;`, `where`, or `{` | ||
|
||
error: aborting due to 2 previous errors | ||
|
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
error: expected one of `->`, `;`, `where`, or `{`, found `:` | ||
error: return types are denoted using `->` | ||
--> $DIR/fn-colon-return-type.rs:1:15 | ||
| | ||
LL | fn foo(x: i32): i32 { | ||
| ^ expected one of `->`, `;`, `where`, or `{` | ||
| ^ help: use `->` instead | ||
|
||
error: aborting due to previous error | ||
|
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 |
---|---|---|
@@ -1,6 +1,15 @@ | ||
fn f(a: isize, b: isize) : lt(a, b) { } | ||
//~^ ERROR expected one of `->`, `;`, `where`, or `{`, found `:` | ||
//~^ ERROR return types are denoted using `->` | ||
//~| ERROR expected type, found function `lt` [E0573] | ||
//~| ERROR expected type, found local variable `a` [E0573] | ||
//~| ERROR expected type, found local variable `b` [E0573] | ||
|
||
fn lt(a: isize, b: isize) { } | ||
|
||
fn main() { let a: isize = 10; let b: isize = 23; check (lt(a, b)); f(a, b); } | ||
fn main() { | ||
let a: isize = 10; | ||
let b: isize = 23; | ||
check (lt(a, b)); | ||
//~^ ERROR cannot find function `check` in this scope [E0425] | ||
f(a, b); | ||
} |
Oops, something went wrong.