Modify existing bounds if they exist
This commit is contained in:
parent
044a28a409
commit
af5a37e844
13 changed files with 186 additions and 43 deletions
|
@ -193,6 +193,9 @@ fn suggest_removing_unsized_bound(
|
|||
}
|
||||
|
||||
/// Suggest restricting a type param with a new bound.
|
||||
///
|
||||
/// If `span_to_replace` is provided, then that span will be replaced with the
|
||||
/// `constraint`. If one wasn't provided, then the full bound will be suggested.
|
||||
pub fn suggest_constraining_type_param(
|
||||
tcx: TyCtxt<'_>,
|
||||
generics: &hir::Generics<'_>,
|
||||
|
@ -200,12 +203,14 @@ pub fn suggest_constraining_type_param(
|
|||
param_name: &str,
|
||||
constraint: &str,
|
||||
def_id: Option<DefId>,
|
||||
span_to_replace: Option<Span>,
|
||||
) -> bool {
|
||||
suggest_constraining_type_params(
|
||||
tcx,
|
||||
generics,
|
||||
err,
|
||||
[(param_name, constraint, def_id)].into_iter(),
|
||||
span_to_replace,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -215,6 +220,7 @@ pub fn suggest_constraining_type_params<'a>(
|
|||
generics: &hir::Generics<'_>,
|
||||
err: &mut Diagnostic,
|
||||
param_names_and_constraints: impl Iterator<Item = (&'a str, &'a str, Option<DefId>)>,
|
||||
span_to_replace: Option<Span>,
|
||||
) -> bool {
|
||||
let mut grouped = FxHashMap::default();
|
||||
param_names_and_constraints.for_each(|(param_name, constraint, def_id)| {
|
||||
|
@ -253,7 +259,9 @@ pub fn suggest_constraining_type_params<'a>(
|
|||
let mut suggest_restrict = |span, bound_list_non_empty| {
|
||||
suggestions.push((
|
||||
span,
|
||||
if bound_list_non_empty {
|
||||
if span_to_replace.is_some() {
|
||||
constraint.clone()
|
||||
} else if bound_list_non_empty {
|
||||
format!(" + {}", constraint)
|
||||
} else {
|
||||
format!(" {}", constraint)
|
||||
|
@ -262,6 +270,11 @@ pub fn suggest_constraining_type_params<'a>(
|
|||
))
|
||||
};
|
||||
|
||||
if let Some(span) = span_to_replace {
|
||||
suggest_restrict(span, true);
|
||||
continue;
|
||||
}
|
||||
|
||||
// When the type parameter has been provided bounds
|
||||
//
|
||||
// Message:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue