Skip to content

Commit 06ca0de

Browse files
authored
Rollup merge of rust-lang#121803 - estebank:dont-mention-type-error-e0277, r=compiler-errors
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.
2 parents 0d2205f + dab3d5b commit 06ca0de

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
@@ -1916,6 +1916,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
19161916
ct_op: |ct| ct.normalize(self.tcx, ty::ParamEnv::empty()),
19171917
},
19181918
);
1919+
if cand.references_error() {
1920+
return false;
1921+
}
19191922
err.highlighted_help(vec![
19201923
StringPart::normal(format!("the trait `{}` ", cand.print_trait_sugared())),
19211924
StringPart::highlighted("is"),
@@ -1940,7 +1943,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
19401943
}
19411944

19421945
let other = if other { "other " } else { "" };
1943-
let report = |candidates: Vec<TraitRef<'tcx>>, err: &mut Diag<'_>| {
1946+
let report = |mut candidates: Vec<TraitRef<'tcx>>, err: &mut Diag<'_>| {
1947+
candidates.retain(|tr| !tr.references_error());
19441948
if candidates.is_empty() {
19451949
return false;
19461950
}

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)