-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Gracefully handle mistyping -> as => in function return type #77035
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How come rustfix does not add a space here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rustfmt doesn't run on the test suite (and shouldn't, because sometimes the tests are for the parser, and the parser should be whitespace-independent). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this the output of rustfix? Shouldn't rustfix code output be sightly formatted (at least not as good as rustfmt)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh! I missed that this is a
Ideally the suggestion would add its own space, yeah. |
||
//~^ 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)); | ||
} |
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)); | ||
} |
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 | ||
|
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!() | ||
} |
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 | ||
|
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 | ||
|
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); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.