Replace rustc_semver with rustc_session::RustcVersion

This commit is contained in:
Alex Macleod 2024-08-09 13:00:24 +00:00
parent cb806113e0
commit b32a0176fa
13 changed files with 30 additions and 39 deletions

View File

@ -7,7 +7,6 @@ edition = "2021"
[dependencies] [dependencies]
itertools = "0.12" itertools = "0.12"
rustc-semver = "1.1"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
toml = "0.7.3" toml = "0.7.3"

View File

@ -14,6 +14,7 @@
)] )]
extern crate rustc_ast; extern crate rustc_ast;
extern crate rustc_attr;
extern crate rustc_data_structures; extern crate rustc_data_structures;
#[allow(unused_extern_crates)] #[allow(unused_extern_crates)]
extern crate rustc_driver; extern crate rustc_driver;

View File

@ -1,6 +1,6 @@
use rustc_ast::Attribute; use rustc_ast::Attribute;
use rustc_semver::RustcVersion; use rustc_attr::parse_version;
use rustc_session::Session; use rustc_session::{RustcVersion, Session};
use rustc_span::{sym, Symbol}; use rustc_span::{sym, Symbol};
use serde::Deserialize; use serde::Deserialize;
use std::fmt; use std::fmt;
@ -10,7 +10,7 @@ macro_rules! msrv_aliases {
$($name:ident),* $(,)? $($name:ident),* $(,)?
})*) => { })*) => {
$($( $($(
pub const $name: RustcVersion = RustcVersion::new($major, $minor, $patch); pub const $name: RustcVersion = RustcVersion { major: $major, minor :$minor, patch: $patch };
)*)* )*)*
}; };
} }
@ -81,9 +81,9 @@ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
D: serde::Deserializer<'de>, D: serde::Deserializer<'de>,
{ {
let v = String::deserialize(deserializer)?; let v = String::deserialize(deserializer)?;
RustcVersion::parse(&v) parse_version(Symbol::intern(&v))
.map(|v| Msrv { stack: vec![v] }) .map(|v| Msrv { stack: vec![v] })
.map_err(|_| serde::de::Error::custom("not a valid Rust version")) .ok_or_else(|| serde::de::Error::custom("not a valid Rust version"))
} }
} }
@ -95,7 +95,7 @@ pub fn empty() -> Msrv {
pub fn read_cargo(&mut self, sess: &Session) { pub fn read_cargo(&mut self, sess: &Session) {
let cargo_msrv = std::env::var("CARGO_PKG_RUST_VERSION") let cargo_msrv = std::env::var("CARGO_PKG_RUST_VERSION")
.ok() .ok()
.and_then(|v| RustcVersion::parse(&v).ok()); .and_then(|v| parse_version(Symbol::intern(&v)));
match (self.current(), cargo_msrv) { match (self.current(), cargo_msrv) {
(None, Some(cargo_msrv)) => self.stack = vec![cargo_msrv], (None, Some(cargo_msrv)) => self.stack = vec![cargo_msrv],
@ -115,7 +115,7 @@ pub fn current(&self) -> Option<RustcVersion> {
} }
pub fn meets(&self, required: RustcVersion) -> bool { pub fn meets(&self, required: RustcVersion) -> bool {
self.current().map_or(true, |version| version.meets(required)) self.current().map_or(true, |msrv| msrv >= required)
} }
fn parse_attr(sess: &Session, attrs: &[Attribute]) -> Option<RustcVersion> { fn parse_attr(sess: &Session, attrs: &[Attribute]) -> Option<RustcVersion> {
@ -131,7 +131,7 @@ fn parse_attr(sess: &Session, attrs: &[Attribute]) -> Option<RustcVersion> {
} }
if let Some(msrv) = msrv_attr.value_str() { if let Some(msrv) = msrv_attr.value_str() {
if let Ok(version) = RustcVersion::parse(msrv.as_str()) { if let Some(version) = parse_version(msrv) {
return Some(version); return Some(version);
} }

View File

@ -25,7 +25,6 @@ regex = { version = "1.5", optional = true }
unicode-normalization = "0.1" unicode-normalization = "0.1"
unicode-script = { version = "0.5", default-features = false } unicode-script = { version = "0.5", default-features = false }
semver = "1.0" semver = "1.0"
rustc-semver = "1.1"
url = "2.2" url = "2.2"
[dev-dependencies] [dev-dependencies]

View File

@ -4,8 +4,7 @@
use rustc_ast::ast::{FloatTy, LitFloatType, LitKind}; use rustc_ast::ast::{FloatTy, LitFloatType, LitKind};
use rustc_hir::{Expr, ExprKind}; use rustc_hir::{Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_semver::RustcVersion; use rustc_session::{impl_lint_pass, RustcVersion};
use rustc_session::impl_lint_pass;
use rustc_span::symbol; use rustc_span::symbol;
use std::f64::consts as f64; use std::f64::consts as f64;

View File

@ -7,8 +7,7 @@
use rustc_hir::{Expr, ExprKind, HirId}; use rustc_hir::{Expr, ExprKind, HirId};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
use rustc_semver::RustcVersion; use rustc_session::{impl_lint_pass, RustcVersion};
use rustc_session::impl_lint_pass;
use rustc_span::def_id::DefId; use rustc_span::def_id::DefId;
use rustc_span::{ExpnKind, Span}; use rustc_span::{ExpnKind, Span};
@ -65,18 +64,18 @@ fn get_def_id_version(&mut self, tcx: TyCtxt<'_>, def_id: DefId) -> RustcVersion
StabilityLevel::Stable { StabilityLevel::Stable {
since: StableSince::Version(version), since: StableSince::Version(version),
.. ..
} => Some(RustcVersion::new( } => Some(version),
version.major.into(),
version.minor.into(),
version.patch.into(),
)),
_ => None, _ => None,
}) { }) {
version version
} else if let Some(parent_def_id) = tcx.opt_parent(def_id) { } else if let Some(parent_def_id) = tcx.opt_parent(def_id) {
self.get_def_id_version(tcx, parent_def_id) self.get_def_id_version(tcx, parent_def_id)
} else { } else {
RustcVersion::new(1, 0, 0) RustcVersion {
major: 1,
minor: 0,
patch: 0,
}
}; };
self.is_above_msrv.insert(def_id, version); self.is_above_msrv.insert(def_id, version);
version version

View File

@ -9,8 +9,7 @@
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::ExprKind::Assign; use rustc_hir::ExprKind::Assign;
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_semver::RustcVersion; use rustc_session::{impl_lint_pass, RustcVersion};
use rustc_session::impl_lint_pass;
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
use rustc_span::Span; use rustc_span::Span;

View File

@ -9,7 +9,6 @@
use rustc_hir::{HirId, Path, PathSegment}; use rustc_hir::{HirId, Path, PathSegment};
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_semver::RustcVersion;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::symbol::kw; use rustc_span::symbol::kw;
use rustc_span::{sym, Span}; use rustc_span::{sym, Span};
@ -185,9 +184,7 @@ fn is_stable(cx: &LateContext<'_>, mut def_id: DefId, msrv: &Msrv) -> bool {
} = stability.level } = stability.level
{ {
let stable = match since { let stable = match since {
StableSince::Version(v) => { StableSince::Version(v) => msrv.meets(v),
msrv.meets(RustcVersion::new(v.major.into(), v.minor.into(), v.patch.into()))
},
StableSince::Current => msrv.current().is_none(), StableSince::Current => msrv.current().is_none(),
StableSince::Err => false, StableSince::Err => false,
}; };

View File

@ -9,7 +9,6 @@
use rustc_hir::{ExprKind, HirId, Item, MutTy, Mutability, Path, TyKind}; use rustc_hir::{ExprKind, HirId, Item, MutTy, Mutability, Path, TyKind};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::hir::nested_filter; use rustc_middle::hir::nested_filter;
use rustc_semver::RustcVersion;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::source_map::Spanned; use rustc_span::source_map::Spanned;
use rustc_span::symbol::Symbol; use rustc_span::symbol::Symbol;
@ -92,7 +91,12 @@ pub struct LintWithoutLintPass {
registered_lints: FxHashSet<Symbol>, registered_lints: FxHashSet<Symbol>,
} }
impl_lint_pass!(LintWithoutLintPass => [DEFAULT_LINT, LINT_WITHOUT_LINT_PASS, INVALID_CLIPPY_VERSION_ATTRIBUTE, MISSING_CLIPPY_VERSION_ATTRIBUTE]); impl_lint_pass!(LintWithoutLintPass => [
DEFAULT_LINT,
LINT_WITHOUT_LINT_PASS,
INVALID_CLIPPY_VERSION_ATTRIBUTE,
MISSING_CLIPPY_VERSION_ATTRIBUTE,
]);
impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass { impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
@ -220,7 +224,7 @@ fn check_invalid_clippy_version_attribute(cx: &LateContext<'_>, item: &'_ Item<'
return; return;
} }
if RustcVersion::parse(value.as_str()).is_err() { if rustc_attr::parse_version(value).is_none() {
span_lint_and_help( span_lint_and_help(
cx, cx,
INVALID_CLIPPY_VERSION_ATTRIBUTE, INVALID_CLIPPY_VERSION_ATTRIBUTE,

View File

@ -8,7 +8,6 @@ publish = false
clippy_config = { path = "../clippy_config" } clippy_config = { path = "../clippy_config" }
arrayvec = { version = "0.7", default-features = false } arrayvec = { version = "0.7", default-features = false }
itertools = "0.12" itertools = "0.12"
rustc-semver = "1.1"
# FIXME(f16_f128): remove when no longer needed for parsing # FIXME(f16_f128): remove when no longer needed for parsing
rustc_apfloat = "0.2.0" rustc_apfloat = "0.2.0"

View File

@ -18,7 +18,6 @@
use rustc_middle::traits::{BuiltinImplSource, ImplSource, ObligationCause}; use rustc_middle::traits::{BuiltinImplSource, ImplSource, ObligationCause};
use rustc_middle::ty::adjustment::PointerCoercion; use rustc_middle::ty::adjustment::PointerCoercion;
use rustc_middle::ty::{self, GenericArgKind, TraitRef, Ty, TyCtxt}; use rustc_middle::ty::{self, GenericArgKind, TraitRef, Ty, TyCtxt};
use rustc_semver::RustcVersion;
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
use rustc_span::Span; use rustc_span::Span;
use rustc_trait_selection::traits::{ObligationCtxt, SelectionContext}; use rustc_trait_selection::traits::{ObligationCtxt, SelectionContext};
@ -391,11 +390,7 @@ fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: &Msrv) -> bool {
StableSince::Err => return false, StableSince::Err => return false,
}; };
msrv.meets(RustcVersion::new( msrv.meets(const_stab_rust_version)
u32::from(const_stab_rust_version.major),
u32::from(const_stab_rust_version.minor),
u32::from(const_stab_rust_version.patch),
))
} else { } else {
// Unstable const fn with the feature enabled. // Unstable const fn with the feature enabled.
msrv.current().is_none() msrv.current().is_none()

View File

@ -17,7 +17,7 @@ mod multiple {
//~^ ERROR: `clippy::msrv` is defined multiple times //~^ ERROR: `clippy::msrv` is defined multiple times
mod foo { mod foo {
#![clippy::msrv = "1"] #![clippy::msrv = "1.0"]
#![clippy::msrv = "1.0.0"] #![clippy::msrv = "1.0.0"]
//~^ ERROR: `clippy::msrv` is defined multiple times //~^ ERROR: `clippy::msrv` is defined multiple times
} }

View File

@ -31,8 +31,8 @@ LL | #![clippy::msrv = "1.0.0"]
note: first definition found here note: first definition found here
--> tests/ui/min_rust_version_invalid_attr.rs:20:9 --> tests/ui/min_rust_version_invalid_attr.rs:20:9
| |
LL | #![clippy::msrv = "1"] LL | #![clippy::msrv = "1.0"]
| ^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 4 previous errors error: aborting due to 4 previous errors