Skip to content

Commit a2db928

Browse files
committed
Auto merge of rust-lang#147143 - estebank:verbose-ret-type, r=fee1-dead
Make replacement suggestion `_` in type verbose ``` error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types --> $DIR/in-signature.rs:6:21 | LL | fn arr_fn() -> [u8; _] { | ^ not allowed in type signatures | help: replace with the correct return type | LL - fn arr_fn() -> [u8; _] { LL + fn arr_fn() -> [u8; 3] { | ```
2 parents c5dc558 + eceb485 commit a2db928

16 files changed

+258
-150
lines changed

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,7 @@ fn recover_infer_ret_ty<'tcx>(
11401140
// recursive function definition to leak out into the fn sig.
11411141
let mut recovered_ret_ty = None;
11421142
if let Some(suggestable_ret_ty) = ret_ty.make_suggestable(tcx, false, None) {
1143-
diag.span_suggestion(
1143+
diag.span_suggestion_verbose(
11441144
infer_ret_ty.span,
11451145
"replace with the correct return type",
11461146
suggestable_ret_ty,
@@ -1152,7 +1152,7 @@ fn recover_infer_ret_ty<'tcx>(
11521152
tcx.param_env(def_id),
11531153
ret_ty,
11541154
) {
1155-
diag.span_suggestion(
1155+
diag.span_suggestion_verbose(
11561156
infer_ret_ty.span,
11571157
"replace with an appropriate return type",
11581158
sugg,

tests/ui/const-generics/generic_arg_infer/in-signature.stderr

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,39 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
22
--> $DIR/in-signature.rs:6:21
33
|
44
LL | fn arr_fn() -> [u8; _] {
5-
| -----^-
6-
| | |
7-
| | not allowed in type signatures
8-
| help: replace with the correct return type: `[u8; 3]`
5+
| ^ not allowed in type signatures
6+
|
7+
help: replace with the correct return type
8+
|
9+
LL - fn arr_fn() -> [u8; _] {
10+
LL + fn arr_fn() -> [u8; 3] {
11+
|
912

1013
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
1114
--> $DIR/in-signature.rs:11:24
1215
|
1316
LL | fn ty_fn() -> Bar<i32, _> {
14-
| ---------^-
15-
| | |
16-
| | not allowed in type signatures
17-
| help: replace with the correct return type: `Bar<i32, 3>`
17+
| ^ not allowed in type signatures
18+
|
19+
help: replace with the correct return type
20+
|
21+
LL - fn ty_fn() -> Bar<i32, _> {
22+
LL + fn ty_fn() -> Bar<i32, 3> {
23+
|
1824

1925
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
2026
--> $DIR/in-signature.rs:16:25
2127
|
2228
LL | fn ty_fn_mixed() -> Bar<_, _> {
23-
| ----^--^-
24-
| | | |
25-
| | | not allowed in type signatures
26-
| | not allowed in type signatures
27-
| help: replace with the correct return type: `Bar<i32, 3>`
29+
| ^ ^ not allowed in type signatures
30+
| |
31+
| not allowed in type signatures
32+
|
33+
help: replace with the correct return type
34+
|
35+
LL - fn ty_fn_mixed() -> Bar<_, _> {
36+
LL + fn ty_fn_mixed() -> Bar<i32, 3> {
37+
|
2838

2939
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
3040
--> $DIR/in-signature.rs:21:20

tests/ui/error-codes/E0121.stderr

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
22
--> $DIR/E0121.rs:1:13
33
|
44
LL | fn foo() -> _ { 5 }
5-
| ^
6-
| |
7-
| not allowed in type signatures
8-
| help: replace with the correct return type: `i32`
5+
| ^ not allowed in type signatures
6+
|
7+
help: replace with the correct return type
8+
|
9+
LL - fn foo() -> _ { 5 }
10+
LL + fn foo() -> i32 { 5 }
11+
|
912

1013
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
1114
--> $DIR/E0121.rs:3:13

tests/ui/fn/issue-80179.stderr

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,26 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
22
--> $DIR/issue-80179.rs:10:24
33
|
44
LL | fn returns_fn_ptr() -> _ {
5-
| ^
6-
| |
7-
| not allowed in type signatures
8-
| help: replace with the correct return type: `fn() -> i32`
5+
| ^ not allowed in type signatures
6+
|
7+
help: replace with the correct return type
8+
|
9+
LL - fn returns_fn_ptr() -> _ {
10+
LL + fn returns_fn_ptr() -> fn() -> i32 {
11+
|
912

1013
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
1114
--> $DIR/issue-80179.rs:18:25
1215
|
1316
LL | fn returns_closure() -> _ {
14-
| ^
15-
| |
16-
| not allowed in type signatures
17-
| help: replace with an appropriate return type: `impl Fn() -> i32`
17+
| ^ not allowed in type signatures
1818
|
1919
= note: for more information on `Fn` traits and closure types, see https://doc.rust-lang.org/book/ch13-01-closures.html
20+
help: replace with an appropriate return type
21+
|
22+
LL - fn returns_closure() -> _ {
23+
LL + fn returns_closure() -> impl Fn() -> i32 {
24+
|
2025

2126
error: aborting due to 2 previous errors
2227

tests/ui/fn/suggest-return-closure.stderr

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,40 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
22
--> $DIR/suggest-return-closure.rs:1:17
33
|
44
LL | fn fn_once() -> _ {
5-
| ^
6-
| |
7-
| not allowed in type signatures
8-
| help: replace with an appropriate return type: `impl FnOnce()`
5+
| ^ not allowed in type signatures
96
|
107
= note: for more information on `Fn` traits and closure types, see https://doc.rust-lang.org/book/ch13-01-closures.html
8+
help: replace with an appropriate return type
9+
|
10+
LL - fn fn_once() -> _ {
11+
LL + fn fn_once() -> impl FnOnce() {
12+
|
1113

1214
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
1315
--> $DIR/suggest-return-closure.rs:13:16
1416
|
1517
LL | fn fn_mut() -> _ {
16-
| ^
17-
| |
18-
| not allowed in type signatures
19-
| help: replace with an appropriate return type: `impl FnMut(char)`
18+
| ^ not allowed in type signatures
2019
|
2120
= note: for more information on `Fn` traits and closure types, see https://doc.rust-lang.org/book/ch13-01-closures.html
21+
help: replace with an appropriate return type
22+
|
23+
LL - fn fn_mut() -> _ {
24+
LL + fn fn_mut() -> impl FnMut(char) {
25+
|
2226

2327
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
2428
--> $DIR/suggest-return-closure.rs:33:13
2529
|
2630
LL | fn fun() -> _ {
27-
| ^
28-
| |
29-
| not allowed in type signatures
30-
| help: replace with an appropriate return type: `impl Fn() -> i32`
31+
| ^ not allowed in type signatures
3132
|
3233
= note: for more information on `Fn` traits and closure types, see https://doc.rust-lang.org/book/ch13-01-closures.html
34+
help: replace with an appropriate return type
35+
|
36+
LL - fn fun() -> _ {
37+
LL + fn fun() -> impl Fn() -> i32 {
38+
|
3339

3440
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
3541
--> $DIR/suggest-return-closure.rs:24:9

tests/ui/fn/suggest-return-future.stderr

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,25 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
22
--> $DIR/suggest-return-future.rs:7:13
33
|
44
LL | fn foo() -> _ {
5-
| ^
6-
| |
7-
| not allowed in type signatures
8-
| help: replace with an appropriate return type: `impl Future<Output = i32>`
5+
| ^ not allowed in type signatures
6+
|
7+
help: replace with an appropriate return type
8+
|
9+
LL - fn foo() -> _ {
10+
LL + fn foo() -> impl Future<Output = i32> {
11+
|
912

1013
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
1114
--> $DIR/suggest-return-future.rs:15:13
1215
|
1316
LL | fn bar() -> _ {
14-
| ^
15-
| |
16-
| not allowed in type signatures
17-
| help: replace with an appropriate return type: `impl Future<Output = i32>`
17+
| ^ not allowed in type signatures
18+
|
19+
help: replace with an appropriate return type
20+
|
21+
LL - fn bar() -> _ {
22+
LL + fn bar() -> impl Future<Output = i32> {
23+
|
1824

1925
error: aborting due to 2 previous errors
2026

tests/ui/return/infer-return-ty-for-fn-sig-issue-125488.stderr

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,49 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
22
--> $DIR/infer-return-ty-for-fn-sig-issue-125488.rs:8:24
33
|
44
LL | fn f1(s: S<'_>) -> _ {
5-
| ^
6-
| |
7-
| not allowed in type signatures
8-
| help: replace with the correct return type: `S<'_>`
5+
| ^ not allowed in type signatures
6+
|
7+
help: replace with the correct return type
8+
|
9+
LL - fn f1(s: S<'_>) -> _ {
10+
LL + fn f1(s: S<'_>) -> S<'_> {
11+
|
912

1013
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
1114
--> $DIR/infer-return-ty-for-fn-sig-issue-125488.rs:13:24
1215
|
1316
LL | fn f2(s: S<'_>) -> _ {
14-
| ^
15-
| |
16-
| not allowed in type signatures
17-
| help: replace with the correct return type: `S<'_>`
17+
| ^ not allowed in type signatures
18+
|
19+
help: replace with the correct return type
20+
|
21+
LL - fn f2(s: S<'_>) -> _ {
22+
LL + fn f2(s: S<'_>) -> S<'_> {
23+
|
1824

1925
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
2026
--> $DIR/infer-return-ty-for-fn-sig-issue-125488.rs:23:24
2127
|
2228
LL | fn f3(s: S<'_>) -> _ {
23-
| ^
24-
| |
25-
| not allowed in type signatures
26-
| help: replace with the correct return type: `S<'_>`
29+
| ^ not allowed in type signatures
30+
|
31+
help: replace with the correct return type
32+
|
33+
LL - fn f3(s: S<'_>) -> _ {
34+
LL + fn f3(s: S<'_>) -> S<'_> {
35+
|
2736

2837
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
2938
--> $DIR/infer-return-ty-for-fn-sig-issue-125488.rs:28:24
3039
|
3140
LL | fn f4(s: S<'_>) -> _ {
32-
| ^
33-
| |
34-
| not allowed in type signatures
35-
| help: replace with the correct return type: `S<'_>`
41+
| ^ not allowed in type signatures
42+
|
43+
help: replace with the correct return type
44+
|
45+
LL - fn f4(s: S<'_>) -> _ {
46+
LL + fn f4(s: S<'_>) -> S<'_> {
47+
|
3648

3749
error: aborting due to 4 previous errors
3850

tests/ui/suggestions/return-cycle-2.stderr

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
22
--> $DIR/return-cycle-2.rs:6:34
33
|
44
LL | fn as_ref(_: i32, _: i32) -> _ {
5-
| ^
6-
| |
7-
| not allowed in type signatures
8-
| help: replace with the correct return type: `Token<&'static T>`
5+
| ^ not allowed in type signatures
6+
|
7+
help: replace with the correct return type
8+
|
9+
LL - fn as_ref(_: i32, _: i32) -> _ {
10+
LL + fn as_ref(_: i32, _: i32) -> Token<&'static T> {
11+
|
912

1013
error: aborting due to 1 previous error
1114

tests/ui/suggestions/return-cycle.stderr

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
22
--> $DIR/return-cycle.rs:6:17
33
|
44
LL | fn new() -> _ {
5-
| ^
6-
| |
7-
| not allowed in type signatures
8-
| help: replace with the correct return type: `Token<()>`
5+
| ^ not allowed in type signatures
6+
|
7+
help: replace with the correct return type
8+
|
9+
LL - fn new() -> _ {
10+
LL + fn new() -> Token<()> {
11+
|
912

1013
error: aborting due to 1 previous error
1114

tests/ui/suggestions/suggest-fn-ptr-for-fn-item-in-fn-ret.stderr

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
22
--> $DIR/suggest-fn-ptr-for-fn-item-in-fn-ret.rs:7:13
33
|
44
LL | fn bar() -> _ { Wrapper(foo) }
5-
| ^
6-
| |
7-
| not allowed in type signatures
8-
| help: replace with the correct return type: `Wrapper<fn()>`
5+
| ^ not allowed in type signatures
6+
|
7+
help: replace with the correct return type
8+
|
9+
LL - fn bar() -> _ { Wrapper(foo) }
10+
LL + fn bar() -> Wrapper<fn()> { Wrapper(foo) }
11+
|
912

1013
error: aborting due to 1 previous error
1114

0 commit comments

Comments
 (0)