|
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}; |
2 | 2 | use rustc_hir as hir;
|
3 | 3 | use rustc_hir::intravisit::FnKind;
|
4 | 4 | use rustc_hir::{Body, Constness, FnDecl, GenericParamKind, HirId};
|
5 | 5 | use rustc_lint::{LateContext, LateLintPass};
|
6 | 6 | 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; |
8 | 8 | use rustc_session::{declare_lint_pass, declare_tool_lint};
|
9 | 9 | use rustc_span::Span;
|
10 |
| -use rustc_typeck::hir_ty_to_ty; |
11 | 10 |
|
12 | 11 | declare_clippy_lint! {
|
13 | 12 | /// **What it does:**
|
@@ -108,36 +107,21 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn {
|
108 | 107 | FnKind::Method(_, sig, ..) => {
|
109 | 108 | if trait_ref_of_method(cx, hir_id).is_some()
|
110 | 109 | || already_const(sig.header)
|
111 |
| - || method_accepts_dropable(cx, sig.decl.inputs) |
112 | 110 | {
|
113 | 111 | return;
|
114 | 112 | }
|
115 | 113 | },
|
116 | 114 | FnKind::Closure(..) => return,
|
117 | 115 | }
|
118 | 116 |
|
119 |
| - let mir = cx.tcx.optimized_mir(def_id); |
| 117 | + let mir = cx.tcx.mir_const(WithOptConstParam::unknown(def_id)).borrow(); |
120 | 118 |
|
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) { |
126 | 120 | span_lint(cx, MISSING_CONST_FOR_FN, span, "this could be a `const fn`");
|
127 | 121 | }
|
128 | 122 | }
|
129 | 123 | }
|
130 | 124 |
|
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 |
| - |
141 | 125 | // We don't have to lint on something that's already `const`
|
142 | 126 | #[must_use]
|
143 | 127 | fn already_const(header: hir::FnHeader) -> bool {
|
|
0 commit comments