Don't create strings in the fast path
This commit is contained in:
parent
88d1109600
commit
4b19c80819
@ -1318,10 +1318,10 @@ fn add_predicates_for_ast_type_binding(
|
|||||||
// those that do.
|
// those that do.
|
||||||
self.one_bound_for_assoc_type(
|
self.one_bound_for_assoc_type(
|
||||||
|| traits::supertraits(tcx, trait_ref),
|
|| traits::supertraits(tcx, trait_ref),
|
||||||
&trait_ref.print_only_trait_path().to_string(),
|
|| trait_ref.print_only_trait_path().to_string(),
|
||||||
binding.item_name,
|
binding.item_name,
|
||||||
path_span,
|
path_span,
|
||||||
match binding.kind {
|
|| match binding.kind {
|
||||||
ConvertedBindingKind::Equality(ty) => Some(ty.to_string()),
|
ConvertedBindingKind::Equality(ty) => Some(ty.to_string()),
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
@ -1878,10 +1878,10 @@ fn find_bound_for_assoc_item(
|
|||||||
predicates.iter().filter_map(|(p, _)| p.to_opt_poly_trait_ref()),
|
predicates.iter().filter_map(|(p, _)| p.to_opt_poly_trait_ref()),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
¶m_name.as_str(),
|
|| param_name.to_string(),
|
||||||
assoc_name,
|
assoc_name,
|
||||||
span,
|
span,
|
||||||
None,
|
|| None,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1890,10 +1890,10 @@ fn find_bound_for_assoc_item(
|
|||||||
fn one_bound_for_assoc_type<I>(
|
fn one_bound_for_assoc_type<I>(
|
||||||
&self,
|
&self,
|
||||||
all_candidates: impl Fn() -> I,
|
all_candidates: impl Fn() -> I,
|
||||||
ty_param_name: &str,
|
ty_param_name: impl Fn() -> String,
|
||||||
assoc_name: ast::Ident,
|
assoc_name: ast::Ident,
|
||||||
span: Span,
|
span: Span,
|
||||||
is_equality: Option<String>,
|
is_equality: impl Fn() -> Option<String>,
|
||||||
) -> Result<ty::PolyTraitRef<'tcx>, ErrorReported>
|
) -> Result<ty::PolyTraitRef<'tcx>, ErrorReported>
|
||||||
where
|
where
|
||||||
I: Iterator<Item = ty::PolyTraitRef<'tcx>>,
|
I: Iterator<Item = ty::PolyTraitRef<'tcx>>,
|
||||||
@ -1906,7 +1906,7 @@ fn one_bound_for_assoc_type<I>(
|
|||||||
None => {
|
None => {
|
||||||
self.complain_about_assoc_type_not_found(
|
self.complain_about_assoc_type_not_found(
|
||||||
all_candidates,
|
all_candidates,
|
||||||
ty_param_name,
|
&ty_param_name(),
|
||||||
assoc_name,
|
assoc_name,
|
||||||
span,
|
span,
|
||||||
);
|
);
|
||||||
@ -1919,6 +1919,7 @@ fn one_bound_for_assoc_type<I>(
|
|||||||
if let Some(bound2) = matching_candidates.next() {
|
if let Some(bound2) = matching_candidates.next() {
|
||||||
debug!("one_bound_for_assoc_type: bound2 = {:?}", bound2);
|
debug!("one_bound_for_assoc_type: bound2 = {:?}", bound2);
|
||||||
|
|
||||||
|
let is_equality = is_equality();
|
||||||
let bounds = iter::once(bound).chain(iter::once(bound2)).chain(matching_candidates);
|
let bounds = iter::once(bound).chain(iter::once(bound2)).chain(matching_candidates);
|
||||||
let mut err = if is_equality.is_some() {
|
let mut err = if is_equality.is_some() {
|
||||||
// More specific Error Index entry.
|
// More specific Error Index entry.
|
||||||
@ -1928,7 +1929,7 @@ fn one_bound_for_assoc_type<I>(
|
|||||||
E0222,
|
E0222,
|
||||||
"ambiguous associated type `{}` in bounds of `{}`",
|
"ambiguous associated type `{}` in bounds of `{}`",
|
||||||
assoc_name,
|
assoc_name,
|
||||||
ty_param_name
|
ty_param_name()
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
struct_span_err!(
|
struct_span_err!(
|
||||||
@ -1937,7 +1938,7 @@ fn one_bound_for_assoc_type<I>(
|
|||||||
E0221,
|
E0221,
|
||||||
"ambiguous associated type `{}` in bounds of `{}`",
|
"ambiguous associated type `{}` in bounds of `{}`",
|
||||||
assoc_name,
|
assoc_name,
|
||||||
ty_param_name
|
ty_param_name()
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
err.span_label(span, format!("ambiguous associated type `{}`", assoc_name));
|
err.span_label(span, format!("ambiguous associated type `{}`", assoc_name));
|
||||||
@ -1975,7 +1976,7 @@ fn one_bound_for_assoc_type<I>(
|
|||||||
"use fully qualified syntax to disambiguate",
|
"use fully qualified syntax to disambiguate",
|
||||||
format!(
|
format!(
|
||||||
"<{} as {}>::{}",
|
"<{} as {}>::{}",
|
||||||
ty_param_name,
|
ty_param_name(),
|
||||||
bound.print_only_trait_path(),
|
bound.print_only_trait_path(),
|
||||||
assoc_name,
|
assoc_name,
|
||||||
),
|
),
|
||||||
@ -1985,7 +1986,7 @@ fn one_bound_for_assoc_type<I>(
|
|||||||
} else {
|
} else {
|
||||||
err.note(&format!(
|
err.note(&format!(
|
||||||
"associated type `{}` could derive from `{}`",
|
"associated type `{}` could derive from `{}`",
|
||||||
ty_param_name,
|
ty_param_name(),
|
||||||
bound.print_only_trait_path(),
|
bound.print_only_trait_path(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -1994,7 +1995,7 @@ fn one_bound_for_assoc_type<I>(
|
|||||||
err.help(&format!(
|
err.help(&format!(
|
||||||
"consider introducing a new type parameter `T` and adding `where` constraints:\
|
"consider introducing a new type parameter `T` and adding `where` constraints:\
|
||||||
\n where\n T: {},\n{}",
|
\n where\n T: {},\n{}",
|
||||||
ty_param_name,
|
ty_param_name(),
|
||||||
where_bounds.join(",\n"),
|
where_bounds.join(",\n"),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -2108,10 +2109,10 @@ pub fn associated_path_to_ty(
|
|||||||
|
|
||||||
self.one_bound_for_assoc_type(
|
self.one_bound_for_assoc_type(
|
||||||
|| traits::supertraits(tcx, ty::Binder::bind(trait_ref)),
|
|| traits::supertraits(tcx, ty::Binder::bind(trait_ref)),
|
||||||
"Self",
|
|| "Self".to_string(),
|
||||||
assoc_ident,
|
assoc_ident,
|
||||||
span,
|
span,
|
||||||
None,
|
|| None,
|
||||||
)?
|
)?
|
||||||
}
|
}
|
||||||
(&ty::Param(_), Res::SelfTy(Some(param_did), None))
|
(&ty::Param(_), Res::SelfTy(Some(param_did), None))
|
||||||
|
Loading…
Reference in New Issue
Block a user