Skip to content

Commit d4af90e

Browse files
committed
Merge commit '7c7683c8efe447b251d6c5ca6cce51233060f6e8' into clippyup
2 parents 1919b3f + 7c7683c commit d4af90e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+416
-326
lines changed

src/tools/clippy/clippy_lints/src/casts/ptr_as_ptr.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::borrow::Cow;
22

33
use clippy_utils::diagnostics::span_lint_and_sugg;
4-
use clippy_utils::meets_msrv;
54
use clippy_utils::sugg::Sugg;
5+
use clippy_utils::{meets_msrv, msrvs};
66
use if_chain::if_chain;
77
use rustc_errors::Applicability;
88
use rustc_hir::{Expr, ExprKind, Mutability, TyKind};
@@ -12,10 +12,8 @@ use rustc_semver::RustcVersion;
1212

1313
use super::PTR_AS_PTR;
1414

15-
const PTR_AS_PTR_MSRV: RustcVersion = RustcVersion::new(1, 38, 0);
16-
1715
pub(super) fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: &Option<RustcVersion>) {
18-
if !meets_msrv(msrv.as_ref(), &PTR_AS_PTR_MSRV) {
16+
if !meets_msrv(msrv.as_ref(), &msrvs::POINTER_CAST) {
1917
return;
2018
}
2119

src/tools/clippy/clippy_lints/src/checked_conversions.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use clippy_utils::diagnostics::span_lint_and_sugg;
44
use clippy_utils::source::snippet_with_applicability;
5-
use clippy_utils::{meets_msrv, SpanlessEq};
5+
use clippy_utils::{meets_msrv, msrvs, SpanlessEq};
66
use if_chain::if_chain;
77
use rustc_ast::ast::LitKind;
88
use rustc_errors::Applicability;
@@ -12,8 +12,6 @@ use rustc_middle::lint::in_external_macro;
1212
use rustc_semver::RustcVersion;
1313
use rustc_session::{declare_tool_lint, impl_lint_pass};
1414

15-
const CHECKED_CONVERSIONS_MSRV: RustcVersion = RustcVersion::new(1, 34, 0);
16-
1715
declare_clippy_lint! {
1816
/// **What it does:** Checks for explicit bounds checking when casting.
1917
///
@@ -58,7 +56,7 @@ impl_lint_pass!(CheckedConversions => [CHECKED_CONVERSIONS]);
5856

5957
impl<'tcx> LateLintPass<'tcx> for CheckedConversions {
6058
fn check_expr(&mut self, cx: &LateContext<'_>, item: &Expr<'_>) {
61-
if !meets_msrv(self.msrv.as_ref(), &CHECKED_CONVERSIONS_MSRV) {
59+
if !meets_msrv(self.msrv.as_ref(), &msrvs::TRY_FROM) {
6260
return;
6361
}
6462

src/tools/clippy/clippy_lints/src/from_over_into.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
22
use clippy_utils::paths::INTO;
3-
use clippy_utils::{match_def_path, meets_msrv};
3+
use clippy_utils::{match_def_path, meets_msrv, msrvs};
44
use if_chain::if_chain;
55
use rustc_hir as hir;
66
use rustc_lint::{LateContext, LateLintPass, LintContext};
77
use rustc_semver::RustcVersion;
88
use rustc_session::{declare_tool_lint, impl_lint_pass};
99

10-
const FROM_OVER_INTO_MSRV: RustcVersion = RustcVersion::new(1, 41, 0);
11-
1210
declare_clippy_lint! {
1311
/// **What it does:** Searches for implementations of the `Into<..>` trait and suggests to implement `From<..>` instead.
1412
///
@@ -57,7 +55,7 @@ impl_lint_pass!(FromOverInto => [FROM_OVER_INTO]);
5755

5856
impl LateLintPass<'_> for FromOverInto {
5957
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
60-
if !meets_msrv(self.msrv.as_ref(), &FROM_OVER_INTO_MSRV) {
58+
if !meets_msrv(self.msrv.as_ref(), &msrvs::RE_REBALANCING_COHERENCE) {
6159
return;
6260
}
6361

src/tools/clippy/clippy_lints/src/if_then_some_else_none.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
22
use clippy_utils::source::snippet_with_macro_callsite;
3-
use clippy_utils::{is_else_clause, is_lang_ctor, meets_msrv};
3+
use clippy_utils::{is_else_clause, is_lang_ctor, meets_msrv, msrvs};
44
use if_chain::if_chain;
55
use rustc_hir::LangItem::{OptionNone, OptionSome};
66
use rustc_hir::{Expr, ExprKind};
@@ -9,8 +9,6 @@ use rustc_middle::lint::in_external_macro;
99
use rustc_semver::RustcVersion;
1010
use rustc_session::{declare_tool_lint, impl_lint_pass};
1111

12-
const IF_THEN_SOME_ELSE_NONE_MSRV: RustcVersion = RustcVersion::new(1, 50, 0);
13-
1412
declare_clippy_lint! {
1513
/// **What it does:** Checks for if-else that could be written to `bool::then`.
1614
///
@@ -59,7 +57,7 @@ impl_lint_pass!(IfThenSomeElseNone => [IF_THEN_SOME_ELSE_NONE]);
5957

6058
impl LateLintPass<'_> for IfThenSomeElseNone {
6159
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &'tcx Expr<'_>) {
62-
if !meets_msrv(self.msrv.as_ref(), &IF_THEN_SOME_ELSE_NONE_MSRV) {
60+
if !meets_msrv(self.msrv.as_ref(), &msrvs::BOOL_THEN) {
6361
return;
6462
}
6563

src/tools/clippy/clippy_lints/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
10771077
store.register_late_pass(move || box from_over_into::FromOverInto::new(msrv));
10781078
store.register_late_pass(move || box use_self::UseSelf::new(msrv));
10791079
store.register_late_pass(move || box missing_const_for_fn::MissingConstForFn::new(msrv));
1080-
store.register_late_pass(move || box needless_question_mark::NeedlessQuestionMark::new(msrv));
1080+
store.register_late_pass(move || box needless_question_mark::NeedlessQuestionMark);
10811081
store.register_late_pass(move || box casts::Casts::new(msrv));
10821082
store.register_early_pass(move || box unnested_or_patterns::UnnestedOrPatterns::new(msrv));
10831083

src/tools/clippy/clippy_lints/src/loops/single_element_loop.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@ pub(super) fn check<'tcx>(
1414
body: &'tcx Expr<'_>,
1515
expr: &'tcx Expr<'_>,
1616
) {
17+
let arg_expr = match arg.kind {
18+
ExprKind::AddrOf(BorrowKind::Ref, _, ref_arg) => ref_arg,
19+
ExprKind::MethodCall(method, _, args, _) if args.len() == 1 && method.ident.name == rustc_span::sym::iter => {
20+
&args[0]
21+
},
22+
_ => return,
23+
};
1724
if_chain! {
18-
if let ExprKind::AddrOf(BorrowKind::Ref, _, arg_expr) = arg.kind;
1925
if let PatKind::Binding(.., target, _) = pat.kind;
2026
if let ExprKind::Array([arg_expression]) = arg_expr.kind;
2127
if let ExprKind::Path(ref list_item) = arg_expression.kind;

src/tools/clippy/clippy_lints/src/manual_non_exhaustive.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::attrs::is_doc_hidden;
22
use clippy_utils::diagnostics::span_lint_and_then;
3-
use clippy_utils::meets_msrv;
43
use clippy_utils::source::snippet_opt;
4+
use clippy_utils::{meets_msrv, msrvs};
55
use if_chain::if_chain;
66
use rustc_ast::ast::{FieldDef, Item, ItemKind, Variant, VariantData, VisibilityKind};
77
use rustc_errors::Applicability;
@@ -10,8 +10,6 @@ use rustc_semver::RustcVersion;
1010
use rustc_session::{declare_tool_lint, impl_lint_pass};
1111
use rustc_span::{sym, Span};
1212

13-
const MANUAL_NON_EXHAUSTIVE_MSRV: RustcVersion = RustcVersion::new(1, 40, 0);
14-
1513
declare_clippy_lint! {
1614
/// **What it does:** Checks for manual implementations of the non-exhaustive pattern.
1715
///
@@ -76,7 +74,7 @@ impl_lint_pass!(ManualNonExhaustive => [MANUAL_NON_EXHAUSTIVE]);
7674

7775
impl EarlyLintPass for ManualNonExhaustive {
7876
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
79-
if !meets_msrv(self.msrv.as_ref(), &MANUAL_NON_EXHAUSTIVE_MSRV) {
77+
if !meets_msrv(self.msrv.as_ref(), &msrvs::NON_EXHAUSTIVE) {
8078
return;
8179
}
8280

src/tools/clippy/clippy_lints/src/manual_strip.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::consts::{constant, Constant};
22
use clippy_utils::diagnostics::{multispan_sugg, span_lint_and_then};
33
use clippy_utils::source::snippet;
44
use clippy_utils::usage::mutated_variables;
5-
use clippy_utils::{eq_expr_value, higher, match_def_path, meets_msrv, paths};
5+
use clippy_utils::{eq_expr_value, higher, match_def_path, meets_msrv, msrvs, paths};
66
use if_chain::if_chain;
77
use rustc_ast::ast::LitKind;
88
use rustc_hir::def::Res;
@@ -17,8 +17,6 @@ use rustc_session::{declare_tool_lint, impl_lint_pass};
1717
use rustc_span::source_map::Spanned;
1818
use rustc_span::Span;
1919

20-
const MANUAL_STRIP_MSRV: RustcVersion = RustcVersion::new(1, 45, 0);
21-
2220
declare_clippy_lint! {
2321
/// **What it does:**
2422
/// Suggests using `strip_{prefix,suffix}` over `str::{starts,ends}_with` and slicing using
@@ -74,7 +72,7 @@ enum StripKind {
7472

7573
impl<'tcx> LateLintPass<'tcx> for ManualStrip {
7674
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
77-
if !meets_msrv(self.msrv.as_ref(), &MANUAL_STRIP_MSRV) {
75+
if !meets_msrv(self.msrv.as_ref(), &msrvs::STR_STRIP_PREFIX) {
7876
return;
7977
}
8078

src/tools/clippy/clippy_lints/src/manual_unwrap_or.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,23 @@ fn lint_manual_unwrap_or<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
112112
then {
113113
let reindented_or_body =
114114
reindent_multiline(or_body_snippet.into(), true, Some(indent));
115+
116+
let suggestion = if scrutinee.span.from_expansion() {
117+
// we don't want parenthesis around macro, e.g. `(some_macro!()).unwrap_or(0)`
118+
sugg::Sugg::hir_with_macro_callsite(cx, scrutinee, "..")
119+
}
120+
else {
121+
sugg::Sugg::hir(cx, scrutinee, "..").maybe_par()
122+
};
123+
115124
span_lint_and_sugg(
116125
cx,
117126
MANUAL_UNWRAP_OR, expr.span,
118127
&format!("this pattern reimplements `{}`", case.unwrap_fn_path()),
119128
"replace with",
120129
format!(
121130
"{}.unwrap_or({})",
122-
sugg::Sugg::hir(cx, scrutinee, "..").maybe_par(),
131+
suggestion,
123132
reindented_or_body,
124133
),
125134
Applicability::MachineApplicable,

src/tools/clippy/clippy_lints/src/matches.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ use clippy_utils::sugg::Sugg;
77
use clippy_utils::ty::{implements_trait, is_type_diagnostic_item, match_type, peel_mid_ty_refs};
88
use clippy_utils::visitors::LocalUsedVisitor;
99
use clippy_utils::{
10-
get_parent_expr, in_macro, is_allowed, is_expn_of, is_lang_ctor, is_refutable, is_wild, meets_msrv, path_to_local,
11-
path_to_local_id, peel_hir_pat_refs, peel_n_hir_expr_refs, recurse_or_patterns, remove_blocks, strip_pat_refs,
10+
get_parent_expr, in_macro, is_allowed, is_expn_of, is_lang_ctor, is_refutable, is_wild, meets_msrv, msrvs,
11+
path_to_local, path_to_local_id, peel_hir_pat_refs, peel_n_hir_expr_refs, recurse_or_patterns, remove_blocks,
12+
strip_pat_refs,
1213
};
1314
use clippy_utils::{paths, search_same, SpanlessEq, SpanlessHash};
1415
use if_chain::if_chain;
@@ -578,8 +579,6 @@ impl_lint_pass!(Matches => [
578579
MATCH_SAME_ARMS,
579580
]);
580581

581-
const MATCH_LIKE_MATCHES_MACRO_MSRV: RustcVersion = RustcVersion::new(1, 42, 0);
582-
583582
impl<'tcx> LateLintPass<'tcx> for Matches {
584583
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
585584
if in_external_macro(cx.sess(), expr.span) || in_macro(expr.span) {
@@ -588,7 +587,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches {
588587

589588
redundant_pattern_match::check(cx, expr);
590589

591-
if meets_msrv(self.msrv.as_ref(), &MATCH_LIKE_MATCHES_MACRO_MSRV) {
590+
if meets_msrv(self.msrv.as_ref(), &msrvs::MATCHES_MACRO) {
592591
if !check_match_like_matches(cx, expr) {
593592
lint_match_arms(cx, expr);
594593
}

0 commit comments

Comments
 (0)