Skip to content

Commit c91801a

Browse files
committed
len_zero: use get_diagnostic_name
1 parent dca603c commit c91801a

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

clippy_lints/src/len_zero.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -355,24 +355,26 @@ fn parse_len_output<'tcx>(cx: &LateContext<'tcx>, sig: FnSig<'tcx>) -> Option<Le
355355
return Some(LenOutput::Integral);
356356
}
357357

358-
if let Res::Def(_, def_id) = res {
359-
if cx.tcx.is_diagnostic_item(sym::Option, def_id) && is_first_generic_integral(segment) {
360-
return Some(LenOutput::Option(def_id));
361-
} else if cx.tcx.is_diagnostic_item(sym::Result, def_id) && is_first_generic_integral(segment) {
362-
return Some(LenOutput::Result(def_id));
358+
if let Res::Def(_, def_id) = res
359+
&& let Some(res) = match cx.tcx.get_diagnostic_name(def_id) {
360+
Some(sym::Option) => Some(LenOutput::Option(def_id)),
361+
Some(sym::Result) => Some(LenOutput::Result(def_id)),
362+
_ => None,
363363
}
364+
&& is_first_generic_integral(segment)
365+
{
366+
return Some(res);
364367
}
365368

366369
return None;
367370
}
368371

369372
match *sig.output().kind() {
370373
ty::Int(_) | ty::Uint(_) => Some(LenOutput::Integral),
371-
ty::Adt(adt, subs) if cx.tcx.is_diagnostic_item(sym::Option, adt.did()) => {
372-
subs.type_at(0).is_integral().then(|| LenOutput::Option(adt.did()))
373-
},
374-
ty::Adt(adt, subs) if cx.tcx.is_diagnostic_item(sym::Result, adt.did()) => {
375-
subs.type_at(0).is_integral().then(|| LenOutput::Result(adt.did()))
374+
ty::Adt(adt, subs) => match cx.tcx.get_diagnostic_name(adt.did()) {
375+
Some(sym::Option) => subs.type_at(0).is_integral().then(|| LenOutput::Option(adt.did())),
376+
Some(sym::Result) => subs.type_at(0).is_integral().then(|| LenOutput::Result(adt.did())),
377+
_ => None,
376378
},
377379
_ => None,
378380
}

0 commit comments

Comments
 (0)