Skip to content

Commit b32a017

Browse files
committed
Replace rustc_semver with rustc_session::RustcVersion
1 parent cb80611 commit b32a017

File tree

13 files changed

+30
-39
lines changed

13 files changed

+30
-39
lines changed

clippy_config/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ edition = "2021"
77

88
[dependencies]
99
itertools = "0.12"
10-
rustc-semver = "1.1"
1110
serde = { version = "1.0", features = ["derive"] }
1211
toml = "0.7.3"
1312

clippy_config/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
)]
1515

1616
extern crate rustc_ast;
17+
extern crate rustc_attr;
1718
extern crate rustc_data_structures;
1819
#[allow(unused_extern_crates)]
1920
extern crate rustc_driver;

clippy_config/src/msrvs.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_ast::Attribute;
2-
use rustc_semver::RustcVersion;
3-
use rustc_session::Session;
2+
use rustc_attr::parse_version;
3+
use rustc_session::{RustcVersion, Session};
44
use rustc_span::{sym, Symbol};
55
use serde::Deserialize;
66
use std::fmt;
@@ -10,7 +10,7 @@ macro_rules! msrv_aliases {
1010
$($name:ident),* $(,)?
1111
})*) => {
1212
$($(
13-
pub const $name: RustcVersion = RustcVersion::new($major, $minor, $patch);
13+
pub const $name: RustcVersion = RustcVersion { major: $major, minor :$minor, patch: $patch };
1414
)*)*
1515
};
1616
}
@@ -81,9 +81,9 @@ impl<'de> Deserialize<'de> for Msrv {
8181
D: serde::Deserializer<'de>,
8282
{
8383
let v = String::deserialize(deserializer)?;
84-
RustcVersion::parse(&v)
84+
parse_version(Symbol::intern(&v))
8585
.map(|v| Msrv { stack: vec![v] })
86-
.map_err(|_| serde::de::Error::custom("not a valid Rust version"))
86+
.ok_or_else(|| serde::de::Error::custom("not a valid Rust version"))
8787
}
8888
}
8989

