diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs index dcbb63f00f7..de3231a0e86 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs @@ -1908,6 +1908,9 @@ fn report_similar_impl_candidates( ct_op: |ct| ct.normalize(self.tcx, ty::ParamEnv::empty()), }, ); + if cand.references_error() { + return false; + } err.highlighted_help(vec![ StringPart::normal(format!("the trait `{}` ", cand.print_trait_sugared())), StringPart::highlighted("is"), @@ -1932,7 +1935,8 @@ fn report_similar_impl_candidates( } let other = if other { "other " } else { "" }; - let report = |candidates: Vec>, err: &mut Diag<'_>| { + let report = |mut candidates: Vec>, err: &mut Diag<'_>| { + candidates.retain(|tr| !tr.references_error()); if candidates.is_empty() { return false; } diff --git a/tests/ui/associated-consts/issue-105330.stderr b/tests/ui/associated-consts/issue-105330.stderr index 50ce69b3381..bde3675b48c 100644 --- a/tests/ui/associated-consts/issue-105330.stderr +++ b/tests/ui/associated-consts/issue-105330.stderr @@ -55,7 +55,6 @@ error[E0277]: the trait bound `Demo: TraitWAssocConst` is not satisfied LL | foo::()(); | ^^^^ the trait `TraitWAssocConst` is not implemented for `Demo` | - = help: the trait `TraitWAssocConst` is implemented for `{type error}` note: required by a bound in `foo` --> $DIR/issue-105330.rs:11:11 | @@ -92,7 +91,6 @@ error[E0277]: the trait bound `Demo: TraitWAssocConst` is not satisfied LL | foo::(); | ^^^^ the trait `TraitWAssocConst` is not implemented for `Demo` | - = help: the trait `TraitWAssocConst` is implemented for `{type error}` note: required by a bound in `foo` --> $DIR/issue-105330.rs:11:11 |