Skip to content

Commit 467efe0

Browse files
authored
fix(len_zero): don't eagerly call GenericArgs::type_at (rust-lang#15660)
Fixes rust-lang/rust-clippy#15657 changelog: [`len_zero`]: fix ICE when `fn len` has a return type without generic type params r? @y21
2 parents 990aaf6 + 6e12c54 commit 467efe0

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)