Skip to content

Commit 219d702

Browse files
committed
Auto merge of #8835 - Jarcho:let_unit_ice, r=llogiq
Fix ICE in `let_unit_value` when calling a static or const callable type fixes #8821 changelog: Fix ICE in `let_unit_value` when calling a static or const callable type
2 parents 6e86ab0 + c649d4e commit 219d702

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

clippy_lints/src/unit_types/let_unit_value.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use clippy_utils::source::snippet_with_macro_callsite;
33
use clippy_utils::visitors::for_each_value_source;
44
use core::ops::ControlFlow;
55
use rustc_errors::Applicability;
6+
use rustc_hir::def::{DefKind, Res};
67
use rustc_hir::{Expr, ExprKind, PatKind, Stmt, StmtKind};
78
use rustc_lint::{LateContext, LintContext};
89
use rustc_middle::lint::in_external_macro;
@@ -71,14 +72,18 @@ fn needs_inferred_result_ty(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
7172
..
7273
},
7374
_,
74-
) => cx.qpath_res(path, *hir_id).opt_def_id(),
75-
ExprKind::MethodCall(..) => cx.typeck_results().type_dependent_def_id(e.hir_id),
75+
) => match cx.qpath_res(path, *hir_id) {
76+
Res::Def(DefKind::AssocFn | DefKind::Fn, id) => id,
77+
_ => return false,
78+
},
79+
ExprKind::MethodCall(..) => match cx.typeck_results().type_dependent_def_id(e.hir_id) {
80+
Some(id) => id,
81+
None => return false,
82+
},
7683
_ => return false,
7784
};
78-
if let Some(id) = id
79-
&& let sig = cx.tcx.fn_sig(id).skip_binder()
80-
&& let ty::Param(output_ty) = *sig.output().kind()
81-
{
85+
let sig = cx.tcx.fn_sig(id).skip_binder();
86+
if let ty::Param(output_ty) = *sig.output().kind() {
8287
sig.inputs().iter().all(|&ty| !ty_contains_param(ty, output_ty.index))
8388
} else {
8489
false

tests/ui/crashes/ice-8821.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![warn(clippy::let_unit_value)]
2+
3+
fn f() {}
4+
static FN: fn() = f;
5+
6+
fn main() {
7+
let _: () = FN();
8+
}

tests/ui/crashes/ice-8821.stderr

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: this let-binding has unit value
2+
--> $DIR/ice-8821.rs:7:5
3+
|
4+
LL | let _: () = FN();
5+
| ^^^^^^^^^^^^^^^^^ help: omit the `let` binding: `FN();`
6+
|
7+
= note: `-D clippy::let-unit-value` implied by `-D warnings`
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)