Skip to content

Commit dab3d5b

Browse files
committed
Never say "Trait is implemented for {type error}"
When a trait bound error occurs, we look for alternative types that would have made the bound succeed. For some reason `{type error}` sometimes would appear as a type that would do so. We now remove `{type error}` from the list in every case to avoid nonsensical `note`s.
1 parent c475e23 commit dab3d5b

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -1908,6 +1908,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
19081908
ct_op: |ct| ct.normalize(self.tcx, ty::ParamEnv::empty()),
19091909
},
19101910
);
1911+
if cand.references_error() {
1912+
return false;
1913+
}
19111914
err.highlighted_help(vec![
19121915
StringPart::normal(format!("the trait `{}` ", cand.print_trait_sugared())),
19131916
StringPart::highlighted("is"),
@@ -1932,7 +1935,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
19321935
}
19331936

19341937
let other = if other { "other " } else { "" };
1935-
let report = |candidates: Vec<TraitRef<'tcx>>, err: &mut Diag<'_>| {
1938+
let report = |mut candidates: Vec<TraitRef<'tcx>>, err: &mut Diag<'_>| {
1939+
candidates.retain(|tr| !tr.references_error());
19361940
if candidates.is_empty() {
19371941
return false;
19381942
}

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

-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ error[E0277]: the trait bound `Demo: TraitWAssocConst` is not satisfied
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 bound `Demo: TraitWAssocConst` is not satisfied
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)