Skip to content

Commit

Permalink
Auto merge of rust-lang#8835 - Jarcho:let_unit_ice, r=llogiq
Browse files Browse the repository at this point in the history
Fix ICE in `let_unit_value` when calling a static or const callable type

fixes rust-lang#8821

changelog: Fix ICE in `let_unit_value` when calling a static or const callable type
  • Loading branch information
bors committed May 16, 2022
2 parents 6e86ab0 + c649d4e commit 219d702
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
17 changes: 11 additions & 6 deletions clippy_lints/src/unit_types/let_unit_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/crashes/ice-8821.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![warn(clippy::let_unit_value)]

fn f() {}
static FN: fn() = f;

fn main() {
let _: () = FN();
}
10 changes: 10 additions & 0 deletions tests/ui/crashes/ice-8821.stderr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 219d702

Please sign in to comment.