Skip to content

Commit 6e12c54

Browse files
committed
fix(len_zero): don't eagerly call GenericArgs::type_at
Results in an ICE if the output type has no generic type params
1 parent ec73197 commit 6e12c54

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

clippy_lints/src/len_zero.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,9 @@ fn parse_len_output<'tcx>(cx: &LateContext<'tcx>, sig: FnSig<'tcx>) -> Option<Le
371371

372372
match *sig.output().kind() {
373373
ty::Int(_) | ty::Uint(_) => Some(LenOutput::Integral),
374-
ty::Adt(adt, subs) if subs.type_at(0).is_integral() => match cx.tcx.get_diagnostic_name(adt.did()) {
375-
Some(sym::Option) => Some(LenOutput::Option(adt.did())),
376-
Some(sym::Result) => Some(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())),
377377
_ => None,
378378
},
379379
_ => None,

tests/ui/crashes/ice-15657.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@check-pass
2+
#![warn(clippy::len_zero)]
3+
4+
pub struct S1;
5+
pub struct S2;
6+
7+
impl S1 {
8+
pub fn len(&self) -> S2 {
9+
S2
10+
}
11+
}

0 commit comments

Comments
 (0)