Gracefully handle mistyping -> as => in function return type
This commit is contained in:
parent
c4926d01ad
commit
5404deeb64
9 changed files with 96 additions and 6 deletions
18
src/test/ui/fn/fn-fat-arrow-return.fixed
Normal file
18
src/test/ui/fn/fn-fat-arrow-return.fixed
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
// run-rustfix
|
||||
#![allow(unused)]
|
||||
fn a() -> 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() {
|
||||
}
|
||||
18
src/test/ui/fn/fn-fat-arrow-return.rs
Normal file
18
src/test/ui/fn/fn-fat-arrow-return.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
// run-rustfix
|
||||
#![allow(unused)]
|
||||
fn a() => 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() {
|
||||
}
|
||||
8
src/test/ui/fn/fn-fat-arrow-return.stderr
Normal file
8
src/test/ui/fn/fn-fat-arrow-return.stderr
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
error: return types are denoted using `->`
|
||||
--> $DIR/fn-fat-arrow-return.rs:3:8
|
||||
|
|
||||
LL | fn a() => usize { 0 }
|
||||
| ^^ help: use `->` instead
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
10
src/test/ui/fn/fn-fat-arrow-return2.rs
Normal file
10
src/test/ui/fn/fn-fat-arrow-return2.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
fn a() => impl Fn() => bool {
|
||||
//~^ ERROR return types are denoted using `->`
|
||||
//~| ERROR expected `;` or `{`, found `=>`
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let foo = |a: bool| => bool { a };
|
||||
dbg!(foo(false));
|
||||
}
|
||||
14
src/test/ui/fn/fn-fat-arrow-return2.stderr
Normal file
14
src/test/ui/fn/fn-fat-arrow-return2.stderr
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
error: return types are denoted using `->`
|
||||
--> $DIR/fn-fat-arrow-return2.rs:1:8
|
||||
|
|
||||
LL | fn a() => impl Fn() => bool {
|
||||
| ^^ help: use `->` instead
|
||||
|
||||
error: expected `;` or `{`, found `=>`
|
||||
--> $DIR/fn-fat-arrow-return2.rs:1:21
|
||||
|
|
||||
LL | fn a() => impl Fn() => bool {
|
||||
| ^^ expected `;` or `{`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue