}
fn suggest_removing_unsized_bound(
- tcx: TyCtxt<'_>,
generics: &hir::Generics<'_>,
suggestions: &mut Vec<(Span, String, SuggestChangingConstraintsMessage<'_>)>,
param: &hir::GenericParam<'_>,
// See if there's a `?Sized` bound that can be removed to suggest that.
// First look at the `where` clause because we can have `where T: ?Sized`,
// then look at params.
- let param_def_id = tcx.hir().local_def_id(param.hir_id);
for (where_pos, predicate) in generics.predicates.iter().enumerate() {
let WherePredicate::BoundPredicate(predicate) = predicate else {
continue;
};
- if !predicate.is_param_bound(param_def_id.to_def_id()) {
+ if !predicate.is_param_bound(param.def_id.to_def_id()) {
continue;
};
for (pos, bound) in predicate.bounds.iter().enumerate() {
- let hir::GenericBound::Trait(poly, hir::TraitBoundModifier::Maybe) = bound else {
+ let hir::GenericBound::Trait(poly, hir::TraitBoundModifier::Maybe) = bound else {
continue;
};
if poly.trait_ref.trait_def_id() != def_id {
param.span,
&format!("this type parameter needs to be `{}`", constraint),
);
- suggest_removing_unsized_bound(tcx, generics, &mut suggestions, param, def_id);
+ suggest_removing_unsized_bound(generics, &mut suggestions, param, def_id);
}
}
// --
// |
// replace with: `T: Bar +`
- let param_def_id = tcx.hir().local_def_id(param.hir_id);
- if let Some(span) = generics.bounds_span_for_suggestions(param_def_id) {
+ if let Some(span) = generics.bounds_span_for_suggestions(param.def_id) {
suggest_restrict(span, true);
continue;
}
c.super_visit_with(self)
}
}
-
-#[derive(Diagnostic)]
-#[diag(borrowck_const_not_used_in_type_alias)]
-pub(super) struct ConstNotUsedTraitAlias {
- pub ct: String,
- #[primary_span]
- pub span: Span,
-}