Skip to content

Commit a158bbc

Browse files
committed
Replace _ with /* Type */ in let binding type suggestion
1 parent 1c57b0f commit a158bbc

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

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

+10-3
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
749749
let ty = header.trait_ref.skip_binder().args.type_at(1);
750750
if ty == self_ty {
751751
if target_type {
752-
paths.push(format!("{target}"));
752+
let mut ty_str = format!("{target}");
753+
if &ty_str == "_" {
754+
ty_str = "/* Type */".to_string();
755+
}
756+
paths.push(ty_str);
753757
} else {
754758
paths.push(format!("<{self_ty} as Into<{target}>>::into"));
755759
}
@@ -777,8 +781,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
777781
let identity_method = args.rebase_onto(tcx, def_id, trait_assoc_substs);
778782
if target_type {
779783
let fn_sig = tcx.fn_sig(def_id).instantiate(tcx, identity_method);
780-
let ret = fn_sig.skip_binder().output();
781-
paths.push(format!("{ret}"));
784+
let mut ret = format!("{}", fn_sig.skip_binder().output());
785+
if &ret == "_" {
786+
ret = "/* Type */".to_string();
787+
}
788+
paths.push(ret);
782789
} else {
783790
paths.push(self.tcx.value_path_str_with_args(def_id, identity_method));
784791
}

tests/ui/pattern/slice-pattern-refutable.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ LL | let [a, b, c] = Zeroes.into() else {
66
|
77
help: consider giving this pattern a type
88
|
9-
LL | let [a, b, c]: _ = Zeroes.into() else {
10-
| +++
9+
LL | let [a, b, c]: /* Type */ = Zeroes.into() else {
10+
| ++++++++++++
1111
help: consider giving this pattern a type
1212
|
1313
LL | let [a, b, c]: [usize; 3] = Zeroes.into() else {

0 commit comments

Comments
 (0)