Skip to content

Commit ad5c16d

Browse files
committed
Never say "Trait is implemented for {type error}
1 parent 862d95b commit ad5c16d

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,8 +1908,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
19081908
ct_op: |ct| ct.normalize(self.tcx, ty::ParamEnv::empty()),
19091909
},
19101910
);
1911+
if !cand.references_error() {
19111912
err.highlighted_help(vec![
1912-
StringPart::normal(format!("the trait `{}` ", cand.print_trait_sugared())),
1913+
StringPart::normal(format!(
1914+
"the trait `{}` ",
1915+
cand.print_trait_sugared()
1916+
)),
19131917
StringPart::highlighted("is"),
19141918
StringPart::normal(" implemented for `"),
19151919
StringPart::highlighted(cand.self_ty().to_string()),
@@ -1922,6 +1926,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
19221926
"for that trait implementation, expected `{}`, found `{}`",
19231927
exp_found.expected, exp_found.found
19241928
));
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 DiagnosticBuilder<'_>| {
1940+
let report = |mut candidates: Vec<TraitRef<'tcx>>, err: &mut DiagnosticBuilder<'_>| {
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)