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

@ -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;

View file

@ -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;
@ -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 };
)*)*
};
}
@ -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"))
}
}
@ -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],
@ -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> {
@ -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);
}