Skip to content

Commit 7f6d507

Browse files
authored
Fix ICE in missing_const_for_fn (#14776)
The `mir_drops_elaborated_and_const_checked` query result has been stolen already and cannot be borrowed again. Use the `optimized_mir` query result instead. changelog: [`missing_const_for_fn`]: fix ICE with some compilation options Fixes #14774 r? @Jarcho
2 parents f60807d + 9ed53b8 commit 7f6d507

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

clippy_lints/src/missing_const_for_fn.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn {
155155
return;
156156
}
157157

158-
let mir = cx.tcx.mir_drops_elaborated_and_const_checked(def_id);
158+
let mir = cx.tcx.optimized_mir(def_id);
159159

160-
if let Ok(()) = is_min_const_fn(cx, &mir.borrow(), self.msrv)
160+
if let Ok(()) = is_min_const_fn(cx, mir, self.msrv)
161161
&& let hir::Node::Item(hir::Item { vis_span, .. }) | hir::Node::ImplItem(hir::ImplItem { vis_span, .. }) =
162162
cx.tcx.hir_node_by_def_id(def_id)
163163
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@compile-flags: -Z validate-mir
2+
#![warn(clippy::missing_const_for_fn)]
3+
4+
static BLOCK_FN_DEF: fn(usize) -> usize = {
5+
//~v missing_const_for_fn
6+
const fn foo(a: usize) -> usize {
7+
a + 10
8+
}
9+
foo
10+
};
11+
struct X;
12+
13+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@compile-flags: -Z validate-mir
2+
#![warn(clippy::missing_const_for_fn)]
3+
4+
static BLOCK_FN_DEF: fn(usize) -> usize = {
5+
//~v missing_const_for_fn
6+
fn foo(a: usize) -> usize {
7+
a + 10
8+
}
9+
foo
10+
};
11+
struct X;
12+
13+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error: this could be a `const fn`
2+
--> tests/ui/crashes/missing_const_for_fn_14774.rs:6:5
3+
|
4+
LL | / fn foo(a: usize) -> usize {
5+
LL | | a + 10
6+
LL | | }
7+
| |_____^
8+
|
9+
= note: `-D clippy::missing-const-for-fn` implied by `-D warnings`
10+
= help: to override `-D warnings` add `#[allow(clippy::missing_const_for_fn)]`
11+
help: make the function `const`
12+
|
13+
LL | const fn foo(a: usize) -> usize {
14+
| +++++
15+
16+
error: aborting due to 1 previous error
17+

0 commit comments

Comments
 (0)