Possibly fix an ICE on test

This commit is contained in:
Yuki Okushi 2019-12-28 21:13:21 +09:00
parent 0fec5905d8
commit fbdb13cfb0

View file

@ -103,18 +103,23 @@ fn check_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, span: Span, ty: Ty<'tcx>) {
.iter()
.any(|path| match_def_path(cx, def.did, &**path))
{
let key_type = substs.type_at(0);
if is_concrete_type(key_type) && !key_type.is_freeze(cx.tcx, cx.param_env, span) {
span_lint(cx, MUTABLE_KEY_TYPE, span, "mutable key type");
let key_type = concrete_type(Some(substs.type_at(0)));
if let Some(key_type) = key_type {
if !key_type.is_freeze(cx.tcx, cx.param_env, span) {
span_lint(cx, MUTABLE_KEY_TYPE, span, "mutable key type");
}
}
}
}
}
fn is_concrete_type(ty: Ty<'_>) -> bool {
match ty.kind {
RawPtr(TypeAndMut { ty: inner_ty, .. }) | Ref(_, inner_ty, _) => is_concrete_type(inner_ty),
Dynamic(..) | Opaque(..) | Param(..) => false,
_ => true,
fn concrete_type(ty: Option<Ty<'_>>) -> Option<Ty<'_>> {
if let Some(ty) = ty {
match ty.kind {
RawPtr(TypeAndMut { ty: inner_ty, .. }) | Ref(_, inner_ty, _) => return concrete_type(Some(inner_ty)),
Dynamic(..) | Opaque(..) | Param(..) => return None,
_ => return Some(ty),
}
}
None
}