Skip to content

Commit

Permalink
use TyS::walk
Browse files Browse the repository at this point in the history
  • Loading branch information
anall committed Mar 9, 2021
1 parent b27cbda commit e322c77
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
19 changes: 8 additions & 11 deletions clippy_utils/src/lib.rs
Expand Up @@ -1504,26 +1504,23 @@ fn is_normalizable_helper<'tcx>(
cache.insert(ty, false); // prevent recursive loops
let result = cx.tcx.infer_ctxt().enter(|infcx| {
let cause = rustc_middle::traits::ObligationCause::dummy();
if infcx.at(&cause, param_env).normalize(ty).is_err() {
false
} else {
if infcx.at(&cause, param_env).normalize(ty).is_ok() {
match ty.kind() {
ty::Adt(def, substs) => !def.variants.iter().any(|variant| {
variant
.fields
.iter()
.any(|field| !is_normalizable_helper(cx, param_env, field.ty(cx.tcx, substs), cache))
}),
ty::Ref(_, pointee, _) | ty::RawPtr(ty::TypeAndMut { ty: pointee, .. }) => {
is_normalizable_helper(cx, param_env, pointee, cache)
},
ty::Array(inner_ty, _) | ty::Slice(inner_ty) => is_normalizable_helper(cx, param_env, inner_ty, cache),
ty::Tuple(tys) => !tys.iter().any(|inner| match inner.unpack() {
GenericArgKind::Type(inner_ty) => !is_normalizable_helper(cx, param_env, inner_ty, cache),
_ => false,
_ => !ty.walk().any(|generic_arg| !match generic_arg.unpack() {
GenericArgKind::Type(inner_ty) if inner_ty != ty => {
is_normalizable_helper(cx, param_env, inner_ty, cache)
},
_ => true, // if inner_ty == ty, we've already checked it
}),
_ => true,
}
} else {
false
}
});
cache.insert(ty, result);
Expand Down
10 changes: 9 additions & 1 deletion tests/ui/crashes/ice-6840.rs
Expand Up @@ -13,11 +13,19 @@ pub struct RuleEdges<R: Rule> {

type RuleDependencyEdges<R> = HashMap<u32, RuleEdges<R>>;

// and additional potential variants
// reproducer from the GitHub issue ends here
// but check some additional variants
type RuleDependencyEdgesArray<R> = HashMap<u32, [RuleEdges<R>; 8]>;
type RuleDependencyEdgesSlice<R> = HashMap<u32, &'static [RuleEdges<R>]>;
type RuleDependencyEdgesRef<R> = HashMap<u32, &'static RuleEdges<R>>;
type RuleDependencyEdgesRaw<R> = HashMap<u32, *const RuleEdges<R>>;
type RuleDependencyEdgesTuple<R> = HashMap<u32, (RuleEdges<R>, RuleEdges<R>)>;

// and an additional checks to make sure fix doesn't have stack-overflow issue
// on self-containing types
pub struct SelfContaining {
inner: Box<SelfContaining>,
}
type SelfContainingEdges = HashMap<u32, SelfContaining>;

fn main() {}

0 comments on commit e322c77

Please sign in to comment.