Don't suppress lint type_alias_bounds for ty aliases containing inherent assoc tys
This commit is contained in:
parent
02a2f02727
commit
63a54d93be
5 changed files with 56 additions and 42 deletions
|
@ -1425,30 +1425,27 @@ impl TypeAliasBounds {
|
|||
|
||||
impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds {
|
||||
fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) {
|
||||
let hir::ItemKind::TyAlias(hir_ty, type_alias_generics) = &item.kind else { return };
|
||||
let hir::ItemKind::TyAlias(hir_ty, generics) = &item.kind else { return };
|
||||
|
||||
// There must not be a where clause.
|
||||
if generics.predicates.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Bounds of lazy type aliases and TAITs are respected.
|
||||
if cx.tcx.type_alias_is_lazy(item.owner_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
let ty = cx.tcx.type_of(item.owner_id).skip_binder();
|
||||
if ty.has_inherent_projections() {
|
||||
// Bounds of type aliases that contain opaque types or inherent projections are
|
||||
// respected. E.g: `type X = impl Trait;`, `type X = (impl Trait, Y);`, `type X =
|
||||
// Type::Inherent;`.
|
||||
return;
|
||||
}
|
||||
|
||||
// There must not be a where clause
|
||||
if type_alias_generics.predicates.is_empty() {
|
||||
return;
|
||||
}
|
||||
// NOTE(inherent_associated_types): While we currently do take some bounds in type
|
||||
// aliases into consideration during IAT *selection*, we don't perform full use+def
|
||||
// site wfchecking for such type aliases. Therefore TAB should still trigger.
|
||||
// See also `tests/ui/associated-inherent-types/type-alias-bounds.rs`.
|
||||
|
||||
let mut where_spans = Vec::new();
|
||||
let mut inline_spans = Vec::new();
|
||||
let mut inline_sugg = Vec::new();
|
||||
for p in type_alias_generics.predicates {
|
||||
for p in generics.predicates {
|
||||
let span = p.span();
|
||||
if p.in_where_clause() {
|
||||
where_spans.push(span);
|
||||
|
@ -1469,10 +1466,7 @@ impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds {
|
|||
cx.emit_span_lint(
|
||||
TYPE_ALIAS_BOUNDS,
|
||||
where_spans,
|
||||
BuiltinTypeAliasWhereClause {
|
||||
suggestion: type_alias_generics.where_clause_span,
|
||||
sub,
|
||||
},
|
||||
BuiltinTypeAliasWhereClause { suggestion: generics.where_clause_span, sub },
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue