|
1 |
| -use crate::utils::{has_drop, is_entrypoint_fn, span_lint, trait_ref_of_method}; |
| 1 | +use crate::utils::{has_drop, is_entrypoint_fn, span_lint, trait_ref_of_method, return_ty}; |
2 | 2 | use rustc::declare_lint_pass;
|
3 | 3 | use rustc::hir;
|
4 | 4 | use rustc::hir::intravisit::FnKind;
|
@@ -91,14 +91,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingConstForFn {
|
91 | 91 | // can skip the actual const check and return early.
|
92 | 92 | match kind {
|
93 | 93 | FnKind::ItemFn(_, _, header, ..) => {
|
94 |
| - if already_const(header) { |
| 94 | + if already_const(header) |
| 95 | + || returns_dropable(cx, hir_id) |
| 96 | + { |
95 | 97 | return;
|
96 | 98 | }
|
97 | 99 | },
|
98 | 100 | FnKind::Method(_, sig, ..) => {
|
99 | 101 | if trait_ref_of_method(cx, hir_id).is_some()
|
100 | 102 | || already_const(sig.header)
|
101 | 103 | || method_accepts_dropable(cx, sig.decl.inputs)
|
| 104 | + || returns_dropable(cx, hir_id) |
102 | 105 | {
|
103 | 106 | return;
|
104 | 107 | }
|
@@ -128,6 +131,11 @@ fn method_accepts_dropable(cx: &LateContext<'_, '_>, param_tys: &[hir::Ty<'_>])
|
128 | 131 | })
|
129 | 132 | }
|
130 | 133 |
|
| 134 | +fn returns_dropable(cx: &LateContext<'_, '_>, ret_ty: hir::HirId) -> bool { |
| 135 | + let return_ty = return_ty(cx, ret_ty); |
| 136 | + has_drop(cx, return_ty) |
| 137 | +} |
| 138 | + |
131 | 139 | // We don't have to lint on something that's already `const`
|
132 | 140 | #[must_use]
|
133 | 141 | fn already_const(header: hir::FnHeader) -> bool {
|
|
0 commit comments