Skip to content

Commit 70e70de

Browse files
Update clippy to use speculative const-checking
Also removes some checks that were overzealous.
1 parent 8095303 commit 70e70de

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

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

+4-20
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
use crate::utils::{fn_has_unsatisfiable_preds, has_drop, is_entrypoint_fn, span_lint, trait_ref_of_method};
1+
use crate::utils::{fn_has_unsatisfiable_preds, is_entrypoint_fn, span_lint, trait_ref_of_method};
22
use rustc_hir as hir;
33
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_mir::transform::qualify_min_const_fn::is_min_const_fn;
7+
use rustc_middle::ty::WithOptConstParam;
88
use rustc_session::{declare_lint_pass, declare_tool_lint};
99
use rustc_span::Span;
10-
use rustc_typeck::hir_ty_to_ty;
1110

1211
declare_clippy_lint! {
1312
/// **What it does:**
@@ -108,36 +107,21 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn {
108107
FnKind::Method(_, sig, ..) => {
109108
if trait_ref_of_method(cx, hir_id).is_some()
110109
|| already_const(sig.header)
111-
|| method_accepts_dropable(cx, sig.decl.inputs)
112110
{
113111
return;
114112
}
115113
},
116114
FnKind::Closure(..) => return,
117115
}
118116

119-
let mir = cx.tcx.optimized_mir(def_id);
117+
let mir = cx.tcx.mir_const(WithOptConstParam::unknown(def_id)).borrow();
120118

121-
if let Err((span, err)) = is_min_const_fn(cx.tcx, def_id.to_def_id(), &mir) {
122-
if rustc_mir::const_eval::is_min_const_fn(cx.tcx, def_id.to_def_id()) {
123-
cx.tcx.sess.span_err(span, &err);
124-
}
125-
} else {
119+
if rustc_mir::transform::check_consts::non_const_fn_could_be_made_stable_const_fn(cx.tcx, def_id, &mir) {
126120
span_lint(cx, MISSING_CONST_FOR_FN, span, "this could be a `const fn`");
127121
}
128122
}
129123
}
130124

131-
/// Returns true if any of the method parameters is a type that implements `Drop`. The method
132-
/// can't be made const then, because `drop` can't be const-evaluated.
133-
fn method_accepts_dropable(cx: &LateContext<'_>, param_tys: &[hir::Ty<'_>]) -> bool {
134-
// If any of the params are droppable, return true
135-
param_tys.iter().any(|hir_ty| {
136-
let ty_ty = hir_ty_to_ty(cx.tcx, hir_ty);
137-
has_drop(cx, ty_ty)
138-
})
139-
}
140-
141125
// We don't have to lint on something that's already `const`
142126
#[must_use]
143127
fn already_const(header: hir::FnHeader) -> bool {

0 commit comments

Comments
 (0)