Skip to content

Commit 845600c

Browse files
committed
ty::Alias refactor: fix clippy
1 parent 83e3011 commit 845600c

14 files changed

Lines changed: 95 additions & 31 deletions

src/tools/clippy/clippy_lints/src/dereference.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -885,12 +885,21 @@ impl TyCoercionStability {
885885
continue;
886886
},
887887
ty::Param(_) if for_return => Self::Deref,
888-
ty::Alias(ty::Free | ty::Inherent, _) => unreachable!("should have been normalized away above"),
889-
ty::Alias(ty::Projection, _) if !for_return && ty.has_non_region_param() => Self::Reborrow,
888+
ty::Alias(ty::AliasTy {
889+
kind: ty::Free { .. } | ty::Inherent { .. },
890+
..
891+
}) => unreachable!("should have been normalized away above"),
892+
ty::Alias(ty::AliasTy {
893+
kind: ty::Projection { .. },
894+
..
895+
}) if !for_return && ty.has_non_region_param() => Self::Reborrow,
890896
ty::Infer(_)
891897
| ty::Error(_)
892898
| ty::Bound(..)
893-
| ty::Alias(ty::Opaque, ..)
899+
| ty::Alias(ty::AliasTy {
900+
kind: ty::Opaque { .. },
901+
..
902+
})
894903
| ty::Placeholder(_)
895904
| ty::Dynamic(..)
896905
| ty::Param(_) => Self::Reborrow,
@@ -921,7 +930,10 @@ impl TyCoercionStability {
921930
| ty::CoroutineClosure(..)
922931
| ty::Never
923932
| ty::Tuple(_)
924-
| ty::Alias(ty::Projection, _)
933+
| ty::Alias(ty::AliasTy {
934+
kind: ty::Projection { .. },
935+
..
936+
})
925937
| ty::UnsafeBinder(_) => Self::Deref,
926938
};
927939
}

