Skip to content

Commit 75d73e9

Browse files
committed
Auto merge of #6976 - Jarcho:manual_map_const, r=phansch
Don't lint `manual_map` in const functions fixes: #6967 changelog: Don't lint `manual_map` in const functions
2 parents 8cf7d9b + cc7f1da commit 75d73e9

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

clippy_lints/src/manual_map.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{map_unit_fn::OPTION_MAP_UNIT_FN, matches::MATCH_AS_REF};
22
use clippy_utils::diagnostics::span_lint_and_sugg;
33
use clippy_utils::source::{snippet_with_applicability, snippet_with_context};
44
use clippy_utils::ty::{can_partially_move_ty, is_type_diagnostic_item, peel_mid_ty_refs_is_mutable};
5-
use clippy_utils::{is_allowed, is_else_clause, match_def_path, match_var, paths, peel_hir_expr_refs};
5+
use clippy_utils::{in_constant, is_allowed, is_else_clause, match_def_path, match_var, paths, peel_hir_expr_refs};
66
use rustc_ast::util::parser::PREC_POSTFIX;
77
use rustc_errors::Applicability;
88
use rustc_hir::{
@@ -47,16 +47,16 @@ declare_lint_pass!(ManualMap => [MANUAL_MAP]);
4747
impl LateLintPass<'_> for ManualMap {
4848
#[allow(clippy::too_many_lines)]
4949
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
50-
if in_external_macro(cx.sess(), expr.span) {
51-
return;
52-
}
53-
5450
if let ExprKind::Match(
5551
scrutinee,
5652
[arm1 @ Arm { guard: None, .. }, arm2 @ Arm { guard: None, .. }],
5753
match_kind,
5854
) = expr.kind
5955
{
56+
if in_external_macro(cx.sess(), expr.span) || in_constant(cx, expr.hir_id) {
57+
return;
58+
}
59+
6060
let (scrutinee_ty, ty_ref_count, ty_mutability) =
6161
peel_mid_ty_refs_is_mutable(cx.typeck_results().expr_ty(scrutinee));
6262
if !(is_type_diagnostic_item(cx, scrutinee_ty, sym::option_type)

tests/ui/manual_map_option.fixed

+8
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,12 @@ fn main() {
138138
if true {
139139
Some(0)
140140
} else { Some(0).map(|x| x + 1) };
141+
142+
// #6967
143+
const fn f4() {
144+
match Some(0) {
145+
Some(x) => Some(x + 1),
146+
None => None,
147+
};
148+
}
141149
}

tests/ui/manual_map_option.rs

+8
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,12 @@ fn main() {
204204
} else {
205205
None
206206
};
207+
208+
// #6967
209+
const fn f4() {
210+
match Some(0) {
211+
Some(x) => Some(x + 1),
212+
None => None,
213+
};
214+
}
207215
}

0 commit comments

Comments
 (0)