add rustc-semver to dependencies

switch Version/VersionReq usages to RustcVersion
This commit is contained in:
Suyash458
2020-11-28 19:41:27 +05:30
committed by suyash458
parent 68cf94f6a6
commit cd087e5c5e
6 changed files with 23 additions and 46 deletions

View File

@@ -28,6 +28,7 @@ smallvec = { version = "1", features = ["union"] }
toml = "0.5.3" toml = "0.5.3"
unicode-normalization = "0.1" unicode-normalization = "0.1"
semver = "0.11" semver = "0.11"
rustc-semver="1.0.0"
# NOTE: cargo requires serde feat in its url dep # NOTE: cargo requires serde feat in its url dep
# see <https://github.com/rust-lang/rust/pull/63587#issuecomment-522343864> # see <https://github.com/rust-lang/rust/pull/63587#issuecomment-522343864>
url = { version = "2.1.0", features = ["serde"] } url = { version = "2.1.0", features = ["serde"] }

View File

@@ -4,17 +4,11 @@ use rustc_ast::ast::{Attribute, Item, ItemKind, StructField, Variant, VariantDat
use rustc_attr as attr; use rustc_attr as attr;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_lint::{EarlyContext, EarlyLintPass};
use rustc_semver::RustcVersion;
use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_session::{declare_tool_lint, impl_lint_pass};
use rustc_span::{sym, Span}; use rustc_span::{sym, Span};
use semver::{Version, VersionReq};
const MANUAL_NON_EXHAUSTIVE_MSRV: Version = Version { const MANUAL_NON_EXHAUSTIVE_MSRV: RustcVersion = RustcVersion::new(1, 40, 0);
major: 1,
minor: 40,
patch: 0,
pre: Vec::new(),
build: Vec::new(),
};
declare_clippy_lint! { declare_clippy_lint! {
/// **What it does:** Checks for manual implementations of the non-exhaustive pattern. /// **What it does:** Checks for manual implementations of the non-exhaustive pattern.
@@ -66,12 +60,12 @@ declare_clippy_lint! {
#[derive(Clone)] #[derive(Clone)]
pub struct ManualNonExhaustive { pub struct ManualNonExhaustive {
msrv: Option<VersionReq>, msrv: Option<RustcVersion>,
} }
impl ManualNonExhaustive { impl ManualNonExhaustive {
#[must_use] #[must_use]
pub fn new(msrv: Option<VersionReq>) -> Self { pub fn new(msrv: Option<RustcVersion>) -> Self {
Self { msrv } Self { msrv }
} }
} }

View File

@@ -13,18 +13,12 @@ use rustc_hir::{BorrowKind, Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::hir::map::Map; use rustc_middle::hir::map::Map;
use rustc_middle::ty; use rustc_middle::ty;
use rustc_semver::RustcVersion;
use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_session::{declare_tool_lint, impl_lint_pass};
use rustc_span::source_map::Spanned; use rustc_span::source_map::Spanned;
use rustc_span::Span; use rustc_span::Span;
use semver::{Version, VersionReq};
const MANUAL_STRIP_MSRV: Version = Version { const MANUAL_STRIP_MSRV: RustcVersion = RustcVersion::new(1, 45, 0);
major: 1,
minor: 45,
patch: 0,
pre: Vec::new(),
build: Vec::new(),
};
declare_clippy_lint! { declare_clippy_lint! {
/// **What it does:** /// **What it does:**
@@ -61,12 +55,12 @@ declare_clippy_lint! {
} }
pub struct ManualStrip { pub struct ManualStrip {
msrv: Option<VersionReq>, msrv: Option<RustcVersion>,
} }
impl ManualStrip { impl ManualStrip {
#[must_use] #[must_use]
pub fn new(msrv: Option<VersionReq>) -> Self { pub fn new(msrv: Option<RustcVersion>) -> Self {
Self { msrv } Self { msrv }
} }
} }

View File

@@ -20,10 +20,10 @@ use rustc_hir::{
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro; use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::{self, Ty, TyS}; use rustc_middle::ty::{self, Ty, TyS};
use rustc_semver::RustcVersion;
use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_session::{declare_tool_lint, impl_lint_pass};
use rustc_span::source_map::{Span, Spanned}; use rustc_span::source_map::{Span, Spanned};
use rustc_span::{sym, Symbol}; use rustc_span::{sym, Symbol};
use semver::{Version, VersionReq};
use std::cmp::Ordering; use std::cmp::Ordering;
use std::collections::hash_map::Entry; use std::collections::hash_map::Entry;
use std::collections::Bound; use std::collections::Bound;
@@ -535,13 +535,13 @@ declare_clippy_lint! {
#[derive(Default)] #[derive(Default)]
pub struct Matches { pub struct Matches {
msrv: Option<VersionReq>, msrv: Option<RustcVersion>,
infallible_destructuring_match_linted: bool, infallible_destructuring_match_linted: bool,
} }
impl Matches { impl Matches {
#[must_use] #[must_use]
pub fn new(msrv: Option<VersionReq>) -> Self { pub fn new(msrv: Option<RustcVersion>) -> Self {
Self { Self {
msrv, msrv,
..Matches::default() ..Matches::default()
@@ -568,13 +568,7 @@ impl_lint_pass!(Matches => [
MATCH_SAME_ARMS, MATCH_SAME_ARMS,
]); ]);
const MATCH_LIKE_MATCHES_MACRO_MSRV: Version = Version { const MATCH_LIKE_MATCHES_MACRO_MSRV: RustcVersion = RustcVersion::new(1, 42, 0);
major: 1,
minor: 42,
patch: 0,
pre: Vec::new(),
build: Vec::new(),
};
impl<'tcx> LateLintPass<'tcx> for Matches { impl<'tcx> LateLintPass<'tcx> for Matches {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {

View File

@@ -18,6 +18,7 @@ use rustc_hir::{TraitItem, TraitItemKind};
use rustc_lint::{LateContext, LateLintPass, Lint, LintContext}; use rustc_lint::{LateContext, LateLintPass, Lint, LintContext};
use rustc_middle::lint::in_external_macro; use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::{self, TraitRef, Ty, TyS}; use rustc_middle::ty::{self, TraitRef, Ty, TyS};
use rustc_semver::RustcVersion;
use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_session::{declare_tool_lint, impl_lint_pass};
use rustc_span::source_map::Span; use rustc_span::source_map::Span;
use rustc_span::symbol::{sym, SymbolStr}; use rustc_span::symbol::{sym, SymbolStr};
@@ -33,7 +34,6 @@ use crate::utils::{
snippet_with_macro_callsite, span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then, sugg, snippet_with_macro_callsite, span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then, sugg,
walk_ptrs_ty_depth, SpanlessEq, walk_ptrs_ty_depth, SpanlessEq,
}; };
use semver::{Version, VersionReq};
declare_clippy_lint! { declare_clippy_lint! {
/// **What it does:** Checks for `.unwrap()` calls on `Option`s and on `Result`s. /// **What it does:** Checks for `.unwrap()` calls on `Option`s and on `Result`s.
@@ -1405,12 +1405,12 @@ declare_clippy_lint! {
} }
pub struct Methods { pub struct Methods {
msrv: Option<VersionReq>, msrv: Option<RustcVersion>,
} }
impl Methods { impl Methods {
#[must_use] #[must_use]
pub fn new(msrv: Option<VersionReq>) -> Self { pub fn new(msrv: Option<RustcVersion>) -> Self {
Self { msrv } Self { msrv }
} }
} }
@@ -3470,13 +3470,7 @@ fn lint_suspicious_map(cx: &LateContext<'_>, expr: &hir::Expr<'_>) {
); );
} }
const OPTION_AS_REF_DEREF_MSRV: Version = Version { const OPTION_AS_REF_DEREF_MSRV: RustcVersion = RustcVersion::new(1, 40, 0);
major: 1,
minor: 40,
patch: 0,
pre: Vec::new(),
build: Vec::new(),
};
/// lint use of `_.as_ref().map(Deref::deref)` for `Option`s /// lint use of `_.as_ref().map(Deref::deref)` for `Option`s
fn lint_option_as_ref_deref<'tcx>( fn lint_option_as_ref_deref<'tcx>(
@@ -3485,7 +3479,7 @@ fn lint_option_as_ref_deref<'tcx>(
as_ref_args: &[hir::Expr<'_>], as_ref_args: &[hir::Expr<'_>],
map_args: &[hir::Expr<'_>], map_args: &[hir::Expr<'_>],
is_mut: bool, is_mut: bool,
msrv: Option<&VersionReq>, msrv: Option<&RustcVersion>,
) { ) {
if !meets_msrv(msrv, &OPTION_AS_REF_DEREF_MSRV) { if !meets_msrv(msrv, &OPTION_AS_REF_DEREF_MSRV) {
return; return;

View File

@@ -51,6 +51,7 @@ use rustc_lint::{LateContext, Level, Lint, LintContext};
use rustc_middle::hir::map::Map; use rustc_middle::hir::map::Map;
use rustc_middle::ty::subst::{GenericArg, GenericArgKind}; use rustc_middle::ty::subst::{GenericArg, GenericArgKind};
use rustc_middle::ty::{self, layout::IntegerExt, Ty, TyCtxt, TypeFoldable}; use rustc_middle::ty::{self, layout::IntegerExt, Ty, TyCtxt, TypeFoldable};
use rustc_semver::RustcVersion;
use rustc_session::Session; use rustc_session::Session;
use rustc_span::hygiene::{ExpnKind, MacroKind}; use rustc_span::hygiene::{ExpnKind, MacroKind};
use rustc_span::source_map::original_sp; use rustc_span::source_map::original_sp;
@@ -59,13 +60,12 @@ use rustc_span::symbol::{self, kw, Symbol};
use rustc_span::{BytePos, Pos, Span, DUMMY_SP}; use rustc_span::{BytePos, Pos, Span, DUMMY_SP};
use rustc_target::abi::Integer; use rustc_target::abi::Integer;
use rustc_trait_selection::traits::query::normalize::AtExt; use rustc_trait_selection::traits::query::normalize::AtExt;
use semver::{Version, VersionReq};
use smallvec::SmallVec; use smallvec::SmallVec;
use crate::consts::{constant, Constant}; use crate::consts::{constant, Constant};
pub fn parse_msrv(msrv: &str, sess: Option<&Session>, span: Option<Span>) -> Option<VersionReq> { pub fn parse_msrv(msrv: &str, sess: Option<&Session>, span: Option<Span>) -> Option<RustcVersion> {
if let Ok(version) = VersionReq::parse(msrv) { if let Ok(version) = RustcVersion::parse(msrv) {
return Some(version); return Some(version);
} else if let Some(sess) = sess { } else if let Some(sess) = sess {
if let Some(span) = span { if let Some(span) = span {
@@ -75,8 +75,8 @@ pub fn parse_msrv(msrv: &str, sess: Option<&Session>, span: Option<Span>) -> Opt
None None
} }
pub fn meets_msrv(msrv: Option<&VersionReq>, lint_msrv: &Version) -> bool { pub fn meets_msrv(msrv: Option<&RustcVersion>, lint_msrv: &RustcVersion) -> bool {
msrv.map_or(true, |msrv| !msrv.matches(lint_msrv)) msrv.map_or(true, |msrv| msrv > lint_msrv)
} }
macro_rules! extract_msrv_attr { macro_rules! extract_msrv_attr {