Pass msrvs by copy

This commit is contained in:
Samuel E. Moelius III 2022-05-08 07:13:14 -04:00
parent 9c78883fdf
commit bdfea1c095
36 changed files with 70 additions and 72 deletions

View File

@ -87,9 +87,7 @@ impl ApproxConstant {
let s = s.as_str(); let s = s.as_str();
if s.parse::<f64>().is_ok() { if s.parse::<f64>().is_ok() {
for &(constant, name, min_digits, msrv) in &KNOWN_CONSTS { for &(constant, name, min_digits, msrv) in &KNOWN_CONSTS {
if is_approx_const(constant, s, min_digits) if is_approx_const(constant, s, min_digits) && msrv.map_or(true, |msrv| meets_msrv(self.msrv, msrv)) {
&& msrv.as_ref().map_or(true, |msrv| meets_msrv(self.msrv.as_ref(), msrv))
{
span_lint_and_help( span_lint_and_help(
cx, cx,
APPROX_CONSTANT, APPROX_CONSTANT,

View File

@ -613,7 +613,7 @@ fn check_empty_line_after_outer_attr(cx: &EarlyContext<'_>, item: &rustc_ast::It
fn check_deprecated_cfg_attr(cx: &EarlyContext<'_>, attr: &Attribute, msrv: Option<RustcVersion>) { fn check_deprecated_cfg_attr(cx: &EarlyContext<'_>, attr: &Attribute, msrv: Option<RustcVersion>) {
if_chain! { if_chain! {
if meets_msrv(msrv.as_ref(), &msrvs::TOOL_ATTRIBUTES); if meets_msrv(msrv, msrvs::TOOL_ATTRIBUTES);
// check cfg_attr // check cfg_attr
if attr.has_name(sym::cfg_attr); if attr.has_name(sym::cfg_attr);
if let Some(items) = attr.meta_item_list(); if let Some(items) = attr.meta_item_list();

View File

@ -57,7 +57,7 @@ impl BorrowAsPtr {
impl<'tcx> LateLintPass<'tcx> for BorrowAsPtr { impl<'tcx> LateLintPass<'tcx> for BorrowAsPtr {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if !meets_msrv(self.msrv.as_ref(), &msrvs::BORROW_AS_PTR) { if !meets_msrv(self.msrv, msrvs::BORROW_AS_PTR) {
return; return;
} }

View File

@ -16,10 +16,10 @@ pub(super) fn check(
cast_expr: &Expr<'_>, cast_expr: &Expr<'_>,
cast_from: Ty<'_>, cast_from: Ty<'_>,
cast_to: Ty<'_>, cast_to: Ty<'_>,
msrv: &Option<RustcVersion>, msrv: Option<RustcVersion>,
) { ) {
if_chain! { if_chain! {
if meets_msrv(msrv.as_ref(), &msrvs::UNSIGNED_ABS); if meets_msrv(msrv, msrvs::UNSIGNED_ABS);
if cast_from.is_integral(); if cast_from.is_integral();
if cast_to.is_integral(); if cast_to.is_integral();
if cast_from.is_signed(); if cast_from.is_signed();

View File

@ -16,7 +16,7 @@ pub(super) fn check(
cast_op: &Expr<'_>, cast_op: &Expr<'_>,
cast_from: Ty<'_>, cast_from: Ty<'_>,
cast_to: Ty<'_>, cast_to: Ty<'_>,
msrv: &Option<RustcVersion>, msrv: Option<RustcVersion>,
) { ) {
if !should_lint(cx, expr, cast_from, cast_to, msrv) { if !should_lint(cx, expr, cast_from, cast_to, msrv) {
return; return;
@ -68,7 +68,7 @@ fn should_lint(
expr: &Expr<'_>, expr: &Expr<'_>,
cast_from: Ty<'_>, cast_from: Ty<'_>,
cast_to: Ty<'_>, cast_to: Ty<'_>,
msrv: &Option<RustcVersion>, msrv: Option<RustcVersion>,
) -> bool { ) -> bool {
// Do not suggest using From in consts/statics until it is valid to do so (see #2267). // Do not suggest using From in consts/statics until it is valid to do so (see #2267).
if in_constant(cx, expr.hir_id) { if in_constant(cx, expr.hir_id) {
@ -95,7 +95,7 @@ fn should_lint(
}; };
!is_isize_or_usize(cast_from) && from_nbits < to_nbits !is_isize_or_usize(cast_from) && from_nbits < to_nbits
}, },
(false, true) if matches!(cast_from.kind(), ty::Bool) && meets_msrv(msrv.as_ref(), &msrvs::FROM_BOOL) => true, (false, true) if matches!(cast_from.kind(), ty::Bool) && meets_msrv(msrv, msrvs::FROM_BOOL) => true,
(_, _) => { (_, _) => {
matches!(cast_from.kind(), ty::Float(FloatTy::F32)) && matches!(cast_to.kind(), ty::Float(FloatTy::F64)) matches!(cast_from.kind(), ty::Float(FloatTy::F32)) && matches!(cast_to.kind(), ty::Float(FloatTy::F64))
}, },

View File

@ -8,9 +8,9 @@ use rustc_semver::RustcVersion;
use super::CAST_SLICE_DIFFERENT_SIZES; use super::CAST_SLICE_DIFFERENT_SIZES;
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, msrv: &Option<RustcVersion>) { pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, msrv: Option<RustcVersion>) {
// suggestion is invalid if `ptr::slice_from_raw_parts` does not exist // suggestion is invalid if `ptr::slice_from_raw_parts` does not exist
if !meets_msrv(msrv.as_ref(), &msrvs::PTR_SLICE_RAW_PARTS) { if !meets_msrv(msrv, msrvs::PTR_SLICE_RAW_PARTS) {
return; return;
} }

View File

@ -532,7 +532,7 @@ impl_lint_pass!(Casts => [
impl<'tcx> LateLintPass<'tcx> for Casts { impl<'tcx> LateLintPass<'tcx> for Casts {
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) { if !in_external_macro(cx.sess(), expr.span) {
ptr_as_ptr::check(cx, expr, &self.msrv); ptr_as_ptr::check(cx, expr, self.msrv);
} }
if expr.span.from_expansion() { if expr.span.from_expansion() {
@ -562,9 +562,9 @@ impl<'tcx> LateLintPass<'tcx> for Casts {
cast_possible_wrap::check(cx, expr, cast_from, cast_to); cast_possible_wrap::check(cx, expr, cast_from, cast_to);
cast_precision_loss::check(cx, expr, cast_from, cast_to); cast_precision_loss::check(cx, expr, cast_from, cast_to);
cast_sign_loss::check(cx, expr, cast_expr, cast_from, cast_to); cast_sign_loss::check(cx, expr, cast_expr, cast_from, cast_to);
cast_abs_to_unsigned::check(cx, expr, cast_expr, cast_from, cast_to, &self.msrv); cast_abs_to_unsigned::check(cx, expr, cast_expr, cast_from, cast_to, self.msrv);
} }
cast_lossless::check(cx, expr, cast_expr, cast_from, cast_to, &self.msrv); cast_lossless::check(cx, expr, cast_expr, cast_from, cast_to, self.msrv);
cast_enum_constructor::check(cx, expr, cast_expr, cast_from); cast_enum_constructor::check(cx, expr, cast_expr, cast_from);
} }
} }
@ -572,8 +572,8 @@ impl<'tcx> LateLintPass<'tcx> for Casts {
cast_ref_to_mut::check(cx, expr); cast_ref_to_mut::check(cx, expr);
cast_ptr_alignment::check(cx, expr); cast_ptr_alignment::check(cx, expr);
char_lit_as_u8::check(cx, expr); char_lit_as_u8::check(cx, expr);
ptr_as_ptr::check(cx, expr, &self.msrv); ptr_as_ptr::check(cx, expr, self.msrv);
cast_slice_different_sizes::check(cx, expr, &self.msrv); cast_slice_different_sizes::check(cx, expr, self.msrv);
} }
extract_msrv_attr!(LateContext); extract_msrv_attr!(LateContext);

View File

@ -12,8 +12,8 @@ use rustc_semver::RustcVersion;
use super::PTR_AS_PTR; use super::PTR_AS_PTR;
pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: &Option<RustcVersion>) { pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: Option<RustcVersion>) {
if !meets_msrv(msrv.as_ref(), &msrvs::POINTER_CAST) { if !meets_msrv(msrv, msrvs::POINTER_CAST) {
return; return;
} }

View File

@ -57,7 +57,7 @@ impl_lint_pass!(CheckedConversions => [CHECKED_CONVERSIONS]);
impl<'tcx> LateLintPass<'tcx> for CheckedConversions { impl<'tcx> LateLintPass<'tcx> for CheckedConversions {
fn check_expr(&mut self, cx: &LateContext<'_>, item: &Expr<'_>) { fn check_expr(&mut self, cx: &LateContext<'_>, item: &Expr<'_>) {
if !meets_msrv(self.msrv.as_ref(), &msrvs::TRY_FROM) { if !meets_msrv(self.msrv, msrvs::TRY_FROM) {
return; return;
} }

View File

@ -55,7 +55,7 @@ impl_lint_pass!(FromOverInto => [FROM_OVER_INTO]);
impl<'tcx> LateLintPass<'tcx> for FromOverInto { impl<'tcx> LateLintPass<'tcx> for FromOverInto {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
if !meets_msrv(self.msrv.as_ref(), &msrvs::RE_REBALANCING_COHERENCE) { if !meets_msrv(self.msrv, msrvs::RE_REBALANCING_COHERENCE) {
return; return;
} }

View File

@ -57,7 +57,7 @@ impl_lint_pass!(IfThenSomeElseNone => [IF_THEN_SOME_ELSE_NONE]);
impl<'tcx> LateLintPass<'tcx> for IfThenSomeElseNone { impl<'tcx> LateLintPass<'tcx> for IfThenSomeElseNone {
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &'tcx Expr<'_>) { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &'tcx Expr<'_>) {
if !meets_msrv(self.msrv.as_ref(), &msrvs::BOOL_THEN) { if !meets_msrv(self.msrv, msrvs::BOOL_THEN) {
return; return;
} }

View File

@ -75,7 +75,7 @@ impl<'tcx> LateLintPass<'tcx> for IndexRefutableSlice {
if !expr.span.from_expansion() || is_expn_of(expr.span, "if_chain").is_some(); if !expr.span.from_expansion() || is_expn_of(expr.span, "if_chain").is_some();
if let Some(IfLet {let_pat, if_then, ..}) = IfLet::hir(cx, expr); if let Some(IfLet {let_pat, if_then, ..}) = IfLet::hir(cx, expr);
if !is_lint_allowed(cx, INDEX_REFUTABLE_SLICE, expr.hir_id); if !is_lint_allowed(cx, INDEX_REFUTABLE_SLICE, expr.hir_id);
if meets_msrv(self.msrv.as_ref(), &msrvs::SLICE_PATTERNS); if meets_msrv(self.msrv, msrvs::SLICE_PATTERNS);
let found_slices = find_slice_values(cx, let_pat); let found_slices = find_slice_values(cx, let_pat);
if !found_slices.is_empty(); if !found_slices.is_empty();

View File

@ -48,7 +48,7 @@ impl_lint_pass!(ManualBits => [MANUAL_BITS]);
impl<'tcx> LateLintPass<'tcx> for ManualBits { impl<'tcx> LateLintPass<'tcx> for ManualBits {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if !meets_msrv(self.msrv.as_ref(), &msrvs::MANUAL_BITS) { if !meets_msrv(self.msrv, msrvs::MANUAL_BITS) {
return; return;
} }

View File

@ -98,7 +98,7 @@ impl_lint_pass!(ManualNonExhaustiveEnum => [MANUAL_NON_EXHAUSTIVE]);
impl EarlyLintPass for ManualNonExhaustiveStruct { impl EarlyLintPass for ManualNonExhaustiveStruct {
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &ast::Item) { fn check_item(&mut self, cx: &EarlyContext<'_>, item: &ast::Item) {
if !meets_msrv(self.msrv.as_ref(), &msrvs::NON_EXHAUSTIVE) { if !meets_msrv(self.msrv, msrvs::NON_EXHAUSTIVE) {
return; return;
} }
@ -150,7 +150,7 @@ impl EarlyLintPass for ManualNonExhaustiveStruct {
impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustiveEnum { impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustiveEnum {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
if !meets_msrv(self.msrv.as_ref(), &msrvs::NON_EXHAUSTIVE) { if !meets_msrv(self.msrv, msrvs::NON_EXHAUSTIVE) {
return; return;
} }

View File

@ -68,7 +68,7 @@ enum StripKind {
impl<'tcx> LateLintPass<'tcx> for ManualStrip { impl<'tcx> LateLintPass<'tcx> for ManualStrip {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if !meets_msrv(self.msrv.as_ref(), &msrvs::STR_STRIP_PREFIX) { if !meets_msrv(self.msrv, msrvs::STR_STRIP_PREFIX) {
return; return;
} }

View File

@ -144,7 +144,7 @@ impl MapClone {
fn lint_explicit_closure(&self, cx: &LateContext<'_>, replace: Span, root: Span, is_copy: bool) { fn lint_explicit_closure(&self, cx: &LateContext<'_>, replace: Span, root: Span, is_copy: bool) {
let mut applicability = Applicability::MachineApplicable; let mut applicability = Applicability::MachineApplicable;
let (message, sugg_method) = if is_copy && meets_msrv(self.msrv.as_ref(), &msrvs::ITERATOR_COPIED) { let (message, sugg_method) = if is_copy && meets_msrv(self.msrv, msrvs::ITERATOR_COPIED) {
("you are using an explicit closure for copying elements", "copied") ("you are using an explicit closure for copying elements", "copied")
} else { } else {
("you are using an explicit closure for cloning elements", "cloned") ("you are using an explicit closure for cloning elements", "cloned")

View File

@ -658,7 +658,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches {
} }
if !contains_cfg_arm(cx, expr, ex, arms) { if !contains_cfg_arm(cx, expr, ex, arms) {
if source == MatchSource::Normal { if source == MatchSource::Normal {
if !(meets_msrv(self.msrv.as_ref(), &msrvs::MATCHES_MACRO) if !(meets_msrv(self.msrv, msrvs::MATCHES_MACRO)
&& match_like_matches::check_match(cx, expr, ex, arms)) && match_like_matches::check_match(cx, expr, ex, arms))
{ {
match_same_arms::check(cx, arms); match_same_arms::check(cx, arms);
@ -685,7 +685,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches {
match_wild_err_arm::check(cx, ex, arms); match_wild_err_arm::check(cx, ex, arms);
wild_in_or_pats::check(cx, arms); wild_in_or_pats::check(cx, arms);
} else { } else {
if meets_msrv(self.msrv.as_ref(), &msrvs::MATCHES_MACRO) { if meets_msrv(self.msrv, msrvs::MATCHES_MACRO) {
match_like_matches::check(cx, expr); match_like_matches::check(cx, expr);
} }
redundant_pattern_match::check(cx, expr); redundant_pattern_match::check(cx, expr);

View File

@ -254,7 +254,7 @@ impl<'tcx> LateLintPass<'tcx> for MemReplace {
then { then {
check_replace_option_with_none(cx, src, dest, expr.span); check_replace_option_with_none(cx, src, dest, expr.span);
check_replace_with_uninit(cx, src, dest, expr.span); check_replace_with_uninit(cx, src, dest, expr.span);
if meets_msrv(self.msrv.as_ref(), &msrvs::MEM_TAKE) { if meets_msrv(self.msrv, msrvs::MEM_TAKE) {
check_replace_with_default(cx, src, dest, expr.span); check_replace_with_default(cx, src, dest, expr.span);
} }
} }

View File

@ -10,16 +10,16 @@ use rustc_span::{sym, Span};
use super::CLONED_INSTEAD_OF_COPIED; use super::CLONED_INSTEAD_OF_COPIED;
pub fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, span: Span, msrv: Option<&RustcVersion>) { pub fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, span: Span, msrv: Option<RustcVersion>) {
let recv_ty = cx.typeck_results().expr_ty_adjusted(recv); let recv_ty = cx.typeck_results().expr_ty_adjusted(recv);
let inner_ty = match recv_ty.kind() { let inner_ty = match recv_ty.kind() {
// `Option<T>` -> `T` // `Option<T>` -> `T`
ty::Adt(adt, subst) ty::Adt(adt, subst)
if cx.tcx.is_diagnostic_item(sym::Option, adt.did()) && meets_msrv(msrv, &msrvs::OPTION_COPIED) => if cx.tcx.is_diagnostic_item(sym::Option, adt.did()) && meets_msrv(msrv, msrvs::OPTION_COPIED) =>
{ {
subst.type_at(0) subst.type_at(0)
}, },
_ if is_trait_method(cx, expr, sym::Iterator) && meets_msrv(msrv, &msrvs::ITERATOR_COPIED) => { _ if is_trait_method(cx, expr, sym::Iterator) && meets_msrv(msrv, msrvs::ITERATOR_COPIED) => {
match get_iterator_item_ty(cx, recv_ty) { match get_iterator_item_ty(cx, recv_ty) {
// <T as Iterator>::Item // <T as Iterator>::Item
Some(ty) => ty, Some(ty) => ty,

View File

@ -13,7 +13,7 @@ pub(super) fn check(
cx: &LateContext<'_>, cx: &LateContext<'_>,
_expr: &rustc_hir::Expr<'_>, _expr: &rustc_hir::Expr<'_>,
recv: &rustc_hir::Expr<'_>, recv: &rustc_hir::Expr<'_>,
msrv: Option<&RustcVersion>, msrv: Option<RustcVersion>,
expect_span: Span, expect_span: Span,
err_span: Span, err_span: Span,
) { ) {
@ -21,7 +21,7 @@ pub(super) fn check(
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result); if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result);
// Test the version to make sure the lint can be showed (expect_err has been // Test the version to make sure the lint can be showed (expect_err has been
// introduced in rust 1.17.0 : https://github.com/rust-lang/rust/pull/38982) // introduced in rust 1.17.0 : https://github.com/rust-lang/rust/pull/38982)
if meets_msrv(msrv, &msrvs::EXPECT_ERR); if meets_msrv(msrv, msrvs::EXPECT_ERR);
// Grabs the `Result<T, E>` type // Grabs the `Result<T, E>` type
let result_type = cx.typeck_results().expr_ty(recv); let result_type = cx.typeck_results().expr_ty(recv);

View File

@ -14,10 +14,10 @@ pub(super) fn check<'tcx>(
expr: &'tcx hir::Expr<'_>, expr: &'tcx hir::Expr<'_>,
recv: &'tcx hir::Expr<'_>, recv: &'tcx hir::Expr<'_>,
arg: &'tcx hir::Expr<'_>, arg: &'tcx hir::Expr<'_>,
msrv: Option<&RustcVersion>, msrv: Option<RustcVersion>,
) { ) {
if is_trait_method(cx, expr, sym::Iterator) { if is_trait_method(cx, expr, sym::Iterator) {
if !meets_msrv(msrv, &msrvs::ITERATOR_FIND_MAP) { if !meets_msrv(msrv, msrvs::ITERATOR_FIND_MAP) {
return; return;
} }

View File

@ -15,9 +15,9 @@ pub(super) fn check<'tcx>(
expr: &'tcx Expr<'_>, expr: &'tcx Expr<'_>,
self_arg: &'tcx Expr<'_>, self_arg: &'tcx Expr<'_>,
radix: &'tcx Expr<'_>, radix: &'tcx Expr<'_>,
msrv: Option<&RustcVersion>, msrv: Option<RustcVersion>,
) { ) {
if !meets_msrv(msrv, &msrvs::IS_ASCII_DIGIT) { if !meets_msrv(msrv, msrvs::IS_ASCII_DIGIT) {
return; return;
} }

View File

@ -19,13 +19,13 @@ pub(super) fn check<'tcx>(
recv: &'tcx hir::Expr<'_>, recv: &'tcx hir::Expr<'_>,
map_arg: &'tcx hir::Expr<'_>, map_arg: &'tcx hir::Expr<'_>,
unwrap_arg: &'tcx hir::Expr<'_>, unwrap_arg: &'tcx hir::Expr<'_>,
msrv: Option<&RustcVersion>, msrv: Option<RustcVersion>,
) -> bool { ) -> bool {
// lint if the caller of `map()` is an `Option` // lint if the caller of `map()` is an `Option`
let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Option); let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Option);
let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result); let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result);
if is_result && !meets_msrv(msrv, &msrvs::RESULT_MAP_OR_ELSE) { if is_result && !meets_msrv(msrv, msrvs::RESULT_MAP_OR_ELSE) {
return false; return false;
} }

View File

@ -2306,7 +2306,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
return; return;
} }
check_methods(cx, expr, self.msrv.as_ref()); check_methods(cx, expr, self.msrv);
match expr.kind { match expr.kind {
hir::ExprKind::Call(func, args) => { hir::ExprKind::Call(func, args) => {
@ -2322,7 +2322,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
single_char_add_str::check(cx, expr, args); single_char_add_str::check(cx, expr, args);
into_iter_on_ref::check(cx, expr, method_span, method_call.ident.name, args); into_iter_on_ref::check(cx, expr, method_span, method_call.ident.name, args);
single_char_pattern::check(cx, expr, method_call.ident.name, args); single_char_pattern::check(cx, expr, method_call.ident.name, args);
unnecessary_to_owned::check(cx, expr, method_call.ident.name, args, self.msrv.as_ref()); unnecessary_to_owned::check(cx, expr, method_call.ident.name, args, self.msrv);
}, },
hir::ExprKind::Binary(op, lhs, rhs) if op.node == hir::BinOpKind::Eq || op.node == hir::BinOpKind::Ne => { hir::ExprKind::Binary(op, lhs, rhs) if op.node == hir::BinOpKind::Eq || op.node == hir::BinOpKind::Ne => {
let mut info = BinaryExprInfo { let mut info = BinaryExprInfo {
@ -2506,7 +2506,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
} }
#[allow(clippy::too_many_lines)] #[allow(clippy::too_many_lines)]
fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Option<&RustcVersion>) { fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Option<RustcVersion>) {
if let Some((name, [recv, args @ ..], span)) = method_call(expr) { if let Some((name, [recv, args @ ..], span)) = method_call(expr) {
match (name, args) { match (name, args) {
("add" | "offset" | "sub" | "wrapping_offset" | "wrapping_add" | "wrapping_sub", [_arg]) => { ("add" | "offset" | "sub" | "wrapping_offset" | "wrapping_add" | "wrapping_sub", [_arg]) => {
@ -2534,7 +2534,7 @@ fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Optio
map_collect_result_unit::check(cx, expr, m_recv, m_arg, recv); map_collect_result_unit::check(cx, expr, m_recv, m_arg, recv);
}, },
Some(("take", [take_self_arg, take_arg], _)) => { Some(("take", [take_self_arg, take_arg], _)) => {
if meets_msrv(msrv, &msrvs::STR_REPEAT) { if meets_msrv(msrv, msrvs::STR_REPEAT) {
manual_str_repeat::check(cx, expr, recv, take_self_arg, take_arg); manual_str_repeat::check(cx, expr, recv, take_self_arg, take_arg);
} }
}, },

View File

@ -19,9 +19,9 @@ pub(super) fn check<'tcx>(
as_ref_recv: &hir::Expr<'_>, as_ref_recv: &hir::Expr<'_>,
map_arg: &hir::Expr<'_>, map_arg: &hir::Expr<'_>,
is_mut: bool, is_mut: bool,
msrv: Option<&RustcVersion>, msrv: Option<RustcVersion>,
) { ) {
if !meets_msrv(msrv, &msrvs::OPTION_AS_DEREF) { if !meets_msrv(msrv, msrvs::OPTION_AS_DEREF) {
return; return;
} }

View File

@ -24,7 +24,7 @@ pub(super) fn check(
self_arg: &Expr<'_>, self_arg: &Expr<'_>,
pat_arg: &Expr<'_>, pat_arg: &Expr<'_>,
count: u128, count: u128,
msrv: Option<&RustcVersion>, msrv: Option<RustcVersion>,
) { ) {
if count < 2 || !cx.typeck_results().expr_ty_adjusted(self_arg).peel_refs().is_str() { if count < 2 || !cx.typeck_results().expr_ty_adjusted(self_arg).peel_refs().is_str() {
return; return;
@ -34,7 +34,7 @@ pub(super) fn check(
IterUsageKind::Nth(n) => count > n + 1, IterUsageKind::Nth(n) => count > n + 1,
IterUsageKind::NextTuple => count > 2, IterUsageKind::NextTuple => count > 2,
}; };
let manual = count == 2 && meets_msrv(msrv, &msrvs::STR_SPLIT_ONCE); let manual = count == 2 && meets_msrv(msrv, msrvs::STR_SPLIT_ONCE);
match parse_iter_usage(cx, expr.span.ctxt(), cx.tcx.hir().parent_iter(expr.hir_id)) { match parse_iter_usage(cx, expr.span.ctxt(), cx.tcx.hir().parent_iter(expr.hir_id)) {
Some(usage) if needless(usage.kind) => lint_needless(cx, method_name, expr, self_arg, pat_arg), Some(usage) if needless(usage.kind) => lint_needless(cx, method_name, expr, self_arg, pat_arg),

View File

@ -26,7 +26,7 @@ pub fn check<'tcx>(
expr: &'tcx Expr<'tcx>, expr: &'tcx Expr<'tcx>,
method_name: Symbol, method_name: Symbol,
args: &'tcx [Expr<'tcx>], args: &'tcx [Expr<'tcx>],
msrv: Option<&RustcVersion>, msrv: Option<RustcVersion>,
) { ) {
if_chain! { if_chain! {
if let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id);
@ -198,7 +198,7 @@ fn check_into_iter_call_arg(
expr: &Expr<'_>, expr: &Expr<'_>,
method_name: Symbol, method_name: Symbol,
receiver: &Expr<'_>, receiver: &Expr<'_>,
msrv: Option<&RustcVersion>, msrv: Option<RustcVersion>,
) -> bool { ) -> bool {
if_chain! { if_chain! {
if let Some(parent) = get_parent_expr(cx, expr); if let Some(parent) = get_parent_expr(cx, expr);
@ -213,7 +213,7 @@ fn check_into_iter_call_arg(
if unnecessary_iter_cloned::check_for_loop_iter(cx, parent, method_name, receiver, true) { if unnecessary_iter_cloned::check_for_loop_iter(cx, parent, method_name, receiver, true) {
return true; return true;
} }
let cloned_or_copied = if is_copy(cx, item_ty) && meets_msrv(msrv, &msrvs::ITERATOR_COPIED) { let cloned_or_copied = if is_copy(cx, item_ty) && meets_msrv(msrv, msrvs::ITERATOR_COPIED) {
"copied" "copied"
} else { } else {
"cloned" "cloned"

View File

@ -93,7 +93,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn {
span: Span, span: Span,
hir_id: HirId, hir_id: HirId,
) { ) {
if !meets_msrv(self.msrv.as_ref(), &msrvs::CONST_IF_MATCH) { if !meets_msrv(self.msrv, msrvs::CONST_IF_MATCH) {
return; return;
} }
@ -146,7 +146,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn {
let mir = cx.tcx.optimized_mir(def_id); let mir = cx.tcx.optimized_mir(def_id);
if let Err((span, err)) = is_min_const_fn(cx.tcx, mir, self.msrv.as_ref()) { if let Err((span, err)) = is_min_const_fn(cx.tcx, mir, self.msrv) {
if cx.tcx.is_const_fn_raw(def_id.to_def_id()) { if cx.tcx.is_const_fn_raw(def_id.to_def_id()) {
cx.tcx.sess.span_err(span, err.as_ref()); cx.tcx.sess.span_err(span, err.as_ref());
} }

View File

@ -193,7 +193,7 @@ impl<'tcx> LateLintPass<'tcx> for Ranges {
check_range_zip_with_len(cx, path, args, expr.span); check_range_zip_with_len(cx, path, args, expr.span);
}, },
ExprKind::Binary(ref op, l, r) => { ExprKind::Binary(ref op, l, r) => {
if meets_msrv(self.msrv.as_ref(), &msrvs::RANGE_CONTAINS) { if meets_msrv(self.msrv, msrvs::RANGE_CONTAINS) {
check_possible_range_contains(cx, op.node, l, r, expr); check_possible_range_contains(cx, op.node, l, r, expr);
} }
}, },

View File

@ -51,7 +51,7 @@ impl_lint_pass!(RedundantFieldNames => [REDUNDANT_FIELD_NAMES]);
impl EarlyLintPass for RedundantFieldNames { impl EarlyLintPass for RedundantFieldNames {
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
if !meets_msrv(self.msrv.as_ref(), &msrvs::FIELD_INIT_SHORTHAND) { if !meets_msrv(self.msrv, msrvs::FIELD_INIT_SHORTHAND) {
return; return;
} }

View File

@ -99,7 +99,7 @@ impl RedundantStaticLifetimes {
impl EarlyLintPass for RedundantStaticLifetimes { impl EarlyLintPass for RedundantStaticLifetimes {
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
if !meets_msrv(self.msrv.as_ref(), &msrvs::STATIC_IN_CONST) { if !meets_msrv(self.msrv, msrvs::STATIC_IN_CONST) {
return; return;
} }

View File

@ -61,13 +61,13 @@ impl_lint_pass!(UnnestedOrPatterns => [UNNESTED_OR_PATTERNS]);
impl EarlyLintPass for UnnestedOrPatterns { impl EarlyLintPass for UnnestedOrPatterns {
fn check_arm(&mut self, cx: &EarlyContext<'_>, a: &ast::Arm) { fn check_arm(&mut self, cx: &EarlyContext<'_>, a: &ast::Arm) {
if meets_msrv(self.msrv.as_ref(), &msrvs::OR_PATTERNS) { if meets_msrv(self.msrv, msrvs::OR_PATTERNS) {
lint_unnested_or_patterns(cx, &a.pat); lint_unnested_or_patterns(cx, &a.pat);
} }
} }
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) { fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) {
if meets_msrv(self.msrv.as_ref(), &msrvs::OR_PATTERNS) { if meets_msrv(self.msrv, msrvs::OR_PATTERNS) {
if let ast::ExprKind::Let(pat, _, _) = &e.kind { if let ast::ExprKind::Let(pat, _, _) = &e.kind {
lint_unnested_or_patterns(cx, pat); lint_unnested_or_patterns(cx, pat);
} }
@ -75,13 +75,13 @@ impl EarlyLintPass for UnnestedOrPatterns {
} }
fn check_param(&mut self, cx: &EarlyContext<'_>, p: &ast::Param) { fn check_param(&mut self, cx: &EarlyContext<'_>, p: &ast::Param) {
if meets_msrv(self.msrv.as_ref(), &msrvs::OR_PATTERNS) { if meets_msrv(self.msrv, msrvs::OR_PATTERNS) {
lint_unnested_or_patterns(cx, &p.pat); lint_unnested_or_patterns(cx, &p.pat);
} }
} }
fn check_local(&mut self, cx: &EarlyContext<'_>, l: &ast::Local) { fn check_local(&mut self, cx: &EarlyContext<'_>, l: &ast::Local) {
if meets_msrv(self.msrv.as_ref(), &msrvs::OR_PATTERNS) { if meets_msrv(self.msrv, msrvs::OR_PATTERNS) {
lint_unnested_or_patterns(cx, &l.pat); lint_unnested_or_patterns(cx, &l.pat);
} }
} }

View File

@ -198,7 +198,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
fn check_ty(&mut self, cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>) { fn check_ty(&mut self, cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>) {
if_chain! { if_chain! {
if !hir_ty.span.from_expansion(); if !hir_ty.span.from_expansion();
if meets_msrv(self.msrv.as_ref(), &msrvs::TYPE_ALIAS_ENUM_VARIANTS); if meets_msrv(self.msrv, msrvs::TYPE_ALIAS_ENUM_VARIANTS);
if let Some(&StackItem::Check { if let Some(&StackItem::Check {
impl_id, impl_id,
in_body, in_body,
@ -225,7 +225,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
if_chain! { if_chain! {
if !expr.span.from_expansion(); if !expr.span.from_expansion();
if meets_msrv(self.msrv.as_ref(), &msrvs::TYPE_ALIAS_ENUM_VARIANTS); if meets_msrv(self.msrv, msrvs::TYPE_ALIAS_ENUM_VARIANTS);
if let Some(&StackItem::Check { impl_id, .. }) = self.stack.last(); if let Some(&StackItem::Check { impl_id, .. }) = self.stack.last();
if cx.typeck_results().expr_ty(expr) == cx.tcx.type_of(impl_id); if cx.typeck_results().expr_ty(expr) == cx.tcx.type_of(impl_id);
then {} else { return; } then {} else { return; }
@ -256,7 +256,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
fn check_pat(&mut self, cx: &LateContext<'_>, pat: &Pat<'_>) { fn check_pat(&mut self, cx: &LateContext<'_>, pat: &Pat<'_>) {
if_chain! { if_chain! {
if !pat.span.from_expansion(); if !pat.span.from_expansion();
if meets_msrv(self.msrv.as_ref(), &msrvs::TYPE_ALIAS_ENUM_VARIANTS); if meets_msrv(self.msrv, msrvs::TYPE_ALIAS_ENUM_VARIANTS);
if let Some(&StackItem::Check { impl_id, .. }) = self.stack.last(); if let Some(&StackItem::Check { impl_id, .. }) = self.stack.last();
if let PatKind::Path(QPath::Resolved(_, path)) = pat.kind; if let PatKind::Path(QPath::Resolved(_, path)) = pat.kind;
if !matches!(path.res, Res::SelfTy { .. } | Res::Def(DefKind::TyParam, _)); if !matches!(path.res, Res::SelfTy { .. } | Res::Def(DefKind::TyParam, _));

View File

@ -117,8 +117,8 @@ pub fn parse_msrv(msrv: &str, sess: Option<&Session>, span: Option<Span>) -> Opt
None None
} }
pub fn meets_msrv(msrv: Option<&RustcVersion>, lint_msrv: &RustcVersion) -> bool { pub fn meets_msrv(msrv: Option<RustcVersion>, lint_msrv: RustcVersion) -> bool {
msrv.map_or(true, |msrv| msrv.meets(*lint_msrv)) msrv.map_or(true, |msrv| msrv.meets(lint_msrv))
} }
#[macro_export] #[macro_export]

View File

@ -19,7 +19,7 @@ use std::borrow::Cow;
type McfResult = Result<(), (Span, Cow<'static, str>)>; type McfResult = Result<(), (Span, Cow<'static, str>)>;
pub fn is_min_const_fn<'a, 'tcx>(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, msrv: Option<&RustcVersion>) -> McfResult { pub fn is_min_const_fn<'a, 'tcx>(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, msrv: Option<RustcVersion>) -> McfResult {
let def_id = body.source.def_id(); let def_id = body.source.def_id();
let mut current = def_id; let mut current = def_id;
loop { loop {
@ -269,7 +269,7 @@ fn check_terminator<'a, 'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
body: &'a Body<'tcx>, body: &'a Body<'tcx>,
terminator: &Terminator<'tcx>, terminator: &Terminator<'tcx>,
msrv: Option<&RustcVersion>, msrv: Option<RustcVersion>,
) -> McfResult { ) -> McfResult {
let span = terminator.source_info.span; let span = terminator.source_info.span;
match &terminator.kind { match &terminator.kind {
@ -353,7 +353,7 @@ fn check_terminator<'a, 'tcx>(
} }
} }
fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: Option<&RustcVersion>) -> bool { fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: Option<RustcVersion>) -> bool {
tcx.is_const_fn(def_id) tcx.is_const_fn(def_id)
&& tcx.lookup_const_stability(def_id).map_or(true, |const_stab| { && tcx.lookup_const_stability(def_id).map_or(true, |const_stab| {
if let rustc_attr::StabilityLevel::Stable { since } = const_stab.level { if let rustc_attr::StabilityLevel::Stable { since } = const_stab.level {
@ -362,7 +362,7 @@ fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: Option<&RustcVersion>) -> b
// as a part of an unimplemented MSRV check https://github.com/rust-lang/rust/issues/65262. // as a part of an unimplemented MSRV check https://github.com/rust-lang/rust/issues/65262.
crate::meets_msrv( crate::meets_msrv(
msrv, msrv,
&RustcVersion::parse(since.as_str()) RustcVersion::parse(since.as_str())
.expect("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted"), .expect("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted"),
) )
} else { } else {

View File

@ -432,7 +432,7 @@ The project's MSRV can then be matched against the feature MSRV in the LintPass
using the `meets_msrv` utility function. using the `meets_msrv` utility function.
``` rust ``` rust
if !meets_msrv(self.msrv.as_ref(), &msrvs::STR_STRIP_PREFIX) { if !meets_msrv(self.msrv, msrvs::STR_STRIP_PREFIX) {
return; return;
} }
``` ```