Skip to content

Commit 3a11131

Browse files
authored
Rollup merge of rust-lang#108520 - compiler-errors:one-bound-nit, r=jackh726
Small cleanup to `one_bound_for_assoc_type` Use fewer closures :)
2 parents 2bceb2a + ff336aa commit 3a11131

File tree

1 file changed

+16
-20
lines changed
  • compiler/rustc_hir_analysis/src/astconv

1 file changed

+16
-20
lines changed

compiler/rustc_hir_analysis/src/astconv/mod.rs

+16-20
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ use rustc_trait_selection::traits::{self, astconv_object_safety_violations, Obli
5050

5151
use smallvec::{smallvec, SmallVec};
5252
use std::collections::BTreeSet;
53+
use std::fmt::Display;
5354
use std::slice;
5455

5556
#[derive(Debug)]
@@ -1095,11 +1096,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
10951096
// those that do.
10961097
self.one_bound_for_assoc_type(
10971098
|| traits::supertraits(tcx, trait_ref),
1098-
|| trait_ref.print_only_trait_path().to_string(),
1099+
trait_ref.print_only_trait_path(),
10991100
binding.item_name,
11001101
path_span,
1101-
|| match binding.kind {
1102-
ConvertedBindingKind::Equality(ty) => Some(ty.to_string()),
1102+
match binding.kind {
1103+
ConvertedBindingKind::Equality(term) => Some(term),
11031104
_ => None,
11041105
},
11051106
)?
@@ -1789,10 +1790,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
17891790
assoc_name,
17901791
)
17911792
},
1792-
|| param_name.to_string(),
1793+
param_name,
17931794
assoc_name,
17941795
span,
1795-
|| None,
1796+
None,
17961797
)
17971798
}
17981799

@@ -1802,10 +1803,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
18021803
fn one_bound_for_assoc_type<I>(
18031804
&self,
18041805
all_candidates: impl Fn() -> I,
1805-
ty_param_name: impl Fn() -> String,
1806+
ty_param_name: impl Display,
18061807
assoc_name: Ident,
18071808
span: Span,
1808-
is_equality: impl Fn() -> Option<String>,
1809+
is_equality: Option<ty::Term<'tcx>>,
18091810
) -> Result<ty::PolyTraitRef<'tcx>, ErrorGuaranteed>
18101811
where
18111812
I: Iterator<Item = ty::PolyTraitRef<'tcx>>,
@@ -1821,7 +1822,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
18211822
(None, None) => {
18221823
let reported = self.complain_about_assoc_type_not_found(
18231824
all_candidates,
1824-
&ty_param_name(),
1825+
&ty_param_name.to_string(),
18251826
assoc_name,
18261827
span,
18271828
);
@@ -1833,7 +1834,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
18331834
if let Some(bound2) = next_cand {
18341835
debug!(?bound2);
18351836

1836-
let is_equality = is_equality();
18371837
let bounds = IntoIterator::into_iter([bound, bound2]).chain(matching_candidates);
18381838
let mut err = if is_equality.is_some() {
18391839
// More specific Error Index entry.
@@ -1843,7 +1843,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
18431843
E0222,
18441844
"ambiguous associated type `{}` in bounds of `{}`",
18451845
assoc_name,
1846-
ty_param_name()
1846+
ty_param_name
18471847
)
18481848
} else {
18491849
struct_span_err!(
@@ -1852,7 +1852,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
18521852
E0221,
18531853
"ambiguous associated type `{}` in bounds of `{}`",
18541854
assoc_name,
1855-
ty_param_name()
1855+
ty_param_name
18561856
)
18571857
};
18581858
err.span_label(span, format!("ambiguous associated type `{}`", assoc_name));
@@ -1886,18 +1886,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
18861886
err.span_suggestion_verbose(
18871887
span.with_hi(assoc_name.span.lo()),
18881888
"use fully qualified syntax to disambiguate",
1889-
format!(
1890-
"<{} as {}>::",
1891-
ty_param_name(),
1892-
bound.print_only_trait_path(),
1893-
),
1889+
format!("<{} as {}>::", ty_param_name, bound.print_only_trait_path()),
18941890
Applicability::MaybeIncorrect,
18951891
);
18961892
}
18971893
} else {
18981894
err.note(&format!(
18991895
"associated type `{}` could derive from `{}`",
1900-
ty_param_name(),
1896+
ty_param_name,
19011897
bound.print_only_trait_path(),
19021898
));
19031899
}
@@ -1906,7 +1902,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
19061902
err.help(&format!(
19071903
"consider introducing a new type parameter `T` and adding `where` constraints:\
19081904
\n where\n T: {},\n{}",
1909-
ty_param_name(),
1905+
ty_param_name,
19101906
where_bounds.join(",\n"),
19111907
));
19121908
}
@@ -2070,10 +2066,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
20702066

20712067
self.one_bound_for_assoc_type(
20722068
|| traits::supertraits(tcx, ty::Binder::dummy(trait_ref.subst_identity())),
2073-
|| "Self".to_string(),
2069+
kw::SelfUpper,
20742070
assoc_ident,
20752071
span,
2076-
|| None,
2072+
None,
20772073
)?
20782074
}
20792075
(

0 commit comments

Comments
 (0)