Skip to content

Commit 34b821f

Browse files
Run const-checking on optimized MIR in clippy
1 parent 70e70de commit 34b821f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use rustc_hir::intravisit::FnKind;
44
use rustc_hir::{Body, Constness, FnDecl, GenericParamKind, HirId};
55
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_middle::lint::in_external_macro;
7-
use rustc_middle::ty::WithOptConstParam;
87
use rustc_session::{declare_lint_pass, declare_tool_lint};
98
use rustc_span::Span;
109

@@ -114,7 +113,10 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn {
114113
FnKind::Closure(..) => return,
115114
}
116115

117-
let mir = cx.tcx.mir_const(WithOptConstParam::unknown(def_id)).borrow();
116+
117+
// FIXME(#6080): Const-checking is only guaranteed to be correct when run on unoptimized MIR.
118+
// This needs to be changed to `mir_const`.
119+
let mir = cx.tcx.optimized_mir(def_id);
118120

119121
if rustc_mir::transform::check_consts::non_const_fn_could_be_made_stable_const_fn(cx.tcx, def_id, &mir) {
120122
span_lint(cx, MISSING_CONST_FOR_FN, span, "this could be a `const fn`");

0 commit comments

Comments
 (0)