Small cleanup to one_bound_for_assoc_type
This commit is contained in:
parent
31448badfd
commit
ff336aa6f9
@ -50,6 +50,7 @@
|
|||||||
|
|
||||||
use smallvec::{smallvec, SmallVec};
|
use smallvec::{smallvec, SmallVec};
|
||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
|
use std::fmt::Display;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -1095,11 +1096,11 @@ 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(),
|
||||||
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(term) => Some(term),
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
)?
|
)?
|
||||||
@ -1789,10 +1790,10 @@ fn find_bound_for_assoc_item(
|
|||||||
assoc_name,
|
assoc_name,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|| param_name.to_string(),
|
param_name,
|
||||||
assoc_name,
|
assoc_name,
|
||||||
span,
|
span,
|
||||||
|| None,
|
None,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1802,10 +1803,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: impl Fn() -> String,
|
ty_param_name: impl Display,
|
||||||
assoc_name: Ident,
|
assoc_name: Ident,
|
||||||
span: Span,
|
span: Span,
|
||||||
is_equality: impl Fn() -> Option<String>,
|
is_equality: Option<ty::Term<'tcx>>,
|
||||||
) -> Result<ty::PolyTraitRef<'tcx>, ErrorGuaranteed>
|
) -> Result<ty::PolyTraitRef<'tcx>, ErrorGuaranteed>
|
||||||
where
|
where
|
||||||
I: Iterator<Item = ty::PolyTraitRef<'tcx>>,
|
I: Iterator<Item = ty::PolyTraitRef<'tcx>>,
|
||||||
@ -1821,7 +1822,7 @@ fn one_bound_for_assoc_type<I>(
|
|||||||
(None, None) => {
|
(None, None) => {
|
||||||
let reported = self.complain_about_assoc_type_not_found(
|
let reported = self.complain_about_assoc_type_not_found(
|
||||||
all_candidates,
|
all_candidates,
|
||||||
&ty_param_name(),
|
&ty_param_name.to_string(),
|
||||||
assoc_name,
|
assoc_name,
|
||||||
span,
|
span,
|
||||||
);
|
);
|
||||||
@ -1833,7 +1834,6 @@ fn one_bound_for_assoc_type<I>(
|
|||||||
if let Some(bound2) = next_cand {
|
if let Some(bound2) = next_cand {
|
||||||
debug!(?bound2);
|
debug!(?bound2);
|
||||||
|
|
||||||
let is_equality = is_equality();
|
|
||||||
let bounds = IntoIterator::into_iter([bound, bound2]).chain(matching_candidates);
|
let bounds = IntoIterator::into_iter([bound, 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.
|
||||||
@ -1843,7 +1843,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!(
|
||||||
@ -1852,7 +1852,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));
|
||||||
@ -1886,18 +1886,14 @@ fn one_bound_for_assoc_type<I>(
|
|||||||
err.span_suggestion_verbose(
|
err.span_suggestion_verbose(
|
||||||
span.with_hi(assoc_name.span.lo()),
|
span.with_hi(assoc_name.span.lo()),
|
||||||
"use fully qualified syntax to disambiguate",
|
"use fully qualified syntax to disambiguate",
|
||||||
format!(
|
format!("<{} as {}>::", ty_param_name, bound.print_only_trait_path()),
|
||||||
"<{} as {}>::",
|
|
||||||
ty_param_name(),
|
|
||||||
bound.print_only_trait_path(),
|
|
||||||
),
|
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} 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(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -1906,7 +1902,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"),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -2070,10 +2066,10 @@ pub fn associated_path_to_ty(
|
|||||||
|
|
||||||
self.one_bound_for_assoc_type(
|
self.one_bound_for_assoc_type(
|
||||||
|| traits::supertraits(tcx, ty::Binder::dummy(trait_ref.subst_identity())),
|
|| traits::supertraits(tcx, ty::Binder::dummy(trait_ref.subst_identity())),
|
||||||
|| "Self".to_string(),
|
kw::SelfUpper,
|
||||||
assoc_ident,
|
assoc_ident,
|
||||||
span,
|
span,
|
||||||
|| None,
|
None,
|
||||||
)?
|
)?
|
||||||
}
|
}
|
||||||
(
|
(
|
||||||
|
Loading…
Reference in New Issue
Block a user