Skip to content

Commit

Permalink
Rollup merge of rust-lang#108520 - compiler-errors:one-bound-nit, r=j…
Browse files Browse the repository at this point in the history
…ackh726

Small cleanup to `one_bound_for_assoc_type`

Use fewer closures :)
  • Loading branch information
matthiaskrgr authored Feb 28, 2023
2 parents 2bceb2a + ff336aa commit 3a11131
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions compiler/rustc_hir_analysis/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ use rustc_trait_selection::traits::{self, astconv_object_safety_violations, Obli

use smallvec::{smallvec, SmallVec};
use std::collections::BTreeSet;
use std::fmt::Display;
use std::slice;

#[derive(Debug)]
Expand Down Expand Up @@ -1095,11 +1096,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// those that do.
self.one_bound_for_assoc_type(
|| traits::supertraits(tcx, trait_ref),
|| trait_ref.print_only_trait_path().to_string(),
trait_ref.print_only_trait_path(),
binding.item_name,
path_span,
|| match binding.kind {
ConvertedBindingKind::Equality(ty) => Some(ty.to_string()),
match binding.kind {
ConvertedBindingKind::Equality(term) => Some(term),
_ => None,
},
)?
Expand Down Expand Up @@ -1789,10 +1790,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
assoc_name,
)
},
|| param_name.to_string(),
param_name,
assoc_name,
span,
|| None,
None,
)
}

Expand All @@ -1802,10 +1803,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
fn one_bound_for_assoc_type<I>(
&self,
all_candidates: impl Fn() -> I,
ty_param_name: impl Fn() -> String,
ty_param_name: impl Display,
assoc_name: Ident,
span: Span,
is_equality: impl Fn() -> Option<String>,
is_equality: Option<ty::Term<'tcx>>,
) -> Result<ty::PolyTraitRef<'tcx>, ErrorGuaranteed>
where
I: Iterator<Item = ty::PolyTraitRef<'tcx>>,
Expand All @@ -1821,7 +1822,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
(None, None) => {
let reported = self.complain_about_assoc_type_not_found(
all_candidates,
&ty_param_name(),
&ty_param_name.to_string(),
assoc_name,
span,
);
Expand All @@ -1833,7 +1834,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
if let Some(bound2) = next_cand {
debug!(?bound2);

let is_equality = is_equality();
let bounds = IntoIterator::into_iter([bound, bound2]).chain(matching_candidates);
let mut err = if is_equality.is_some() {
// More specific Error Index entry.
Expand All @@ -1843,7 +1843,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
E0222,
"ambiguous associated type `{}` in bounds of `{}`",
assoc_name,
ty_param_name()
ty_param_name
)
} else {
struct_span_err!(
Expand All @@ -1852,7 +1852,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
E0221,
"ambiguous associated type `{}` in bounds of `{}`",
assoc_name,
ty_param_name()
ty_param_name
)
};
err.span_label(span, format!("ambiguous associated type `{}`", assoc_name));
Expand Down Expand Up @@ -1886,18 +1886,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
err.span_suggestion_verbose(
span.with_hi(assoc_name.span.lo()),
"use fully qualified syntax to disambiguate",
format!(
"<{} as {}>::",
ty_param_name(),
bound.print_only_trait_path(),
),
format!("<{} as {}>::", ty_param_name, bound.print_only_trait_path()),
Applicability::MaybeIncorrect,
);
}
} else {
err.note(&format!(
"associated type `{}` could derive from `{}`",
ty_param_name(),
ty_param_name,
bound.print_only_trait_path(),
));
}
Expand All @@ -1906,7 +1902,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
err.help(&format!(
"consider introducing a new type parameter `T` and adding `where` constraints:\
\n where\n T: {},\n{}",
ty_param_name(),
ty_param_name,
where_bounds.join(",\n"),
));
}
Expand Down Expand Up @@ -2070,10 +2066,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {

self.one_bound_for_assoc_type(
|| traits::supertraits(tcx, ty::Binder::dummy(trait_ref.subst_identity())),
|| "Self".to_string(),
kw::SelfUpper,
assoc_ident,
span,
|| None,
None,
)?
}
(
Expand Down

0 comments on commit 3a11131

Please sign in to comment.