Skip to content

Commit

Permalink
Never say "Trait is implemented for {type error}
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Feb 28, 2024
1 parent ebbd167 commit 492bbf0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
Expand Up @@ -1908,20 +1908,25 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
ct_op: |ct| ct.normalize(self.tcx, ty::ParamEnv::empty()),
},
);
err.highlighted_help(vec![
StringPart::normal(format!("the trait `{}` ", cand.print_trait_sugared())),
StringPart::highlighted("is"),
StringPart::normal(" implemented for `"),
StringPart::highlighted(cand.self_ty().to_string()),
StringPart::normal("`"),
]);

if let [TypeError::Sorts(exp_found)] = &terrs[..] {
let exp_found = self.resolve_vars_if_possible(*exp_found);
err.help(format!(
"for that trait implementation, expected `{}`, found `{}`",
exp_found.expected, exp_found.found
));
if !cand.references_error() {
err.highlighted_help(vec![
StringPart::normal(format!(
"the trait `{}` ",
cand.print_trait_sugared()
)),
StringPart::highlighted("is"),
StringPart::normal(" implemented for `"),
StringPart::highlighted(cand.self_ty().to_string()),
StringPart::normal("`"),
]);

if let [TypeError::Sorts(exp_found)] = &terrs[..] {
let exp_found = self.resolve_vars_if_possible(*exp_found);
err.help(format!(
"for that trait implementation, expected `{}`, found `{}`",
exp_found.expected, exp_found.found
));
}
}

true
Expand All @@ -1932,7 +1937,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
}

let other = if other { "other " } else { "" };
let report = |candidates: Vec<TraitRef<'tcx>>, err: &mut Diag<'_>| {
let report = |mut candidates: Vec<TraitRef<'tcx>>, err: &mut Diag<'_>| {
candidates.retain(|tr| !tr.references_error());
if candidates.is_empty() {
return false;
}
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/associated-consts/issue-105330.stderr
Expand Up @@ -55,7 +55,6 @@ error[E0277]: the trait `TraitWAssocConst` is not implemented for `Demo`
LL | foo::<Demo>()();
| ^^^^ 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
|
Expand Down Expand Up @@ -92,7 +91,6 @@ error[E0277]: the trait `TraitWAssocConst` is not implemented for `Demo`
LL | foo::<Demo>();
| ^^^^ 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
|
Expand Down

0 comments on commit 492bbf0

Please sign in to comment.