mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-02 18:12:51 +00:00
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
This commit is contained in:
commit
75d73e95a0
@ -2,7 +2,7 @@ use crate::{map_unit_fn::OPTION_MAP_UNIT_FN, matches::MATCH_AS_REF};
|
|||||||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
use clippy_utils::diagnostics::span_lint_and_sugg;
|
||||||
use clippy_utils::source::{snippet_with_applicability, snippet_with_context};
|
use clippy_utils::source::{snippet_with_applicability, snippet_with_context};
|
||||||
use clippy_utils::ty::{can_partially_move_ty, is_type_diagnostic_item, peel_mid_ty_refs_is_mutable};
|
use clippy_utils::ty::{can_partially_move_ty, is_type_diagnostic_item, peel_mid_ty_refs_is_mutable};
|
||||||
use clippy_utils::{is_allowed, is_else_clause, match_def_path, match_var, paths, peel_hir_expr_refs};
|
use clippy_utils::{in_constant, is_allowed, is_else_clause, match_def_path, match_var, paths, peel_hir_expr_refs};
|
||||||
use rustc_ast::util::parser::PREC_POSTFIX;
|
use rustc_ast::util::parser::PREC_POSTFIX;
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir::{
|
use rustc_hir::{
|
||||||
@ -47,16 +47,16 @@ declare_lint_pass!(ManualMap => [MANUAL_MAP]);
|
|||||||
impl LateLintPass<'_> for ManualMap {
|
impl LateLintPass<'_> for ManualMap {
|
||||||
#[allow(clippy::too_many_lines)]
|
#[allow(clippy::too_many_lines)]
|
||||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
||||||
if in_external_macro(cx.sess(), expr.span) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let ExprKind::Match(
|
if let ExprKind::Match(
|
||||||
scrutinee,
|
scrutinee,
|
||||||
[arm1 @ Arm { guard: None, .. }, arm2 @ Arm { guard: None, .. }],
|
[arm1 @ Arm { guard: None, .. }, arm2 @ Arm { guard: None, .. }],
|
||||||
match_kind,
|
match_kind,
|
||||||
) = expr.kind
|
) = expr.kind
|
||||||
{
|
{
|
||||||
|
if in_external_macro(cx.sess(), expr.span) || in_constant(cx, expr.hir_id) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let (scrutinee_ty, ty_ref_count, ty_mutability) =
|
let (scrutinee_ty, ty_ref_count, ty_mutability) =
|
||||||
peel_mid_ty_refs_is_mutable(cx.typeck_results().expr_ty(scrutinee));
|
peel_mid_ty_refs_is_mutable(cx.typeck_results().expr_ty(scrutinee));
|
||||||
if !(is_type_diagnostic_item(cx, scrutinee_ty, sym::option_type)
|
if !(is_type_diagnostic_item(cx, scrutinee_ty, sym::option_type)
|
||||||
|
@ -138,4 +138,12 @@ fn main() {
|
|||||||
if true {
|
if true {
|
||||||
Some(0)
|
Some(0)
|
||||||
} else { Some(0).map(|x| x + 1) };
|
} else { Some(0).map(|x| x + 1) };
|
||||||
|
|
||||||
|
// #6967
|
||||||
|
const fn f4() {
|
||||||
|
match Some(0) {
|
||||||
|
Some(x) => Some(x + 1),
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -204,4 +204,12 @@ fn main() {
|
|||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// #6967
|
||||||
|
const fn f4() {
|
||||||
|
match Some(0) {
|
||||||
|
Some(x) => Some(x + 1),
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user