Skip to content

Commit 7d1e47a

Browse files
committed
Suggest : Type instead of : _
1 parent 3e25bcb commit 7d1e47a

File tree

20 files changed

+79
-75
lines changed

20 files changed

+79
-75
lines changed

compiler/rustc_error_messages/locales/en-US/infer.ftl

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ infer_source_kind_subdiag_let = {$kind ->
3434
[const] the value of the constant
3535
} `{$arg_name}` is specified
3636
[underscore] , where the placeholders `_` are specified
37+
[anon] , where the placeholder `Type` is specified
3738
*[empty] {""}
3839
}
3940

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,15 @@ impl InferenceDiagnosticsData {
7777
!(self.name == "_" && matches!(self.kind, UnderspecifiedArgKind::Type { .. }))
7878
}
7979

80-
fn where_x_is_kind(&self, in_type: Ty<'_>) -> &'static str {
81-
if self.name == "_" {
80+
fn where_x_is_kind(&self, in_type: Ty<'_>, is_collect: bool) -> &'static str {
81+
if is_collect {
82+
"empty"
83+
} else if in_type.is_ty_infer() {
84+
"anon"
85+
} else if self.name == "_" {
8286
// FIXME: Consider specializing this message if there is a single `_`
8387
// in the type.
8488
"underscore"
85-
} else if in_type.is_ty_infer() {
86-
"empty"
8789
} else {
8890
"has_name"
8991
}
@@ -190,6 +192,7 @@ fn ty_to_string<'tcx>(infcx: &InferCtxt<'tcx>, ty: Ty<'tcx>) -> String {
190192
// We don't want the regular output for `fn`s because it includes its path in
191193
// invalid pseudo-syntax, we want the `fn`-pointer output instead.
192194
ty::FnDef(..) => ty.fn_sig(infcx.tcx).print(printer).unwrap().into_buffer(),
195+
_ if ty.is_ty_infer() => "Type".to_string(),
193196
// FIXME: The same thing for closures, but this only works when the closure
194197
// does not capture anything.
195198
//
@@ -411,7 +414,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
411414
infer_subdiags.push(SourceKindSubdiag::LetLike {
412415
span: insert_span,
413416
name: pattern_name.map(|name| name.to_string()).unwrap_or_else(String::new),
414-
x_kind: if is_collect { "empty" } else { arg_data.where_x_is_kind(ty) },
417+
x_kind: arg_data.where_x_is_kind(ty, is_collect),
415418
prefix_kind: arg_data.kind.clone(),
416419
prefix: arg_data.kind.try_get_prefix().unwrap_or_default(),
417420
arg_name: arg_data.name,
@@ -427,7 +430,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
427430
infer_subdiags.push(SourceKindSubdiag::LetLike {
428431
span: insert_span,
429432
name: String::new(),
430-
x_kind: arg_data.where_x_is_kind(ty),
433+
x_kind: arg_data.where_x_is_kind(ty, false),
431434
prefix_kind: arg_data.kind.clone(),
432435
prefix: arg_data.kind.try_get_prefix().unwrap_or_default(),
433436
arg_name: arg_data.name,

src/test/ui/array-slice-vec/infer_array_len.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ error[E0282]: type annotations needed
44
LL | let [_, _] = a.into();
55
| ^^^^^^
66
|
7-
help: consider giving this pattern a type, where the placeholders `_` are specified
7+
help: consider giving this pattern a type, where the placeholder `Type` is specified
88
|
9-
LL | let [_, _]: _ = a.into();
10-
| +++
9+
LL | let [_, _]: Type = a.into();
10+
| ++++++
1111

1212
error: aborting due to previous error
1313

src/test/ui/closure-expected-type/expect-two-infer-vars-supply-ty-with-bound-region.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ error[E0282]: type annotations needed
44
LL | with_closure(|x: u32, y| {});
55
| ^
66
|
7-
help: consider giving this closure parameter an explicit type
7+
help: consider giving this closure parameter an explicit type, where the placeholder `Type` is specified
88
|
9-
LL | with_closure(|x: u32, y: _| {});
10-
| +++
9+
LL | with_closure(|x: u32, y: Type| {});
10+
| ++++++
1111

1212
error: aborting due to previous error
1313

src/test/ui/closures/issue-52437.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ error[E0282]: type annotations needed
1010
LL | [(); &(&'static: loop { |x| {}; }) as *const _ as usize]
1111
| ^
1212
|
13-
help: consider giving this closure parameter an explicit type, where the placeholders `_` are specified
13+
help: consider giving this closure parameter an explicit type, where the placeholder `Type` is specified
1414
|
15-
LL | [(); &(&'static: loop { |x: _| {}; }) as *const _ as usize]
16-
| +++
15+
LL | [(); &(&'static: loop { |x: Type| {}; }) as *const _ as usize]
16+
| ++++++
1717

1818
error: aborting due to 2 previous errors
1919

src/test/ui/const-generics/issues/issue-83249.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ error[E0282]: type annotations needed
44
LL | let _ = foo([0; 1]);
55
| ^
66
|
7-
help: consider giving this pattern a type
7+
help: consider giving this pattern a type, where the placeholder `Type` is specified
88
|
9-
LL | let _: _ = foo([0; 1]);
10-
| +++
9+
LL | let _: Type = foo([0; 1]);
10+
| ++++++
1111

1212
error: aborting due to previous error
1313

src/test/ui/impl-trait/issues/issue-86719.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ error[E0282]: type annotations needed
1818
LL | |_| true
1919
| ^
2020
|
21-
help: consider giving this closure parameter an explicit type, where the placeholders `_` are specified
21+
help: consider giving this closure parameter an explicit type, where the placeholder `Type` is specified
2222
|
23-
LL | |_: _| true
24-
| +++
23+
LL | |_: Type| true
24+
| ++++++
2525

2626
error: aborting due to 3 previous errors
2727

src/test/ui/inference/issue-72690.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ error[E0282]: type annotations needed
3030
LL | |x| String::from("x".as_ref());
3131
| ^
3232
|
33-
help: consider giving this closure parameter an explicit type, where the placeholders `_` are specified
33+
help: consider giving this closure parameter an explicit type, where the placeholder `Type` is specified
3434
|
35-
LL | |x: _| String::from("x".as_ref());
36-
| +++
35+
LL | |x: Type| String::from("x".as_ref());
36+
| ++++++
3737

3838
error[E0283]: type annotations needed
3939
--> $DIR/issue-72690.rs:12:26

src/test/ui/issues/issue-18159.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ error[E0282]: type annotations needed
44
LL | let x;
55
| ^
66
|
7-
help: consider giving `x` an explicit type, where the placeholders `_` are specified
7+
help: consider giving `x` an explicit type, where the placeholder `Type` is specified
88
|
9-
LL | let x: _;
10-
| +++
9+
LL | let x: Type;
10+
| ++++++
1111

1212
error: aborting due to previous error
1313

src/test/ui/issues/issue-2151.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ LL | let x = panic!();
66
LL | x.clone();
77
| - type must be known at this point
88
|
9-
help: consider giving `x` an explicit type, where the placeholders `_` are specified
9+
help: consider giving `x` an explicit type, where the placeholder `Type` is specified
1010
|
11-
LL | let x: _ = panic!();
12-
| +++
11+
LL | let x: Type = panic!();
12+
| ++++++
1313

1414
error: aborting due to previous error
1515

src/test/ui/issues/issue-24036.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ error[E0282]: type annotations needed
1717
LL | 1 => |c| c + 1,
1818
| ^
1919
|
20-
help: consider giving this closure parameter an explicit type, where the placeholders `_` are specified
20+
help: consider giving this closure parameter an explicit type, where the placeholder `Type` is specified
2121
|
22-
LL | 1 => |c: _| c + 1,
23-
| +++
22+
LL | 1 => |c: Type| c + 1,
23+
| ++++++
2424

2525
error: aborting due to 2 previous errors
2626

src/test/ui/lazy-type-alias-impl-trait/branches3.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,43 @@ error[E0282]: type annotations needed
44
LL | |s| s.len()
55
| ^ - type must be known at this point
66
|
7-
help: consider giving this closure parameter an explicit type, where the placeholders `_` are specified
7+
help: consider giving this closure parameter an explicit type, where the placeholder `Type` is specified
88
|
9-
LL | |s: _| s.len()
10-
| +++
9+
LL | |s: Type| s.len()
10+
| ++++++
1111

1212
error[E0282]: type annotations needed
1313
--> $DIR/branches3.rs:15:10
1414
|
1515
LL | |s| s.len()
1616
| ^ - type must be known at this point
1717
|
18-
help: consider giving this closure parameter an explicit type, where the placeholders `_` are specified
18+
help: consider giving this closure parameter an explicit type, where the placeholder `Type` is specified
1919
|
20-
LL | |s: _| s.len()
21-
| +++
20+
LL | |s: Type| s.len()
21+
| ++++++
2222

2323
error[E0282]: type annotations needed
2424
--> $DIR/branches3.rs:23:10
2525
|
2626
LL | |s| s.len()
2727
| ^ - type must be known at this point
2828
|
29-
help: consider giving this closure parameter an explicit type, where the placeholders `_` are specified
29+
help: consider giving this closure parameter an explicit type, where the placeholder `Type` is specified
3030
|
31-
LL | |s: _| s.len()
32-
| +++
31+
LL | |s: Type| s.len()
32+
| ++++++
3333

3434
error[E0282]: type annotations needed
3535
--> $DIR/branches3.rs:30:10
3636
|
3737
LL | |s| s.len()
3838
| ^ - type must be known at this point
3939
|
40-
help: consider giving this closure parameter an explicit type, where the placeholders `_` are specified
40+
help: consider giving this closure parameter an explicit type, where the placeholder `Type` is specified
4141
|
42-
LL | |s: _| s.len()
43-
| +++
42+
LL | |s: Type| s.len()
43+
| ++++++
4444

4545
error: aborting due to 4 previous errors
4646

src/test/ui/match/match-unresolved-one-arm.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ error[E0282]: type annotations needed
44
LL | let x = match () {
55
| ^
66
|
7-
help: consider giving `x` an explicit type, where the placeholders `_` are specified
7+
help: consider giving `x` an explicit type, where the placeholder `Type` is specified
88
|
9-
LL | let x: _ = match () {
10-
| +++
9+
LL | let x: Type = match () {
10+
| ++++++
1111

1212
error: aborting due to previous error
1313

src/test/ui/pattern/pat-tuple-bad-type.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ LL | let x;
77
LL | (..) => {}
88
| ---- type must be known at this point
99
|
10-
help: consider giving `x` an explicit type, where the placeholders `_` are specified
10+
help: consider giving `x` an explicit type, where the placeholder `Type` is specified
1111
|
12-
LL | let x: _;
13-
| +++
12+
LL | let x: Type;
13+
| ++++++
1414

1515
error[E0308]: mismatched types
1616
--> $DIR/pat-tuple-bad-type.rs:10:9

src/test/ui/pattern/rest-pat-semantic-disallowed.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,10 @@ error[E0282]: type annotations needed
191191
LL | let x @ ..;
192192
| ^^^^^^
193193
|
194-
help: consider giving this pattern a type, where the placeholders `_` are specified
194+
help: consider giving this pattern a type, where the placeholder `Type` is specified
195195
|
196-
LL | let x @ ..: _;
197-
| +++
196+
LL | let x @ ..: Type;
197+
| ++++++
198198

199199
error: aborting due to 23 previous errors
200200

src/test/ui/resolve/issue-85348.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ error[E0282]: type annotations needed
1919
LL | let mut N;
2020
| ^^^^^
2121
|
22-
help: consider giving `N` an explicit type, where the placeholders `_` are specified
22+
help: consider giving `N` an explicit type, where the placeholder `Type` is specified
2323
|
24-
LL | let mut N: _;
25-
| +++
24+
LL | let mut N: Type;
25+
| ++++++
2626

2727
error: aborting due to 3 previous errors
2828

src/test/ui/span/method-and-field-eager-resolution.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ LL |
77
LL | x.0;
88
| - type must be known at this point
99
|
10-
help: consider giving `x` an explicit type, where the placeholders `_` are specified
10+
help: consider giving `x` an explicit type, where the placeholder `Type` is specified
1111
|
12-
LL | let mut x: _ = Default::default();
13-
| +++
12+
LL | let mut x: Type = Default::default();
13+
| ++++++
1414

1515
error[E0282]: type annotations needed
1616
--> $DIR/method-and-field-eager-resolution.rs:11:9
@@ -21,10 +21,10 @@ LL |
2121
LL | x[0];
2222
| - type must be known at this point
2323
|
24-
help: consider giving `x` an explicit type, where the placeholders `_` are specified
24+
help: consider giving `x` an explicit type, where the placeholder `Type` is specified
2525
|
26-
LL | let mut x: _ = Default::default();
27-
| +++
26+
LL | let mut x: Type = Default::default();
27+
| ++++++
2828

2929
error: aborting due to 2 previous errors
3030

src/test/ui/type-alias-impl-trait/closures_in_branches.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ error[E0282]: type annotations needed
44
LL | |x| x.len()
55
| ^ - type must be known at this point
66
|
7-
help: consider giving this closure parameter an explicit type, where the placeholders `_` are specified
7+
help: consider giving this closure parameter an explicit type, where the placeholder `Type` is specified
88
|
9-
LL | |x: _| x.len()
10-
| +++
9+
LL | |x: Type| x.len()
10+
| ++++++
1111

1212
error[E0282]: type annotations needed
1313
--> $DIR/closures_in_branches.rs:21:10
1414
|
1515
LL | |x| x.len()
1616
| ^ - type must be known at this point
1717
|
18-
help: consider giving this closure parameter an explicit type, where the placeholders `_` are specified
18+
help: consider giving this closure parameter an explicit type, where the placeholder `Type` is specified
1919
|
20-
LL | |x: _| x.len()
21-
| +++
20+
LL | |x: Type| x.len()
21+
| ++++++
2222

2323
error: aborting due to 2 previous errors
2424

src/test/ui/type/type-check/unknown_type_for_closure.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ error[E0282]: type annotations needed
1010
LL | let x = |_| {};
1111
| ^
1212
|
13-
help: consider giving this closure parameter an explicit type, where the placeholders `_` are specified
13+
help: consider giving this closure parameter an explicit type, where the placeholder `Type` is specified
1414
|
15-
LL | let x = |_: _| {};
16-
| +++
15+
LL | let x = |_: Type| {};
16+
| ++++++
1717

1818
error[E0282]: type annotations needed
1919
--> $DIR/unknown_type_for_closure.rs:10:14

src/test/ui/type/type-path-err-node-types.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ error[E0282]: type annotations needed
2828
LL | let _ = |a, b: _| -> _ { 0 };
2929
| ^
3030
|
31-
help: consider giving this closure parameter an explicit type, where the placeholders `_` are specified
31+
help: consider giving this closure parameter an explicit type, where the placeholder `Type` is specified
3232
|
33-
LL | let _ = |a: _, b: _| -> _ { 0 };
34-
| +++
33+
LL | let _ = |a: Type, b: _| -> _ { 0 };
34+
| ++++++
3535

3636
error: aborting due to 5 previous errors
3737

0 commit comments

Comments
 (0)