-
Notifications
You must be signed in to change notification settings - Fork 13k
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 #127110 - surechen:fix_125488_06, r=compiler-errors
Fix a error suggestion for E0121 when using placeholder _ as return types on function signature. Recommit after refactoring based on comment: #126017 (comment) But when changing return type's lifetime to `ReError` will affect the subsequent borrow check process and cause test11 in typeck_type_placeholder_item.rs to lost E0515 message. ```rust fn test11(x: &usize) -> &_ { //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types &x //~ ERROR cannot return reference to function parameter(this E0515 msg will disappear) } ``` fixes #125488 r? ``@pnkfelix``
- Loading branch information
Showing
6 changed files
with
127 additions
and
11 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`. |
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