@@ -95,7 +95,7 @@ impl Msrv {
9595
pub fn read_cargo(&mut self, sess: &Session) {
9696
let cargo_msrv = std::env::var("CARGO_PKG_RUST_VERSION")
9797
.ok()
98-
.and_then(|v| RustcVersion::parse(&v).ok());
98+
.and_then(|v| parse_version(Symbol::intern(&v)));
9999

100100
match (self.current(), cargo_msrv) {
101101
(None, Some(cargo_msrv)) => self.stack = vec![cargo_msrv],
@@ -115,7 +115,7 @@ impl Msrv {
115115
}
116116

117117
pub fn meets(&self, required: RustcVersion) -> bool {
118-
self.current().map_or(true, |version| version.meets(required))
118+
self.current().map_or(true, |msrv| msrv >= required)
119119
}
120120

121121
fn parse_attr(sess: &Session, attrs: &[Attribute]) -> Option<RustcVersion> {
@@ -131,7 +131,7 @@ impl Msrv {
131131
}
132132

133133
if let Some(msrv) = msrv_attr.value_str() {
134-
if let Ok(version) = RustcVersion::parse(msrv.as_str()) {
134+
if let Some(version) = parse_version(msrv) {
135135
return Some(version);
136136
}
137137

clippy_lints/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ regex = { version = "1.5", optional = true }
2525
unicode-normalization = "0.1"
2626
unicode-script = { version = "0.5", default-features = false }
2727
semver = "1.0"
28-
rustc-semver = "1.1"
2928
url = "2.2"
3029

3130
[dev-dependencies]

clippy_lints/src/approx_const.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ use clippy_utils::diagnostics::span_lint_and_help;
44
use rustc_ast::ast::{FloatTy, LitFloatType, LitKind};
55
use rustc_hir::{Expr, ExprKind};
66
use rustc_lint::{LateContext, LateLintPass};
7-
use rustc_semver::RustcVersion;
8-
use rustc_session::impl_lint_pass;
7+
use rustc_session::{impl_lint_pass, RustcVersion};
98
use rustc_span::symbol;
109
use std::f64::consts as f64;
1110

clippy_lints/src/incompatible_msrv.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ use rustc_data_structures::fx::FxHashMap;
77
use rustc_hir::{Expr, ExprKind, HirId};
88
use rustc_lint::{LateContext, LateLintPass};
99
use rustc_middle::ty::TyCtxt;
10-
use rustc_semver::RustcVersion;
11-
use rustc_session::impl_lint_pass;
10+
use rustc_session::{impl_lint_pass, RustcVersion};
1211
use rustc_span::def_id::DefId;
1312
use rustc_span::{ExpnKind, Span};
1413

@@ -65,18 +64,18 @@ impl IncompatibleMsrv {
6564
StabilityLevel::Stable {
6665
since: StableSince::Version(version),
6766
..
68-
} => Some(RustcVersion::new(
69-
version.major.into(),
70-
version.minor.into(),
71-
version.patch.into(),
72-
)),
67+
} => Some(version),
7368
_ => None,
7469
}) {
7570
version
7671
} else if let Some(parent_def_id) = tcx.opt_parent(def_id) {
7772
self.get_def_id_version(tcx, parent_def_id)
7873
} else {
79-
RustcVersion::new(1, 0, 0)
74+
RustcVersion {
75+
major: 1,
76+
minor: 0,
77+
patch: 0,
78+
}
8079
};
8180
self.is_above_msrv.insert(def_id, version);
8281
version

clippy_lints/src/manual_retain.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use rustc_hir as hir;
99
use rustc_hir::def_id::DefId;
1010
use rustc_hir::ExprKind::Assign;
1111
use rustc_lint::{LateContext, LateLintPass};
12-
use rustc_semver::RustcVersion;
13-
use rustc_session::impl_lint_pass;
12+
use rustc_session::{impl_lint_pass, RustcVersion};
1413
use rustc_span::symbol::sym;
1514
use rustc_span::Span;
1615

clippy_lints/src/std_instead_of_core.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use rustc_hir::def_id::DefId;
99
use rustc_hir::{HirId, Path, PathSegment};
1010
use rustc_lint::{LateContext, LateLintPass, LintContext};
1111
use rustc_middle::lint::in_external_macro;
12-
use rustc_semver::RustcVersion;
1312
use rustc_session::impl_lint_pass;
1413
use rustc_span::symbol::kw;
1514
use rustc_span::{sym, Span};
@@ -185,9 +184,7 @@ fn is_stable(cx: &LateContext<'_>, mut def_id: DefId, msrv: &Msrv) -> bool {
185184
} = stability.level
186185
{
187186
let stable = match since {
188-
StableSince::Version(v) => {
189-
msrv.meets(RustcVersion::new(v.major.into(), v.minor.into(), v.patch.into()))
190-
},
187+
StableSince::Version(v) => msrv.meets(v),
191188
StableSince::Current => msrv.current().is_none(),
192189
StableSince::Err => false,
193190
};

clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use rustc_hir::intravisit::Visitor;
99
use rustc_hir::{ExprKind, HirId, Item, MutTy, Mutability, Path, TyKind};
1010
use rustc_lint::{LateContext, LateLintPass};
1111
use rustc_middle::hir::nested_filter;
12-
use rustc_semver::RustcVersion;
1312
use rustc_session::impl_lint_pass;
1413
use rustc_span::source_map::Spanned;
1514
use rustc_span::symbol::Symbol;
@@ -92,7 +91,12 @@ pub struct LintWithoutLintPass {
9291
registered_lints: FxHashSet<Symbol>,
9392
}
9493

95-
impl_lint_pass!(LintWithoutLintPass => [DEFAULT_LINT, LINT_WITHOUT_LINT_PASS, INVALID_CLIPPY_VERSION_ATTRIBUTE, MISSING_CLIPPY_VERSION_ATTRIBUTE]);
94+
impl_lint_pass!(LintWithoutLintPass => [
95+
DEFAULT_LINT,
96+
LINT_WITHOUT_LINT_PASS,
97+
INVALID_CLIPPY_VERSION_ATTRIBUTE,
98+
MISSING_CLIPPY_VERSION_ATTRIBUTE,
99+
]);
96100

97101
impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass {
98102
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<'
220224
return;
221225
}
222226

223-
if RustcVersion::parse(value.as_str()).is_err() {
227+
if rustc_attr::parse_version(value).is_none() {
224228
span_lint_and_help(
225229
cx,
226230
INVALID_CLIPPY_VERSION_ATTRIBUTE,

clippy_utils/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ publish = false
88
clippy_config = { path = "../clippy_config" }
99
arrayvec = { version = "0.7", default-features = false }
1010
itertools = "0.12"
11-
rustc-semver = "1.1"
1211
# FIXME(f16_f128): remove when no longer needed for parsing
1312
rustc_apfloat = "0.2.0"
1413

0 commit comments

Comments
 (0)