Skip to content

Commit b1786f6

Browse files
committed
add tcx to fn walk
1 parent 19d1fe2 commit b1786f6

File tree

11 files changed

+23
-23
lines changed

11 files changed

+23
-23
lines changed

clippy_lints/src/escape.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn is_non_trait_box(ty: Ty<'_>) -> bool {
5353
struct EscapeDelegate<'a, 'tcx> {
5454
cx: &'a LateContext<'tcx>,
5555
set: HirIdSet,
56-
trait_self_ty: Option<Ty<'a>>,
56+
trait_self_ty: Option<Ty<'tcx>>,
5757
too_large_for_stack: u64,
5858
}
5959

@@ -171,7 +171,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
171171
// skip if there is a `self` parameter binding to a type
172172
// that contains `Self` (i.e.: `self: Box<Self>`), see #4804
173173
if let Some(trait_self_ty) = self.trait_self_ty {
174-
if map.name(cmt.hir_id) == kw::SelfLower && contains_ty(cmt.place.ty(), trait_self_ty) {
174+
if map.name(cmt.hir_id) == kw::SelfLower && contains_ty(self.cx.tcx, cmt.place.ty(), trait_self_ty) {
175175
return;
176176
}
177177
}

clippy_lints/src/let_underscore.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
119119
if let Some(init) = local.init;
120120
then {
121121
let init_ty = cx.typeck_results().expr_ty(init);
122-
let contains_sync_guard = init_ty.walk().any(|inner| match inner.unpack() {
122+
let contains_sync_guard = init_ty.walk(cx.tcx).any(|inner| match inner.unpack() {
123123
GenericArgKind::Type(inner_ty) => {
124124
SYNC_GUARD_PATHS.iter().any(|path| match_type(cx, inner_ty, path))
125125
},

clippy_lints/src/loops/same_item_push.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub(super) fn check<'tcx>(
4949
if same_item_push_visitor.should_lint();
5050
if let Some((vec, pushed_item)) = same_item_push_visitor.vec_push;
5151
let vec_ty = cx.typeck_results().expr_ty(vec);
52-
let ty = vec_ty.walk().nth(1).unwrap().expect_ty();
52+
let ty = vec_ty.walk(cx.tcx).nth(1).unwrap().expect_ty();
5353
if cx
5454
.tcx
5555
.lang_items()

clippy_lints/src/methods/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,10 +1987,10 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
19871987

19881988
// walk the return type and check for Self (this does not check associated types)
19891989
if let Some(self_adt) = self_ty.ty_adt_def() {
1990-
if contains_adt_constructor(ret_ty, self_adt) {
1990+
if contains_adt_constructor(cx.tcx, ret_ty, self_adt) {
19911991
return;
19921992
}
1993-
} else if contains_ty(ret_ty, self_ty) {
1993+
} else if contains_ty(cx.tcx, ret_ty, self_ty) {
19941994
return;
19951995
}
19961996

@@ -2001,10 +2001,10 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
20012001
if let ty::PredicateKind::Projection(projection_predicate) = predicate.kind().skip_binder() {
20022002
// walk the associated type and check for Self
20032003
if let Some(self_adt) = self_ty.ty_adt_def() {
2004-
if contains_adt_constructor(projection_predicate.ty, self_adt) {
2004+
if contains_adt_constructor(cx.tcx, projection_predicate.ty, self_adt) {
20052005
return;
20062006
}
2007-
} else if contains_ty(projection_predicate.ty, self_ty) {
2007+
} else if contains_ty(cx.tcx, projection_predicate.ty, self_ty) {
20082008
return;
20092009
}
20102010
}
@@ -2053,7 +2053,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
20532053
if let TraitItemKind::Fn(_, _) = item.kind;
20542054
let ret_ty = return_ty(cx, item.hir_id());
20552055
let self_ty = TraitRef::identity(cx.tcx, item.def_id.to_def_id()).self_ty();
2056-
if !contains_ty(ret_ty, self_ty);
2056+
if !contains_ty(cx.tcx, ret_ty, self_ty);
20572057

20582058
then {
20592059
span_lint(

clippy_lints/src/returns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ impl<'tcx> Visitor<'tcx> for BorrowVisitor<'_, 'tcx> {
288288
.fn_sig(def_id)
289289
.output()
290290
.skip_binder()
291-
.walk()
291+
.walk(self.cx.tcx)
292292
.any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(_)));
293293
}
294294

clippy_lints/src/self_named_constructors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ impl<'tcx> LateLintPass<'tcx> for SelfNamedConstructors {
6262

6363
// Ensure method is constructor-like
6464
if let Some(self_adt) = self_ty.ty_adt_def() {
65-
if !contains_adt_constructor(ret_ty, self_adt) {
65+
if !contains_adt_constructor(cx.tcx, ret_ty, self_adt) {
6666
return;
6767
}
68-
} else if !contains_ty(ret_ty, self_ty) {
68+
} else if !contains_ty(cx.tcx, ret_ty, self_ty) {
6969
return;
7070
}
7171

clippy_lints/src/unnecessary_sort_by.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ fn detect_lint(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<LintTrigger> {
218218

219219
fn expr_borrows(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
220220
let ty = cx.typeck_results().expr_ty(expr);
221-
matches!(ty.kind(), ty::Ref(..)) || ty.walk().any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(_)))
221+
matches!(ty.kind(), ty::Ref(..)) || ty.walk(cx.tcx).any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(_)))
222222
}
223223

224224
impl LateLintPass<'_> for UnnecessarySortBy {

clippy_lints/src/use_self.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
170170
//
171171
// See also https://github.com/rust-lang/rust-clippy/issues/2894.
172172
for (impl_hir_ty, trait_sem_ty) in impl_inputs_outputs.zip(trait_method_sig.inputs_and_output) {
173-
if trait_sem_ty.walk().any(|inner| inner == self_ty.into()) {
173+
if trait_sem_ty.walk(cx.tcx).any(|inner| inner == self_ty.into()) {
174174
let mut visitor = SkipTyCollector::default();
175175
visitor.visit_ty(impl_hir_ty);
176176
types_to_skip.extend(visitor.types_to_skip);

clippy_utils/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,15 +1627,15 @@ pub fn is_slice_of_primitives(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<S
16271627
if is_primitive {
16281628
// if we have wrappers like Array, Slice or Tuple, print these
16291629
// and get the type enclosed in the slice ref
1630-
match expr_type.peel_refs().walk().nth(1).unwrap().expect_ty().kind() {
1630+
match expr_type.peel_refs().walk(cx.tcx).nth(1).unwrap().expect_ty().kind() {
16311631
rustc_ty::Slice(..) => return Some("slice".into()),
16321632
rustc_ty::Array(..) => return Some("array".into()),
16331633
rustc_ty::Tuple(..) => return Some("tuple".into()),
16341634
_ => {
16351635
// is_recursively_primitive_type() should have taken care
16361636
// of the rest and we can rely on the type that is found
16371637
let refs_peeled = expr_type.peel_refs();
1638-
return Some(refs_peeled.walk().last().unwrap().to_string());
1638+
return Some(refs_peeled.walk(cx.tcx).last().unwrap().to_string());
16391639
},
16401640
}
16411641
}

clippy_utils/src/qualify_min_const_fn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, msrv: Option<&Ru
8888
}
8989

9090
fn check_ty(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) -> McfResult {
91-
for arg in ty.walk() {
91+
for arg in ty.walk(tcx) {
9292
let ty = match arg.unpack() {
9393
GenericArgKind::Type(ty) => ty,
9494

clippy_utils/src/ty.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_hir::{TyKind, Unsafety};
1010
use rustc_infer::infer::TyCtxtInferExt;
1111
use rustc_lint::LateContext;
1212
use rustc_middle::ty::subst::{GenericArg, GenericArgKind};
13-
use rustc_middle::ty::{self, AdtDef, IntTy, Ty, TypeFoldable, UintTy};
13+
use rustc_middle::ty::{self, TyCtxt, AdtDef, IntTy, Ty, TypeFoldable, UintTy};
1414
use rustc_span::sym;
1515
use rustc_span::symbol::{Ident, Symbol};
1616
use rustc_span::DUMMY_SP;
@@ -36,17 +36,17 @@ pub fn can_partially_move_ty(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
3636
}
3737

3838
/// Walks into `ty` and returns `true` if any inner type is the same as `other_ty`
39-
pub fn contains_ty(ty: Ty<'_>, other_ty: Ty<'_>) -> bool {
40-
ty.walk().any(|inner| match inner.unpack() {
39+
pub fn contains_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, other_ty: Ty<'tcx>) -> bool {
40+
ty.walk(tcx).any(|inner| match inner.unpack() {
4141
GenericArgKind::Type(inner_ty) => ty::TyS::same_type(other_ty, inner_ty),
4242
GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false,
4343
})
4444
}
4545

4646
/// Walks into `ty` and returns `true` if any inner type is an instance of the given adt
4747
/// constructor.
48-
pub fn contains_adt_constructor(ty: Ty<'_>, adt: &AdtDef) -> bool {
49-
ty.walk().any(|inner| match inner.unpack() {
48+
pub fn contains_adt_constructor<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, adt: &'tcx AdtDef) -> bool {
49+
ty.walk(tcx).any(|inner| match inner.unpack() {
5050
GenericArgKind::Type(inner_ty) => inner_ty.ty_adt_def() == Some(adt),
5151
GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false,
5252
})
@@ -209,7 +209,7 @@ fn is_normalizable_helper<'tcx>(
209209
.iter()
210210
.all(|field| is_normalizable_helper(cx, param_env, field.ty(cx.tcx, substs), cache))
211211
}),
212-
_ => ty.walk().all(|generic_arg| match generic_arg.unpack() {
212+
_ => ty.walk(cx.tcx).all(|generic_arg| match generic_arg.unpack() {
213213
GenericArgKind::Type(inner_ty) if inner_ty != ty => {
214214
is_normalizable_helper(cx, param_env, inner_ty, cache)
215215
},

0 commit comments

Comments
 (0)