Skip to content

Commit 492bbf0

Browse files
committed
Never say "Trait is implemented for {type error}
1 parent ebbd167 commit 492bbf0

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,20 +1908,25 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
19081908
ct_op: |ct| ct.normalize(self.tcx, ty::ParamEnv::empty()),
19091909
},
19101910
);
1911-
err.highlighted_help(vec![
1912-
StringPart::normal(format!("the trait `{}` ", cand.print_trait_sugared())),
1913-
StringPart::highlighted("is"),
1914-
StringPart::normal(" implemented for `"),
1915-
StringPart::highlighted(cand.self_ty().to_string()),
1916-
StringPart::normal("`"),
1917-
]);
1918-
1919-
if let [TypeError::Sorts(exp_found)] = &terrs[..] {
1920-
let exp_found = self.resolve_vars_if_possible(*exp_found);
1921-
err.help(format!(
1922-
"for that trait implementation, expected `{}`, found `{}`",
1923-
exp_found.expected, exp_found.found
1924-
));
1911+
if !cand.references_error() {
1912+
err.highlighted_help(vec![
1913+
StringPart::normal(format!(
1914+
"the trait `{}` ",
1915+
cand.print_trait_sugared()
1916+
)),
1917+
StringPart::highlighted("is"),
1918+
StringPart::normal(" implemented for `"),
1919+
StringPart::highlighted(cand.self_ty().to_string()),
1920+
StringPart::normal("`"),
1921+
]);
1922+
1923+
if let [TypeError::Sorts(exp_found)] = &terrs[..] {
1924+
let exp_found = self.resolve_vars_if_possible(*exp_found);
1925+
err.help(format!(
1926+
"for that trait implementation, expected `{}`, found `{}`",
1927+
exp_found.expected, exp_found.found
1928+
));
1929+
}
19251930
}
19261931

19271932
true
@@ -1932,7 +1937,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
19321937
}
19331938

19341939
let other = if other { "other " } else { "" };
1935-
let report = |candidates: Vec<TraitRef<'tcx>>, err: &mut Diag<'_>| {
1940+
let report = |mut candidates: Vec<TraitRef<'tcx>>, err: &mut Diag<'_>| {
1941+
candidates.retain(|tr| !tr.references_error());
19361942
if candidates.is_empty() {
19371943
return false;
19381944
}

tests/ui/associated-consts/issue-105330.stderr

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ error[E0277]: the trait `TraitWAssocConst` is not implemented for `Demo`
5555
LL | foo::<Demo>()();
5656
| ^^^^ the trait `TraitWAssocConst` is not implemented for `Demo`
5757
|
58-
= help: the trait `TraitWAssocConst` is implemented for `{type error}`
5958
note: required by a bound in `foo`
6059
--> $DIR/issue-105330.rs:11:11
6160
|
@@ -92,7 +91,6 @@ error[E0277]: the trait `TraitWAssocConst` is not implemented for `Demo`
9291
LL | foo::<Demo>();
9392
| ^^^^ the trait `TraitWAssocConst` is not implemented for `Demo`
9493
|
95-
= help: the trait `TraitWAssocConst` is implemented for `{type error}`
9694
note: required by a bound in `foo`
9795
--> $DIR/issue-105330.rs:11:11
9896
|

0 commit comments

Comments
 (0)