-
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.
Fix a error suggestion of situation when using placeholder
_
as ret…
…urn types on function signature. fixes #125488
- Loading branch information
Showing
4 changed files
with
195 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
33 changes: 33 additions & 0 deletions
33
tests/ui/return/infer-return-ty-for-fn-sig-issue-125488.fixed
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,33 @@ | ||
//@ run-rustfix | ||
|
||
#[allow(dead_code)] | ||
|
||
fn main() { | ||
struct S<'a>(&'a ()); | ||
|
||
fn f1(s: S<'_>) -> S<'_> { | ||
//~^ ERROR the placeholder `_` is not allowed | ||
s | ||
} | ||
|
||
fn f2(s: S<'_>) -> S<'_> { | ||
//~^ ERROR the placeholder `_` is not allowed | ||
let x = true; | ||
if x { | ||
s | ||
} else { | ||
s | ||
} | ||
} | ||
|
||
fn f3(s: S<'_>) -> S<'_> { | ||
//~^ ERROR the placeholder `_` is not allowed | ||
return s; | ||
} | ||
|
||
fn f4(s: S<'_>) -> S<'_> { | ||
//~^ ERROR the placeholder `_` is not allowed | ||
let _x = 1; | ||
return s; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
tests/ui/return/infer-return-ty-for-fn-sig-issue-125488.rs
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,33 @@ | ||
//@ run-rustfix | ||
|
||
#[allow(dead_code)] | ||
|
||
fn main() { | ||
struct S<'a>(&'a ()); | ||
|
||
fn f1(s: S<'_>) -> _ { | ||
//~^ ERROR the placeholder `_` is not allowed | ||
s | ||
} | ||
|
||
fn f2(s: S<'_>) -> _ { | ||
//~^ ERROR the placeholder `_` is not allowed | ||
let x = true; | ||
if x { | ||
s | ||
} else { | ||
s | ||
} | ||
} | ||
|
||
fn f3(s: S<'_>) -> _ { | ||
//~^ ERROR the placeholder `_` is not allowed | ||
return s; | ||
} | ||
|
||
fn f4(s: S<'_>) -> _ { | ||
//~^ ERROR the placeholder `_` is not allowed | ||
let _x = 1; | ||
return s; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
tests/ui/return/infer-return-ty-for-fn-sig-issue-125488.stderr
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,39 @@ | ||
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types | ||
--> $DIR/infer-return-ty-for-fn-sig-issue-125488.rs:8:24 | ||
| | ||
LL | fn f1(s: S<'_>) -> _ { | ||
| ^ | ||
| | | ||
| not allowed in type signatures | ||
| help: replace with the correct return type: `S<'_>` | ||
|
||
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types | ||
--> $DIR/infer-return-ty-for-fn-sig-issue-125488.rs:13:24 | ||
| | ||
LL | fn f2(s: S<'_>) -> _ { | ||
| ^ | ||
| | | ||
| not allowed in type signatures | ||
| help: replace with the correct return type: `S<'_>` | ||
|
||
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types | ||
--> $DIR/infer-return-ty-for-fn-sig-issue-125488.rs:23:24 | ||
| | ||
LL | fn f3(s: S<'_>) -> _ { | ||
| ^ | ||
| | | ||
| not allowed in type signatures | ||
| help: replace with the correct return type: `S<'_>` | ||
|
||
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types | ||
--> $DIR/infer-return-ty-for-fn-sig-issue-125488.rs:28:24 | ||
| | ||
LL | fn f4(s: S<'_>) -> _ { | ||
| ^ | ||
| | | ||
| not allowed in type signatures | ||
| help: replace with the correct return type: `S<'_>` | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0121`. |