Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace rustc_semver with rustc_session::RustcVersion #13243

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion clippy_config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ edition = "2021"

[dependencies]
itertools = "0.12"
rustc-semver = "1.1"
serde = { version = "1.0", features = ["derive"] }
toml = "0.7.3"

Expand Down
1 change: 1 addition & 0 deletions clippy_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
)]

extern crate rustc_ast;
extern crate rustc_attr;
extern crate rustc_data_structures;
#[allow(unused_extern_crates)]
extern crate rustc_driver;
Expand Down
16 changes: 8 additions & 8 deletions clippy_config/src/msrvs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rustc_ast::Attribute;
use rustc_semver::RustcVersion;
use rustc_session::Session;
use rustc_attr::parse_version;
use rustc_session::{RustcVersion, Session};
use rustc_span::{sym, Symbol};
use serde::Deserialize;
use std::fmt;
Expand All @@ -10,7 +10,7 @@ macro_rules! msrv_aliases {
$($name:ident),* $(,)?
})*) => {
$($(
pub const $name: RustcVersion = RustcVersion::new($major, $minor, $patch);
pub const $name: RustcVersion = RustcVersion { major: $major, minor :$minor, patch: $patch };
)*)*
};
}
Expand Down Expand Up @@ -81,9 +81,9 @@ impl<'de> Deserialize<'de> for Msrv {
D: serde::Deserializer<'de>,
{
let v = String::deserialize(deserializer)?;
RustcVersion::parse(&v)
parse_version(Symbol::intern(&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"))
}
}

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

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

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> {
Expand All @@ -131,7 +131,7 @@ impl Msrv {
}

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);
}

Expand Down
1 change: 0 additions & 1 deletion clippy_lints/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ regex = { version = "1.5", optional = true }
unicode-normalization = "0.1"
unicode-script = { version = "0.5", default-features = false }
semver = "1.0"
rustc-semver = "1.1"
url = "2.2"

[dev-dependencies]
Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/approx_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use clippy_utils::diagnostics::span_lint_and_help;
use rustc_ast::ast::{FloatTy, LitFloatType, LitKind};
use rustc_hir::{Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_semver::RustcVersion;
use rustc_session::impl_lint_pass;
use rustc_session::{impl_lint_pass, RustcVersion};
use rustc_span::symbol;
use std::f64::consts as f64;

Expand Down
15 changes: 7 additions & 8 deletions clippy_lints/src/incompatible_msrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_hir::{Expr, ExprKind, HirId};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::TyCtxt;
use rustc_semver::RustcVersion;
use rustc_session::impl_lint_pass;
use rustc_session::{impl_lint_pass, RustcVersion};
use rustc_span::def_id::DefId;
use rustc_span::{ExpnKind, Span};

Expand Down Expand Up @@ -65,18 +64,18 @@ impl IncompatibleMsrv {
StabilityLevel::Stable {
since: StableSince::Version(version),
..
} => Some(RustcVersion::new(
version.major.into(),
version.minor.into(),
version.patch.into(),
)),
} => Some(version),
_ => None,
}) {
version
} else if let Some(parent_def_id) = tcx.opt_parent(def_id) {
self.get_def_id_version(tcx, parent_def_id)
} else {
RustcVersion::new(1, 0, 0)
RustcVersion {
major: 1,
minor: 0,
patch: 0,
}
};
self.is_above_msrv.insert(def_id, version);
version
Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/manual_retain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::ExprKind::Assign;
use rustc_lint::{LateContext, LateLintPass};
use rustc_semver::RustcVersion;
use rustc_session::impl_lint_pass;
use rustc_session::{impl_lint_pass, RustcVersion};
use rustc_span::symbol::sym;
use rustc_span::Span;

Expand Down
5 changes: 1 addition & 4 deletions clippy_lints/src/std_instead_of_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use rustc_hir::def_id::DefId;
use rustc_hir::{HirId, Path, PathSegment};
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_semver::RustcVersion;
use rustc_session::impl_lint_pass;
use rustc_span::symbol::kw;
use rustc_span::{sym, Span};
Expand Down Expand Up @@ -185,9 +184,7 @@ fn is_stable(cx: &LateContext<'_>, mut def_id: DefId, msrv: &Msrv) -> bool {
} = stability.level
{
let stable = match since {
StableSince::Version(v) => {
msrv.meets(RustcVersion::new(v.major.into(), v.minor.into(), v.patch.into()))
},
StableSince::Version(v) => msrv.meets(v),
StableSince::Current => msrv.current().is_none(),
StableSince::Err => false,
};
Expand Down
10 changes: 7 additions & 3 deletions clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use rustc_hir::intravisit::Visitor;
use rustc_hir::{ExprKind, HirId, Item, MutTy, Mutability, Path, TyKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::hir::nested_filter;
use rustc_semver::RustcVersion;
use rustc_session::impl_lint_pass;
use rustc_span::source_map::Spanned;
use rustc_span::symbol::Symbol;
Expand Down Expand Up @@ -92,7 +91,12 @@ pub struct LintWithoutLintPass {
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 {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
Expand Down Expand Up @@ -220,7 +224,7 @@ fn check_invalid_clippy_version_attribute(cx: &LateContext<'_>, item: &'_ Item<'
return;
}

if RustcVersion::parse(value.as_str()).is_err() {
if rustc_attr::parse_version(value).is_none() {
span_lint_and_help(
cx,
INVALID_CLIPPY_VERSION_ATTRIBUTE,
Expand Down
1 change: 0 additions & 1 deletion clippy_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ publish = false
clippy_config = { path = "../clippy_config" }
arrayvec = { version = "0.7", default-features = false }
itertools = "0.12"
rustc-semver = "1.1"
# FIXME(f16_f128): remove when no longer needed for parsing
rustc_apfloat = "0.2.0"

Expand Down
7 changes: 1 addition & 6 deletions clippy_utils/src/qualify_min_const_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use rustc_middle::mir::{
use rustc_middle::traits::{BuiltinImplSource, ImplSource, ObligationCause};
use rustc_middle::ty::adjustment::PointerCoercion;
use rustc_middle::ty::{self, GenericArgKind, TraitRef, Ty, TyCtxt};
use rustc_semver::RustcVersion;
use rustc_span::symbol::sym;
use rustc_span::Span;
use rustc_trait_selection::traits::{ObligationCtxt, SelectionContext};
Expand Down Expand Up @@ -391,11 +390,7 @@ fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: &Msrv) -> bool {
StableSince::Err => return false,
};

msrv.meets(RustcVersion::new(
u32::from(const_stab_rust_version.major),
u32::from(const_stab_rust_version.minor),
u32::from(const_stab_rust_version.patch),
))
msrv.meets(const_stab_rust_version)
} else {
// Unstable const fn with the feature enabled.
msrv.current().is_none()
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/min_rust_version_invalid_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mod multiple {
//~^ ERROR: `clippy::msrv` is defined multiple times

mod foo {
#![clippy::msrv = "1"]
#![clippy::msrv = "1.0"]
#![clippy::msrv = "1.0.0"]
//~^ ERROR: `clippy::msrv` is defined multiple times
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/min_rust_version_invalid_attr.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ LL | #![clippy::msrv = "1.0.0"]
note: first definition found here
--> 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