Skip to content

Commit

Permalink
Swap Msrv from Vec to SmallVec
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev committed Oct 27, 2024
1 parent 31f6679 commit d0b15f1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions clippy_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ extern crate rustc_driver;
extern crate rustc_errors;
extern crate rustc_session;
extern crate rustc_span;
extern crate smallvec;

mod conf;
mod metadata;
Expand Down
9 changes: 5 additions & 4 deletions clippy_config/src/msrvs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use rustc_attr::parse_version;
use rustc_session::{RustcVersion, Session};
use rustc_span::{Symbol, sym};
use serde::Deserialize;
use smallvec::{SmallVec, smallvec};
use std::fmt;

macro_rules! msrv_aliases {
Expand Down Expand Up @@ -67,7 +68,7 @@ msrv_aliases! {
/// Tracks the current MSRV from `clippy.toml`, `Cargo.toml` or set via `#[clippy::msrv]`
#[derive(Debug, Clone)]
pub struct Msrv {
stack: Vec<RustcVersion>,
stack: SmallVec<[RustcVersion; 2]>,
}

impl fmt::Display for Msrv {
Expand All @@ -87,14 +88,14 @@ impl<'de> Deserialize<'de> for Msrv {
{
let v = String::deserialize(deserializer)?;
parse_version(Symbol::intern(&v))
.map(|v| Msrv { stack: vec![v] })
.map(|v| Msrv { stack: smallvec![v] })
.ok_or_else(|| serde::de::Error::custom("not a valid Rust version"))
}
}

impl Msrv {
pub fn empty() -> Msrv {
Msrv { stack: Vec::new() }
Msrv { stack: SmallVec::new() }
}

pub fn read_cargo(&mut self, sess: &Session) {
Expand All @@ -103,7 +104,7 @@ impl Msrv {
.and_then(|v| parse_version(Symbol::intern(&v)));

match (self.current(), cargo_msrv) {
(None, Some(cargo_msrv)) => self.stack = vec![cargo_msrv],
(None, Some(cargo_msrv)) => self.stack = smallvec![cargo_msrv],
(Some(clippy_msrv), Some(cargo_msrv)) => {
if clippy_msrv != cargo_msrv {
sess.dcx().warn(format!(
Expand Down

0 comments on commit d0b15f1

Please sign in to comment.