Skip to content

Commit

Permalink
Remove redundant notes in E0275
Browse files Browse the repository at this point in the history
Fix #58964.
  • Loading branch information
estebank committed Nov 18, 2020
1 parent 7d747db commit 2098ade
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 511 deletions.
Expand Up @@ -2055,13 +2055,37 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
}
}
ObligationCauseCode::ImplDerivedObligation(ref data) => {
let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_ref);
let mut parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_ref);
err.note(&format!(
"required because of the requirements on the impl of `{}` for `{}`",
parent_trait_ref.print_only_trait_path(),
parent_trait_ref.skip_binder().self_ty()
));
let parent_predicate = parent_trait_ref.without_const().to_predicate(tcx);

let mut parent_predicate = parent_trait_ref.without_const().to_predicate(tcx);
let mut data = data;
let mut redundant = false;
let mut count = 0;
while let ObligationCauseCode::ImplDerivedObligation(child) = &*data.parent_code {
// Skip redundant recursive obligation notes. See `ui/issue-20413.rs`.
let child_trait_ref = self.resolve_vars_if_possible(child.parent_trait_ref);
if parent_trait_ref.def_id() != child_trait_ref.def_id() {
break;
}
count += 1;
redundant = true;
data = child;
parent_predicate = child_trait_ref.without_const().to_predicate(tcx);
parent_trait_ref = child_trait_ref;
}
if redundant {
err.note(&format!("{} redundant requirements hidden", count));
err.note(&format!(
"required because of the requirements on the impl of `{}` for `{}`",
parent_trait_ref.print_only_trait_path(),
parent_trait_ref.skip_binder().self_ty()
));
}
// #74711: avoid a stack overflow
ensure_sufficient_stack(|| {
self.note_obligation_cause_code(
Expand All @@ -2087,15 +2111,15 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
}
ObligationCauseCode::CompareImplMethodObligation { .. } => {
err.note(&format!(
"the requirement `{}` appears on the impl method \
but not on the corresponding trait method",
"the requirement `{}` appears on the impl method but not on the corresponding \
trait method",
predicate
));
}
ObligationCauseCode::CompareImplTypeObligation { .. } => {
err.note(&format!(
"the requirement `{}` appears on the associated impl type \
but not on the corresponding associated trait type",
"the requirement `{}` appears on the associated impl type but not on the \
corresponding associated trait type",
predicate
));
}
Expand Down

0 comments on commit 2098ade

Please sign in to comment.