src/tools/clippy/clippy_lints/src/from_over_into.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto {
7878
&& span_is_local(item.span)
7979
&& let middle_trait_ref = cx.tcx.impl_trait_ref(item.owner_id).instantiate_identity()
8080
&& cx.tcx.is_diagnostic_item(sym::Into, middle_trait_ref.def_id)
81-
&& !matches!(middle_trait_ref.args.type_at(1).kind(), ty::Alias(ty::Opaque, _))
81+
&& !matches!(middle_trait_ref.args.type_at(1).kind(), ty::Alias(ty::AliasTy { kind: ty::Opaque{..} , .. }))
8282
&& self.msrv.meets(cx, msrvs::RE_REBALANCING_COHERENCE)
8383
{
8484
span_lint_and_then(

src/tools/clippy/clippy_lints/src/future_not_send.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
7575
return;
7676
}
7777
let ret_ty = return_ty(cx, cx.tcx.local_def_id_to_hir_id(fn_def_id).expect_owner());
78-
if let ty::Alias(ty::Opaque, AliasTy { def_id, args, .. }) = *ret_ty.kind()
78+
if let ty::Alias(AliasTy { kind: ty::Opaque{def_id}, args, .. }) = *ret_ty.kind()
7979
&& let Some(future_trait) = cx.tcx.lang_items().future_trait()
8080
&& let Some(send_trait) = cx.tcx.get_diagnostic_item(sym::Send)
8181
&& let preds = cx.tcx.explicit_item_self_bounds(def_id)
@@ -148,7 +148,12 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for TyParamAtTopLevelVisitor {
148148
fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result {
149149
match ty.kind() {
150150
ty::Param(_) => ControlFlow::Break(true),
151-
ty::Alias(ty::AliasTyKind::Projection, ty) => ty.visit_with(self),
151+
ty::Alias(
152+
ty @ AliasTy {
153+
kind: ty::Projection { .. },
154+
..
155+
},
156+
) => ty.visit_with(self),
152157
_ => ControlFlow::Break(false),
153158
}
154159
}

src/tools/clippy/clippy_lints/src/indexing_slicing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ fn ty_has_applicable_get_function<'tcx>(
280280
&& let generic_ty = option_generic_param.expect_ty().peel_refs()
281281
// FIXME: ideally this would handle type params and projections properly, for now just assume it's the same type
282282
&& (cx.typeck_results().expr_ty(index_expr).peel_refs() == generic_ty.peel_refs()
283-
|| matches!(generic_ty.peel_refs().kind(), ty::Param(_) | ty::Alias(_, _)))
283+
|| matches!(generic_ty.peel_refs().kind(), ty::Param(_) | ty::Alias(_)))
284284
{
285285
true
286286
} else {

src/tools/clippy/clippy_lints/src/len_without_is_empty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, ident: Iden
137137
}
138138

139139
fn extract_future_output<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<&'tcx PathSegment<'tcx>> {
140-
if let ty::Alias(_, alias_ty) = ty.kind()
141-
&& let Some(Node::OpaqueTy(opaque)) = cx.tcx.hir_get_if_local(alias_ty.def_id)
140+
if let ty::Alias(alias_ty) = ty.kind()
141+
&& let Some(Node::OpaqueTy(opaque)) = cx.tcx.hir_get_if_local(alias_ty.kind.def_id())
142142
&& let OpaqueTyOrigin::AsyncFn { .. } = opaque.origin
143143
&& let [GenericBound::Trait(trait_ref)] = &opaque.bounds
144144
&& let Some(segment) = trait_ref.trait_ref.path.segments.last()

src/tools/clippy/clippy_lints/src/len_zero.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,10 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: Msrv) -> bool {
336336
.filter_by_name_unhygienic(sym::is_empty)
337337
.any(|item| is_is_empty_and_stable(cx, item, msrv))
338338
}),
339-
ty::Alias(ty::Projection, proj) => has_is_empty_impl(cx, proj.def_id, msrv),
339+
&ty::Alias(ty::AliasTy {
340+
kind: ty::Projection { def_id },
341+
..
342+
}) => has_is_empty_impl(cx, def_id, msrv),
340343
ty::Adt(id, _) => {
341344
has_is_empty_impl(cx, id.did(), msrv)
342345
|| (cx.tcx.recursion_limit().value_within_limit(depth)

src/tools/clippy/clippy_lints/src/methods/needless_collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ fn iterates_same_ty<'tcx>(cx: &LateContext<'tcx>, iter_ty: Ty<'tcx>, collect_ty:
247247
&& let Some(into_iter_item_proj) = make_projection(cx.tcx, into_iter_trait, sym::Item, [collect_ty])
248248
&& let Ok(into_iter_item_ty) = cx.tcx.try_normalize_erasing_regions(
249249
cx.typing_env(),
250-
Ty::new_projection_from_args(cx.tcx, into_iter_item_proj.def_id, into_iter_item_proj.args),
250+
Ty::new_projection_from_args(cx.tcx, into_iter_item_proj.kind.def_id(), into_iter_item_proj.args),
251251
)
252252
{
253253
iter_item_ty == into_iter_item_ty

src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ fn fn_inputs_has_impl_trait_ty(cx: &LateContext<'_>, def_id: LocalDefId) -> bool
207207
inputs.iter().any(|input| {
208208
matches!(
209209
input.kind(),
210-
ty::Alias(ty::AliasTyKind::Free, alias_ty) if cx.tcx.type_of(alias_ty.def_id).skip_binder().is_impl_trait()
210+
&ty::Alias(ty::AliasTy { kind: ty::Free{def_id} , ..}) if cx.tcx.type_of(def_id).skip_binder().is_impl_trait()
211211
)
212212
})
213213
}

src/tools/clippy/clippy_lints/src/needless_borrows_for_generic_args.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,12 @@ fn is_mixed_projection_predicate<'tcx>(
331331
let mut projection_term = projection_predicate.projection_term;
332332
loop {
333333
match *projection_term.self_ty().kind() {
334-
ty::Alias(ty::Projection, inner_projection_ty) => {
334+
ty::Alias(
335+
inner_projection_ty @ ty::AliasTy {
336+
kind: ty::Projection { .. },
337+
..
338+
},
339+
) => {
335340
projection_term = inner_projection_ty.into();
336341
},
337342
ty::Param(param_ty) => {

src/tools/clippy/clippy_lints/src/non_copy_const.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ use rustc_lint::{LateContext, LateLintPass, LintContext};
3535
use rustc_middle::mir::{ConstValue, UnevaluatedConst};
3636
use rustc_middle::ty::adjustment::{Adjust, Adjustment, DerefAdjustKind};
3737
use rustc_middle::ty::{
38-
self, AliasTyKind, EarlyBinder, GenericArgs, GenericArgsRef, Instance, Ty, TyCtxt, TypeFolder, TypeSuperFoldable,
39-
TypeckResults, TypingEnv,
38+
self, EarlyBinder, GenericArgs, GenericArgsRef, Instance, Ty, TyCtxt, TypeFolder, TypeSuperFoldable, TypeckResults,
39+
TypingEnv,
4040
};
4141
use rustc_session::impl_lint_pass;
4242
use rustc_span::DUMMY_SP;
@@ -884,7 +884,12 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReplaceAssocFolder<'tcx> {
884884
}
885885

886886
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
887-
if let ty::Alias(AliasTyKind::Projection, ty) = ty.kind()
887+
if let ty::Alias(
888+
ty @ ty::AliasTy {
889+
kind: ty::Projection { .. },
890+
..
891+
},
892+
) = ty.kind()
888893
&& ty.trait_def_id(self.tcx) == self.trait_id
889894
&& ty.self_ty() == self.self_ty
890895
{

0 commit comments

Comments
 (0)