Skip to content

Commit 4b19c80

Browse files
committed
Don't create strings in the fast path
1 parent 88d1109 commit 4b19c80

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

src/librustc_typeck/astconv.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,10 +1318,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
13181318
// those that do.
13191319
self.one_bound_for_assoc_type(
13201320
|| traits::supertraits(tcx, trait_ref),
1321-
&trait_ref.print_only_trait_path().to_string(),
1321+
|| trait_ref.print_only_trait_path().to_string(),
13221322
binding.item_name,
13231323
path_span,
1324-
match binding.kind {
1324+
|| match binding.kind {
13251325
ConvertedBindingKind::Equality(ty) => Some(ty.to_string()),
13261326
_ => None,
13271327
},
@@ -1878,10 +1878,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
18781878
predicates.iter().filter_map(|(p, _)| p.to_opt_poly_trait_ref()),
18791879
)
18801880
},
1881-
&param_name.as_str(),
1881+
|| param_name.to_string(),
18821882
assoc_name,
18831883
span,
1884-
None,
1884+
|| None,
18851885
)
18861886
}
18871887

@@ -1890,10 +1890,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
18901890
fn one_bound_for_assoc_type<I>(
18911891
&self,
18921892
all_candidates: impl Fn() -> I,
1893-
ty_param_name: &str,
1893+
ty_param_name: impl Fn() -> String,
18941894
assoc_name: ast::Ident,
18951895
span: Span,
1896-
is_equality: Option<String>,
1896+
is_equality: impl Fn() -> Option<String>,
18971897
) -> Result<ty::PolyTraitRef<'tcx>, ErrorReported>
18981898
where
18991899
I: Iterator<Item = ty::PolyTraitRef<'tcx>>,
@@ -1906,7 +1906,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
19061906
None => {
19071907
self.complain_about_assoc_type_not_found(
19081908
all_candidates,
1909-
ty_param_name,
1909+
&ty_param_name(),
19101910
assoc_name,
19111911
span,
19121912
);
@@ -1919,6 +1919,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
19191919
if let Some(bound2) = matching_candidates.next() {
19201920
debug!("one_bound_for_assoc_type: bound2 = {:?}", bound2);
19211921

1922+
let is_equality = is_equality();
19221923
let bounds = iter::once(bound).chain(iter::once(bound2)).chain(matching_candidates);
19231924
let mut err = if is_equality.is_some() {
19241925
// More specific Error Index entry.
@@ -1928,7 +1929,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
19281929
E0222,
19291930
"ambiguous associated type `{}` in bounds of `{}`",
19301931
assoc_name,
1931-
ty_param_name
1932+
ty_param_name()
19321933
)
19331934
} else {
19341935
struct_span_err!(
@@ -1937,7 +1938,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
19371938
E0221,
19381939
"ambiguous associated type `{}` in bounds of `{}`",
19391940
assoc_name,
1940-
ty_param_name
1941+
ty_param_name()
19411942
)
19421943
};
19431944
err.span_label(span, format!("ambiguous associated type `{}`", assoc_name));
@@ -1975,7 +1976,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
19751976
"use fully qualified syntax to disambiguate",
19761977
format!(
19771978
"<{} as {}>::{}",
1978-
ty_param_name,
1979+
ty_param_name(),
19791980
bound.print_only_trait_path(),
19801981
assoc_name,
19811982
),
@@ -1985,7 +1986,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
19851986
} else {
19861987
err.note(&format!(
19871988
"associated type `{}` could derive from `{}`",
1988-
ty_param_name,
1989+
ty_param_name(),
19891990
bound.print_only_trait_path(),
19901991
));
19911992
}
@@ -1994,7 +1995,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
19941995
err.help(&format!(
19951996
"consider introducing a new type parameter `T` and adding `where` constraints:\
19961997
\n where\n T: {},\n{}",
1997-
ty_param_name,
1998+
ty_param_name(),
19981999
where_bounds.join(",\n"),
19992000
));
20002001
}
@@ -2108,10 +2109,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
21082109

21092110
self.one_bound_for_assoc_type(
21102111
|| traits::supertraits(tcx, ty::Binder::bind(trait_ref)),
2111-
"Self",
2112+
|| "Self".to_string(),
21122113
assoc_ident,
21132114
span,
2114-
None,
2115+
|| None,
21152116
)?
21162117
}
21172118
(&ty::Param(_), Res::SelfTy(Some(param_did), None))

0 commit comments

Comments
 (0)