add tcx to fn walk

This commit is contained in:
lcnr 2021-07-17 16:43:23 +02:00
parent bfaf13af4e
commit cc47998e28
29 changed files with 73 additions and 67 deletions

View file

@ -51,7 +51,7 @@ impl<'a, 'tcx> FindHirNodeVisitor<'a, 'tcx> {
fn node_ty_contains_target(&self, hir_id: HirId) -> Option<Ty<'tcx>> {
self.node_type_opt(hir_id).map(|ty| self.infcx.resolve_vars_if_possible(ty)).filter(|ty| {
ty.walk().any(|inner| {
ty.walk(self.infcx.tcx).any(|inner| {
inner == self.target
|| match (inner.unpack(), self.target.unpack()) {
(GenericArgKind::Type(inner_ty), GenericArgKind::Type(target_ty)) => {

View file

@ -189,7 +189,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
visited: &mut SsoHashSet<GenericArg<'tcx>>,
) -> VerifyBound<'tcx> {
let mut bounds = parent
.walk_shallow(visited)
.walk_shallow(self.tcx, visited)
.filter_map(|child| match child.unpack() {
GenericArgKind::Type(ty) => Some(self.type_bound(ty, visited)),
GenericArgKind::Lifetime(lt) => {

View file

@ -152,8 +152,8 @@ declare_lint! {
declare_lint_pass!(BoxPointers => [BOX_POINTERS]);
impl BoxPointers {
fn check_heap_type(&self, cx: &LateContext<'_>, span: Span, ty: Ty<'_>) {
for leaf in ty.walk() {
fn check_heap_type<'tcx>(&self, cx: &LateContext<'tcx>, span: Span, ty: Ty<'tcx>) {
for leaf in ty.walk(cx.tcx) {
if let GenericArgKind::Type(leaf_ty) = leaf.unpack() {
if leaf_ty.is_box() {
cx.struct_span_lint(BOX_POINTERS, span, |lint| {

View file

@ -194,7 +194,7 @@ fn compute_components_recursive(
out: &mut SmallVec<[Component<'tcx>; 4]>,
visited: &mut SsoHashSet<GenericArg<'tcx>>,
) {
for child in parent.walk_shallow(visited) {
for child in parent.walk_shallow(tcx, visited) {
match child.unpack() {
GenericArgKind::Type(ty) => {
compute_components(tcx, ty, out, visited);

View file

@ -1,8 +1,8 @@
//! An iterator over the type substructure.
//! WARNING: this does not keep track of the region depth.
use crate::ty;
use crate::ty::subst::{GenericArg, GenericArgKind};
use crate::ty::{self, TyCtxt};
use rustc_data_structures::sso::SsoHashSet;
use smallvec::{self, SmallVec};
@ -11,6 +11,7 @@ use smallvec::{self, SmallVec};
type TypeWalkerStack<'tcx> = SmallVec<[GenericArg<'tcx>; 8]>;
pub struct TypeWalker<'tcx> {
tcx: TyCtxt<'tcx>,
stack: TypeWalkerStack<'tcx>,
last_subtree: usize,
pub visited: SsoHashSet<GenericArg<'tcx>>,
@ -25,8 +26,8 @@ pub struct TypeWalker<'tcx> {
/// It maintains a set of visited types and
/// skips any types that are already there.
impl<'tcx> TypeWalker<'tcx> {
pub fn new(root: GenericArg<'tcx>) -> Self {
Self { stack: smallvec![root], last_subtree: 1, visited: SsoHashSet::new() }
fn new(tcx: TyCtxt<'tcx>, root: GenericArg<'tcx>) -> Self {
Self { tcx, stack: smallvec![root], last_subtree: 1, visited: SsoHashSet::new() }
}
/// Skips the subtree corresponding to the last type
@ -55,7 +56,7 @@ impl<'tcx> Iterator for TypeWalker<'tcx> {
let next = self.stack.pop()?;
self.last_subtree = self.stack.len();
if self.visited.insert(next) {
push_inner(&mut self.stack, next);
push_inner(self.tcx, &mut self.stack, next);
debug!("next: stack={:?}", self.stack);
return Some(next);
}
@ -74,8 +75,8 @@ impl GenericArg<'tcx> {
/// Foo<Bar<isize>> => { Foo<Bar<isize>>, Bar<isize>, isize }
/// [isize] => { [isize], isize }
/// ```
pub fn walk(self) -> TypeWalker<'tcx> {
TypeWalker::new(self)
pub fn walk(self, tcx: TyCtxt<'tcx>) -> TypeWalker<'tcx> {
TypeWalker::new(tcx, self)
}
/// Iterator that walks the immediate children of `self`. Hence
@ -87,10 +88,11 @@ impl GenericArg<'tcx> {
/// and skips any types that are already there.
pub fn walk_shallow(
self,
tcx: TyCtxt<'tcx>,
visited: &mut SsoHashSet<GenericArg<'tcx>>,
) -> impl Iterator<Item = GenericArg<'tcx>> {
let mut stack = SmallVec::new();
push_inner(&mut stack, self);
push_inner(tcx, &mut stack, self);
stack.retain(|a| visited.insert(*a));
stack.into_iter()
}
@ -107,18 +109,22 @@ impl<'tcx> super::TyS<'tcx> {
/// Foo<Bar<isize>> => { Foo<Bar<isize>>, Bar<isize>, isize }
/// [isize] => { [isize], isize }
/// ```
pub fn walk(&'tcx self) -> TypeWalker<'tcx> {
TypeWalker::new(self.into())
pub fn walk(&'tcx self, tcx: TyCtxt<'tcx>) -> TypeWalker<'tcx> {
TypeWalker::new(tcx, self.into())
}
}
// We push `GenericArg`s on the stack in reverse order so as to
// maintain a pre-order traversal. As of the time of this
// writing, the fact that the traversal is pre-order is not
// known to be significant to any code, but it seems like the
// natural order one would expect (basically, the order of the
// types as they are written).
fn push_inner<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>) {
/// We push `GenericArg`s on the stack in reverse order so as to
/// maintain a pre-order traversal. As of the time of this
/// writing, the fact that the traversal is pre-order is not
/// known to be significant to any code, but it seems like the
/// natural order one would expect (basically, the order of the
/// types as they are written).
fn push_inner<'tcx>(
tcx: TyCtxt<'tcx>,
stack: &mut TypeWalkerStack<'tcx>,
parent: GenericArg<'tcx>,
) {
match parent.unpack() {
GenericArgKind::Type(parent_ty) => match *parent_ty.kind() {
ty::Bool
@ -196,8 +202,7 @@ fn push_inner<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>)
| ty::ConstKind::Error(_) => {}
ty::ConstKind::Unevaluated(ct) => {
// TODO
stack.extend(ct.substs_.unwrap().iter().rev());
stack.extend(ct.substs(tcx).iter().rev());
}
}
}

View file

@ -573,7 +573,7 @@ fn check_type_length_limit<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) {
let type_length = instance
.substs
.iter()
.flat_map(|arg| arg.walk())
.flat_map(|arg| arg.walk(tcx))
.filter(|arg| match arg.unpack() {
GenericArgKind::Type(_) | GenericArgKind::Const(_) => true,
GenericArgKind::Lifetime(_) => false,

View file

@ -365,7 +365,7 @@ impl Checker<'mir, 'tcx> {
fn check_local_or_return_ty(&mut self, ty: Ty<'tcx>, local: Local) {
let kind = self.body.local_kind(local);
for ty in ty.walk() {
for ty in ty.walk(self.tcx) {
let ty = match ty.unpack() {
GenericArgKind::Type(ty) => ty,

View file

@ -49,7 +49,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FunctionItemRefChecker<'a, 'tcx> {
// Handle calls to `transmute`
if self.tcx.is_diagnostic_item(sym::transmute, def_id) {
let arg_ty = args[0].ty(self.body, self.tcx);
for generic_inner_ty in arg_ty.walk() {
for generic_inner_ty in arg_ty.walk(self.tcx) {
if let GenericArgKind::Type(inner_ty) = generic_inner_ty.unpack() {
if let Some((fn_id, fn_substs)) =
FunctionItemRefChecker::is_fn_ref(inner_ty)
@ -110,7 +110,7 @@ impl<'a, 'tcx> FunctionItemRefChecker<'a, 'tcx> {
let arg_defs = self.tcx.fn_sig(def_id).skip_binder().inputs();
for (arg_num, arg_def) in arg_defs.iter().enumerate() {
// For all types reachable from the argument type in the fn sig
for generic_inner_ty in arg_def.walk() {
for generic_inner_ty in arg_def.walk(self.tcx) {
if let GenericArgKind::Type(inner_ty) = generic_inner_ty.unpack() {
// If the inner type matches the type bound by `Pointer`
if TyS::same_type(inner_ty, bound_ty) {

View file

@ -237,7 +237,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
// code at the moment, because types like `for <'a> fn(&'a ())` do
// not *yet* implement `PartialEq`. So for now we leave this here.
has_impl
|| ty.walk().any(|t| match t.unpack() {
|| ty.walk(self.tcx()).any(|t| match t.unpack() {
ty::subst::GenericArgKind::Lifetime(_) => false,
ty::subst::GenericArgKind::Type(t) => t.is_fn_ptr(),
ty::subst::GenericArgKind::Const(_) => false,

View file

@ -767,14 +767,15 @@ fn substs_infer_vars<'a, 'tcx>(
selcx: &mut SelectionContext<'a, 'tcx>,
substs: ty::Binder<'tcx, SubstsRef<'tcx>>,
) -> impl Iterator<Item = TyOrConstInferVar<'tcx>> {
let tcx = selcx.tcx();
selcx
.infcx()
.resolve_vars_if_possible(substs)
.skip_binder() // ok because this check doesn't care about regions
.iter()
.filter(|arg| arg.has_infer_types_or_consts())
.flat_map(|arg| {
let mut walker = arg.walk();
.flat_map(move |arg| {
let mut walker = arg.walk(tcx);
while let Some(c) = walker.next() {
if !c.has_infer_types_or_consts() {
walker.visited.remove(&c);

View file

@ -278,7 +278,7 @@ fn predicate_references_self(
(predicate, sp): (ty::Predicate<'tcx>, Span),
) -> Option<Span> {
let self_ty = tcx.types.self_param;
let has_self_ty = |arg: &GenericArg<'_>| arg.walk().any(|arg| arg == self_ty.into());
let has_self_ty = |arg: &GenericArg<'tcx>| arg.walk(tcx).any(|arg| arg == self_ty.into());
match predicate.kind().skip_binder() {
ty::PredicateKind::Trait(ref data) => {
// In the case of a trait predicate, we can skip the "self" type.

View file

@ -947,7 +947,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let mut unsizing_params = GrowableBitSet::new_empty();
if tcx.features().relaxed_struct_unsize {
for arg in tail_field_ty.walk() {
for arg in tail_field_ty.walk(tcx) {
if let Some(i) = maybe_unsizing_param_idx(arg) {
unsizing_params.insert(i);
}
@ -956,7 +956,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// Ensure none of the other fields mention the parameters used
// in unsizing.
for field in prefix_fields {
for arg in tcx.type_of(field.did).walk() {
for arg in tcx.type_of(field.did).walk(tcx) {
if let Some(i) = maybe_unsizing_param_idx(arg) {
unsizing_params.remove(i);
}
@ -968,7 +968,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}
} else {
let mut found = false;
for arg in tail_field_ty.walk() {
for arg in tail_field_ty.walk(tcx) {
if let Some(i) = maybe_unsizing_param_idx(arg) {
unsizing_params.insert(i);
found = true;
@ -984,7 +984,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// by putting it in a query; it would only need the `DefId` as it
// looks at declared field types, not anything substituted.
for field in prefix_fields {
for arg in tcx.type_of(field.did).walk() {
for arg in tcx.type_of(field.did).walk(tcx) {
if let Some(i) = maybe_unsizing_param_idx(arg) {
if unsizing_params.contains(i) {
return Err(Unimplemented);

View file

@ -422,7 +422,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
/// Pushes all the predicates needed to validate that `ty` is WF into `out`.
fn compute(&mut self, arg: GenericArg<'tcx>) {
let mut walker = arg.walk();
let mut walker = arg.walk(self.tcx());
let param_env = self.param_env;
let depth = self.recursion_depth;
while let Some(arg) = walker.next() {

View file

@ -361,7 +361,7 @@ fn well_formed_types_in_env<'tcx>(
// constituents are well-formed.
NodeKind::InherentImpl => {
let self_ty = tcx.type_of(def_id);
inputs.extend(self_ty.walk());
inputs.extend(self_ty.walk(tcx));
}
// In an fn, we assume that the arguments and all their constituents are
@ -370,7 +370,7 @@ fn well_formed_types_in_env<'tcx>(
let fn_sig = tcx.fn_sig(def_id);
let fn_sig = tcx.liberate_late_bound_regions(def_id, fn_sig);
inputs.extend(fn_sig.inputs().iter().flat_map(|ty| ty.walk()));
inputs.extend(fn_sig.inputs().iter().flat_map(|ty| ty.walk(tcx)));
}
NodeKind::Other => (),

View file

@ -394,7 +394,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
if self.is_object && has_default {
let default_ty = tcx.at(self.span).type_of(param.def_id);
let self_param = tcx.types.self_param;
if default_ty.walk().any(|arg| arg == self_param.into()) {
if default_ty.walk(tcx).any(|arg| arg == self_param.into()) {
// There is no suitable inference default for a type parameter
// that references self, in an object type.
return true;
@ -1354,7 +1354,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// A `Self` within the original bound will be substituted with a
// `trait_object_dummy_self`, so check for that.
let references_self =
pred.skip_binder().ty.walk().any(|arg| arg == dummy_self.into());
pred.skip_binder().ty.walk(tcx).any(|arg| arg == dummy_self.into());
// If the projection output contains `Self`, force the user to
// elaborate it explicitly to avoid a lot of complexity.

View file

@ -1482,7 +1482,7 @@ pub(super) fn check_type_params_are_used<'tcx>(
return;
}
for leaf in ty.walk() {
for leaf in ty.walk(tcx) {
if let GenericArgKind::Type(leaf_ty) = leaf.unpack() {
if let ty::Param(param) = leaf_ty.kind() {
debug!("found use of ty param {:?}", param);

View file

@ -937,7 +937,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let ty = self.resolve_vars_if_possible(ty);
// We walk the argument type because the argument's type could have
// been `Option<T>`, but the `FulfillmentError` references `T`.
if ty.walk().any(|arg| arg == predicate.self_ty().into()) {
if ty.walk(self.tcx).any(|arg| arg == predicate.self_ty().into()) {
Some(i)
} else {
None

View file

@ -114,7 +114,7 @@ fn insert_required_predicates_to_be_wf<'tcx>(
required_predicates: &mut RequiredPredicates<'tcx>,
explicit_map: &mut ExplicitPredicatesMap<'tcx>,
) {
for arg in field_ty.walk() {
for arg in field_ty.walk(tcx) {
let ty = match arg.unpack() {
GenericArgKind::Type(ty) => ty,
@ -306,7 +306,7 @@ pub fn check_explicit_predicates<'tcx>(
// 'b`.
if let Some(self_ty) = ignored_self_ty {
if let GenericArgKind::Type(ty) = outlives_predicate.0.unpack() {
if ty.walk().any(|arg| arg == self_ty.into()) {
if ty.walk(tcx).any(|arg| arg == self_ty.into()) {
debug!("skipping self ty = {:?}", &ty);
continue;
}

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)
},