Skip to content

Commit fbdb13c

Browse files
committed
Possibly fix an ICE on test
1 parent 0fec590 commit fbdb13c

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

clippy_lints/src/mut_key.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,23 @@ fn check_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, span: Span, ty: Ty<'tcx>) {
103103
.iter()
104104
.any(|path| match_def_path(cx, def.did, &**path))
105105
{
106-
let key_type = substs.type_at(0);
107-
if is_concrete_type(key_type) && !key_type.is_freeze(cx.tcx, cx.param_env, span) {
108-
span_lint(cx, MUTABLE_KEY_TYPE, span, "mutable key type");
106+
let key_type = concrete_type(Some(substs.type_at(0)));
107+
if let Some(key_type) = key_type {
108+
if !key_type.is_freeze(cx.tcx, cx.param_env, span) {
109+
span_lint(cx, MUTABLE_KEY_TYPE, span, "mutable key type");
110+
}
109111
}
110112
}
111113
}
112114
}
113115

114-
fn is_concrete_type(ty: Ty<'_>) -> bool {
115-
match ty.kind {
116-
RawPtr(TypeAndMut { ty: inner_ty, .. }) | Ref(_, inner_ty, _) => is_concrete_type(inner_ty),
117-
Dynamic(..) | Opaque(..) | Param(..) => false,
118-
_ => true,
116+
fn concrete_type(ty: Option<Ty<'_>>) -> Option<Ty<'_>> {
117+
if let Some(ty) = ty {
118+
match ty.kind {
119+
RawPtr(TypeAndMut { ty: inner_ty, .. }) | Ref(_, inner_ty, _) => return concrete_type(Some(inner_ty)),
120+
Dynamic(..) | Opaque(..) | Param(..) => return None,
121+
_ => return Some(ty),
122+
}
119123
}
124+
None
120125
}

0 commit comments

Comments
 (0)