Skip to content

Commit 165efab

Browse files
committed
review comments
1 parent 7d1e47a commit 165efab

File tree

20 files changed

+96
-98
lines changed

20 files changed

+96
-98
lines changed

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

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ 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
3837
*[empty] {""}
3938
}
4039

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

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

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"
80+
fn where_x_is_kind(&self, in_type: Ty<'_>) -> &'static str {
81+
if in_type.is_ty_infer() {
82+
""
8583
} else if self.name == "_" {
8684
// FIXME: Consider specializing this message if there is a single `_`
8785
// in the type.
@@ -185,14 +183,20 @@ fn fmt_printer<'a, 'tcx>(infcx: &'a InferCtxt<'tcx>, ns: Namespace) -> FmtPrinte
185183
printer
186184
}
187185

188-
fn ty_to_string<'tcx>(infcx: &InferCtxt<'tcx>, ty: Ty<'tcx>) -> String {
186+
fn ty_to_string<'tcx>(infcx: &InferCtxt<'tcx>, ty: Ty<'tcx>, def_id: Option<DefId>) -> String {
189187
let printer = fmt_printer(infcx, Namespace::TypeNS);
190188
let ty = infcx.resolve_vars_if_possible(ty);
191-
match ty.kind() {
189+
match (ty.kind(), def_id) {
192190
// We don't want the regular output for `fn`s because it includes its path in
193191
// invalid pseudo-syntax, we want the `fn`-pointer output instead.
194-
ty::FnDef(..) => ty.fn_sig(infcx.tcx).print(printer).unwrap().into_buffer(),
195-
_ if ty.is_ty_infer() => "Type".to_string(),
192+
(ty::FnDef(..), _) => ty.fn_sig(infcx.tcx).print(printer).unwrap().into_buffer(),
193+
(_, Some(def_id))
194+
if ty.is_ty_infer()
195+
&& infcx.tcx.get_diagnostic_item(sym::iterator_collect_fn) == Some(def_id) =>
196+
{
197+
"Vec<_>".to_string()
198+
}
199+
_ if ty.is_ty_infer() => "/* Type */".to_string(),
196200
// FIXME: The same thing for closures, but this only works when the closure
197201
// does not capture anything.
198202
//
@@ -216,15 +220,15 @@ fn closure_as_fn_str<'tcx>(infcx: &InferCtxt<'tcx>, ty: Ty<'tcx>) -> String {
216220
.map(|args| {
217221
args.tuple_fields()
218222
.iter()
219-
.map(|arg| ty_to_string(infcx, arg))
223+
.map(|arg| ty_to_string(infcx, arg, None))
220224
.collect::<Vec<_>>()
221225
.join(", ")
222226
})
223227
.unwrap_or_default();
224228
let ret = if fn_sig.output().skip_binder().is_unit() {
225229
String::new()
226230
} else {
227-
format!(" -> {}", ty_to_string(infcx, fn_sig.output().skip_binder()))
231+
format!(" -> {}", ty_to_string(infcx, fn_sig.output().skip_binder(), None))
228232
};
229233
format!("fn({}){}", args, ret)
230234
}
@@ -410,32 +414,28 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
410414
let mut infer_subdiags = Vec::new();
411415
let mut multi_suggestions = Vec::new();
412416
match kind {
413-
InferSourceKind::LetBinding { insert_span, pattern_name, ty, is_collect } => {
417+
InferSourceKind::LetBinding { insert_span, pattern_name, ty, def_id } => {
414418
infer_subdiags.push(SourceKindSubdiag::LetLike {
415419
span: insert_span,
416420
name: pattern_name.map(|name| name.to_string()).unwrap_or_else(String::new),
417-
x_kind: arg_data.where_x_is_kind(ty, is_collect),
421+
x_kind: arg_data.where_x_is_kind(ty),
418422
prefix_kind: arg_data.kind.clone(),
419423
prefix: arg_data.kind.try_get_prefix().unwrap_or_default(),
420424
arg_name: arg_data.name,
421425
kind: if pattern_name.is_some() { "with_pattern" } else { "other" },
422-
type_name: if is_collect {
423-
"Vec<_>".to_string()
424-
} else {
425-
ty_to_string(self, ty)
426-
},
426+
type_name: ty_to_string(self, ty, def_id),
427427
});
428428
}
429429
InferSourceKind::ClosureArg { insert_span, ty } => {
430430
infer_subdiags.push(SourceKindSubdiag::LetLike {
431431
span: insert_span,
432432
name: String::new(),
433-
x_kind: arg_data.where_x_is_kind(ty, false),
433+
x_kind: arg_data.where_x_is_kind(ty),
434434
prefix_kind: arg_data.kind.clone(),
435435
prefix: arg_data.kind.try_get_prefix().unwrap_or_default(),
436436
arg_name: arg_data.name,
437437
kind: "closure",
438-
type_name: ty_to_string(self, ty),
438+
type_name: ty_to_string(self, ty, None),
439439
});
440440
}
441441
InferSourceKind::GenericArg {
@@ -534,7 +534,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
534534
));
535535
}
536536
InferSourceKind::ClosureReturn { ty, data, should_wrap_expr } => {
537-
let ty_info = ty_to_string(self, ty);
537+
let ty_info = ty_to_string(self, ty, None);
538538
multi_suggestions.push(SourceKindMultiSuggestion::new_closure_return(
539539
ty_info,
540540
data,
@@ -622,7 +622,7 @@ enum InferSourceKind<'tcx> {
622622
insert_span: Span,
623623
pattern_name: Option<Ident>,
624624
ty: Ty<'tcx>,
625-
is_collect: bool,
625+
def_id: Option<DefId>,
626626
},
627627
ClosureArg {
628628
insert_span: Span,
@@ -677,7 +677,7 @@ impl<'tcx> InferSourceKind<'tcx> {
677677
if ty.is_closure() {
678678
("closure", closure_as_fn_str(infcx, ty))
679679
} else if !ty.is_ty_infer() {
680-
("normal", ty_to_string(infcx, ty))
680+
("normal", ty_to_string(infcx, ty, None))
681681
} else {
682682
("other", String::new())
683683
}
@@ -807,14 +807,13 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
807807
let cost = self.source_cost(&new_source) + self.attempt;
808808
debug!(?cost);
809809
self.attempt += 1;
810-
if let Some(InferSource { kind: InferSourceKind::GenericArg { def_id, ..}, .. }) = self.infer_source
811-
&& self.infcx.tcx.get_diagnostic_item(sym::iterator_collect_fn) == Some(def_id)
812-
&& let InferSourceKind::LetBinding { ref ty, ref mut is_collect, ..} = new_source.kind
810+
if let Some(InferSource { kind: InferSourceKind::GenericArg { def_id: did, ..}, .. }) = self.infer_source
811+
&& let InferSourceKind::LetBinding { ref ty, ref mut def_id, ..} = new_source.kind
813812
&& ty.is_ty_infer()
814813
{
815814
// Customize the output so we talk about `let x: Vec<_> = iter.collect();` instead of
816815
// `let x: _ = iter.collect();`, as this is a very common case.
817-
*is_collect = true;
816+
*def_id = Some(did);
818817
}
819818
if cost < self.infer_source_cost {
820819
self.infer_source_cost = cost;
@@ -1113,7 +1112,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> {
11131112
insert_span: local.pat.span.shrink_to_hi(),
11141113
pattern_name: local.pat.simple_ident(),
11151114
ty,
1116-
is_collect: false,
1115+
def_id: None,
11171116
},
11181117
})
11191118
}

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 placeholder `Type` is specified
7+
help: consider giving this pattern a type
88
|
9-
LL | let [_, _]: Type = 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, where the placeholder `Type` is specified
7+
help: consider giving this closure parameter an explicit type
88
|
9-
LL | with_closure(|x: u32, y: Type| {});
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 placeholder `Type` is specified
13+
help: consider giving this closure parameter an explicit type
1414
|
15-
LL | [(); &(&'static: loop { |x: Type| {}; }) 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, where the placeholder `Type` is specified
7+
help: consider giving this pattern a type
88
|
9-
LL | let _: Type = 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 placeholder `Type` is specified
21+
help: consider giving this closure parameter an explicit type
2222
|
23-
LL | |_: Type| 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 placeholder `Type` is specified
33+
help: consider giving this closure parameter an explicit type
3434
|
35-
LL | |x: Type| 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 placeholder `Type` is specified
7+
help: consider giving `x` an explicit type
88
|
9-
LL | let x: Type;
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 placeholder `Type` is specified
9+
help: consider giving `x` an explicit type
1010
|
11-
LL | let x: Type = 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 placeholder `Type` is specified
20+
help: consider giving this closure parameter an explicit type
2121
|
22-
LL | 1 => |c: Type| 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 placeholder `Type` is specified
7+
help: consider giving this closure parameter an explicit type
88
|
9-
LL | |s: Type| 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 placeholder `Type` is specified
18+
help: consider giving this closure parameter an explicit type
1919
|
20-
LL | |s: Type| 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 placeholder `Type` is specified
29+
help: consider giving this closure parameter an explicit type
3030
|
31-
LL | |s: Type| 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 placeholder `Type` is specified
40+
help: consider giving this closure parameter an explicit type
4141
|
42-
LL | |s: Type| 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 placeholder `Type` is specified
7+
help: consider giving `x` an explicit type
88
|
9-
LL | let x: Type = 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 placeholder `Type` is specified
10+
help: consider giving `x` an explicit type
1111
|
12-
LL | let x: Type;
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 placeholder `Type` is specified
194+
help: consider giving this pattern a type
195195
|
196-
LL | let x @ ..: Type;
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 placeholder `Type` is specified
22+
help: consider giving `N` an explicit type
2323
|
24-
LL | let mut N: Type;
25-
| ++++++
24+
LL | let mut N: /* Type */;
25+
| ++++++++++++
2626

2727
error: aborting due to 3 previous errors
2828

0 commit comments

Comments
 (0)