add tcx to fn walk

This commit is contained in:
lcnr 2021-07-17 16:43:23 +02:00
parent 19d1fe21c7
commit b1786f62ed
11 changed files with 23 additions and 23 deletions

View file

@ -53,7 +53,7 @@ fn is_non_trait_box(ty: Ty<'_>) -> bool {
struct EscapeDelegate<'a, 'tcx> {
cx: &'a LateContext<'tcx>,
set: HirIdSet,
trait_self_ty: Option<Ty<'a>>,
trait_self_ty: Option<Ty<'tcx>>,
too_large_for_stack: u64,
}
@ -171,7 +171,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
// skip if there is a `self` parameter binding to a type
// that contains `Self` (i.e.: `self: Box<Self>`), see #4804
if let Some(trait_self_ty) = self.trait_self_ty {
if map.name(cmt.hir_id) == kw::SelfLower && contains_ty(cmt.place.ty(), trait_self_ty) {
if map.name(cmt.hir_id) == kw::SelfLower && contains_ty(self.cx.tcx, cmt.place.ty(), trait_self_ty) {
return;
}
}

View file

@ -119,7 +119,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
if let Some(init) = local.init;
then {
let init_ty = cx.typeck_results().expr_ty(init);
let contains_sync_guard = init_ty.walk().any(|inner| match inner.unpack() {
let contains_sync_guard = init_ty.walk(cx.tcx).any(|inner| match inner.unpack() {
GenericArgKind::Type(inner_ty) => {
SYNC_GUARD_PATHS.iter().any(|path| match_type(cx, inner_ty, path))
},

View file

@ -49,7 +49,7 @@ pub(super) fn check<'tcx>(
if same_item_push_visitor.should_lint();
if let Some((vec, pushed_item)) = same_item_push_visitor.vec_push;
let vec_ty = cx.typeck_results().expr_ty(vec);
let ty = vec_ty.walk().nth(1).unwrap().expect_ty();
let ty = vec_ty.walk(cx.tcx).nth(1).unwrap().expect_ty();
if cx
.tcx
.lang_items()

View file

@ -1987,10 +1987,10 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
// walk the return type and check for Self (this does not check associated types)
if let Some(self_adt) = self_ty.ty_adt_def() {
if contains_adt_constructor(ret_ty, self_adt) {
if contains_adt_constructor(cx.tcx, ret_ty, self_adt) {
return;
}
} else if contains_ty(ret_ty, self_ty) {
} else if contains_ty(cx.tcx, ret_ty, self_ty) {
return;
}
@ -2001,10 +2001,10 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
if let ty::PredicateKind::Projection(projection_predicate) = predicate.kind().skip_binder() {
// walk the associated type and check for Self
if let Some(self_adt) = self_ty.ty_adt_def() {
if contains_adt_constructor(projection_predicate.ty, self_adt) {
if contains_adt_constructor(cx.tcx, projection_predicate.ty, self_adt) {
return;
}
} else if contains_ty(projection_predicate.ty, self_ty) {
} else if contains_ty(cx.tcx, projection_predicate.ty, self_ty) {
return;
}
}
@ -2053,7 +2053,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
if let TraitItemKind::Fn(_, _) = item.kind;
let ret_ty = return_ty(cx, item.hir_id());
let self_ty = TraitRef::identity(cx.tcx, item.def_id.to_def_id()).self_ty();
if !contains_ty(ret_ty, self_ty);
if !contains_ty(cx.tcx, ret_ty, self_ty);
then {
span_lint(

View file

@ -288,7 +288,7 @@ impl<'tcx> Visitor<'tcx> for BorrowVisitor<'_, 'tcx> {
.fn_sig(def_id)
.output()
.skip_binder()
.walk()
.walk(self.cx.tcx)
.any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(_)));
}

View file

@ -62,10 +62,10 @@ impl<'tcx> LateLintPass<'tcx> for SelfNamedConstructors {
// Ensure method is constructor-like
if let Some(self_adt) = self_ty.ty_adt_def() {
if !contains_adt_constructor(ret_ty, self_adt) {
if !contains_adt_constructor(cx.tcx, ret_ty, self_adt) {
return;
}
} else if !contains_ty(ret_ty, self_ty) {
} else if !contains_ty(cx.tcx, ret_ty, self_ty) {
return;
}

View file

@ -218,7 +218,7 @@ fn detect_lint(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<LintTrigger> {
fn expr_borrows(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
let ty = cx.typeck_results().expr_ty(expr);
matches!(ty.kind(), ty::Ref(..)) || ty.walk().any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(_)))
matches!(ty.kind(), ty::Ref(..)) || ty.walk(cx.tcx).any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(_)))
}
impl LateLintPass<'_> for UnnecessarySortBy {

View file

@ -170,7 +170,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
//
// See also https://github.com/rust-lang/rust-clippy/issues/2894.
for (impl_hir_ty, trait_sem_ty) in impl_inputs_outputs.zip(trait_method_sig.inputs_and_output) {
if trait_sem_ty.walk().any(|inner| inner == self_ty.into()) {
if trait_sem_ty.walk(cx.tcx).any(|inner| inner == self_ty.into()) {
let mut visitor = SkipTyCollector::default();
visitor.visit_ty(impl_hir_ty);
types_to_skip.extend(visitor.types_to_skip);

View file

@ -1627,7 +1627,7 @@ pub fn is_slice_of_primitives(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<S
if is_primitive {
// if we have wrappers like Array, Slice or Tuple, print these
// and get the type enclosed in the slice ref
match expr_type.peel_refs().walk().nth(1).unwrap().expect_ty().kind() {
match expr_type.peel_refs().walk(cx.tcx).nth(1).unwrap().expect_ty().kind() {
rustc_ty::Slice(..) => return Some("slice".into()),
rustc_ty::Array(..) => return Some("array".into()),
rustc_ty::Tuple(..) => return Some("tuple".into()),
@ -1635,7 +1635,7 @@ pub fn is_slice_of_primitives(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<S
// is_recursively_primitive_type() should have taken care
// of the rest and we can rely on the type that is found
let refs_peeled = expr_type.peel_refs();
return Some(refs_peeled.walk().last().unwrap().to_string());
return Some(refs_peeled.walk(cx.tcx).last().unwrap().to_string());
},
}
}

View file

@ -88,7 +88,7 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, msrv: Option<&Ru
}
fn check_ty(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) -> McfResult {
for arg in ty.walk() {
for arg in ty.walk(tcx) {
let ty = match arg.unpack() {
GenericArgKind::Type(ty) => ty,

View file

@ -10,7 +10,7 @@ use rustc_hir::{TyKind, Unsafety};
use rustc_infer::infer::TyCtxtInferExt;
use rustc_lint::LateContext;
use rustc_middle::ty::subst::{GenericArg, GenericArgKind};
use rustc_middle::ty::{self, AdtDef, IntTy, Ty, TypeFoldable, UintTy};
use rustc_middle::ty::{self, TyCtxt, AdtDef, IntTy, Ty, TypeFoldable, UintTy};
use rustc_span::sym;
use rustc_span::symbol::{Ident, Symbol};
use rustc_span::DUMMY_SP;
@ -36,8 +36,8 @@ pub fn can_partially_move_ty(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
}
/// Walks into `ty` and returns `true` if any inner type is the same as `other_ty`
pub fn contains_ty(ty: Ty<'_>, other_ty: Ty<'_>) -> bool {
ty.walk().any(|inner| match inner.unpack() {
pub fn contains_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, other_ty: Ty<'tcx>) -> bool {
ty.walk(tcx).any(|inner| match inner.unpack() {
GenericArgKind::Type(inner_ty) => ty::TyS::same_type(other_ty, inner_ty),
GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false,
})
@ -45,8 +45,8 @@ pub fn contains_ty(ty: Ty<'_>, other_ty: Ty<'_>) -> bool {
/// Walks into `ty` and returns `true` if any inner type is an instance of the given adt
/// constructor.
pub fn contains_adt_constructor(ty: Ty<'_>, adt: &AdtDef) -> bool {
ty.walk().any(|inner| match inner.unpack() {
pub fn contains_adt_constructor<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, adt: &'tcx AdtDef) -> bool {
ty.walk(tcx).any(|inner| match inner.unpack() {
GenericArgKind::Type(inner_ty) => inner_ty.ty_adt_def() == Some(adt),
GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false,
})
@ -209,7 +209,7 @@ fn is_normalizable_helper<'tcx>(
.iter()
.all(|field| is_normalizable_helper(cx, param_env, field.ty(cx.tcx, substs), cache))
}),
_ => ty.walk().all(|generic_arg| match generic_arg.unpack() {
_ => ty.walk(cx.tcx).all(|generic_arg| match generic_arg.unpack() {
GenericArgKind::Type(inner_ty) if inner_ty != ty => {
is_normalizable_helper(cx, param_env, inner_ty, cache)
},