Fix ICE in let_unit_value
when calling a static or const callable type
This commit is contained in:
parent
a1632fffc1
commit
c649d4e8a7
@ -3,6 +3,7 @@ use clippy_utils::source::snippet_with_macro_callsite;
|
||||
use clippy_utils::visitors::for_each_value_source;
|
||||
use core::ops::ControlFlow;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::{Expr, ExprKind, PatKind, Stmt, StmtKind};
|
||||
use rustc_lint::{LateContext, LintContext};
|
||||
use rustc_middle::lint::in_external_macro;
|
||||
@ -71,14 +72,18 @@ fn needs_inferred_result_ty(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
|
||||
..
|
||||
},
|
||||
_,
|
||||
) => cx.qpath_res(path, *hir_id).opt_def_id(),
|
||||
ExprKind::MethodCall(..) => cx.typeck_results().type_dependent_def_id(e.hir_id),
|
||||
) => match cx.qpath_res(path, *hir_id) {
|
||||
Res::Def(DefKind::AssocFn | DefKind::Fn, id) => id,
|
||||
_ => return false,
|
||||
},
|
||||
ExprKind::MethodCall(..) => match cx.typeck_results().type_dependent_def_id(e.hir_id) {
|
||||
Some(id) => id,
|
||||
None => return false,
|
||||
},
|
||||
_ => return false,
|
||||
};
|
||||
if let Some(id) = id
|
||||
&& let sig = cx.tcx.fn_sig(id).skip_binder()
|
||||
&& let ty::Param(output_ty) = *sig.output().kind()
|
||||
{
|
||||
let sig = cx.tcx.fn_sig(id).skip_binder();
|
||||
if let ty::Param(output_ty) = *sig.output().kind() {
|
||||
sig.inputs().iter().all(|&ty| !ty_contains_param(ty, output_ty.index))
|
||||
} else {
|
||||
false
|
||||
|
8
tests/ui/crashes/ice-8821.rs
Normal file
8
tests/ui/crashes/ice-8821.rs
Normal file
@ -0,0 +1,8 @@
|
||||
#![warn(clippy::let_unit_value)]
|
||||
|
||||
fn f() {}
|
||||
static FN: fn() = f;
|
||||
|
||||
fn main() {
|
||||
let _: () = FN();
|
||||
}
|
10
tests/ui/crashes/ice-8821.stderr
Normal file
10
tests/ui/crashes/ice-8821.stderr
Normal file
@ -0,0 +1,10 @@
|
||||
error: this let-binding has unit value
|
||||
--> $DIR/ice-8821.rs:7:5
|
||||
|
|
||||
LL | let _: () = FN();
|
||||
| ^^^^^^^^^^^^^^^^^ help: omit the `let` binding: `FN();`
|
||||
|
|
||||
= note: `-D clippy::let-unit-value` implied by `-D warnings`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
Loading…
x
Reference in New Issue
Block a user