Skip to content

Commit a529c44

Browse files
committed
Auto merge of rust-lang#13472 - GnomedDev:smaller-msrv, r=Jarcho
Optimise Msrv for common one item case Currently, `Msrv` is cloned around a lot in order to handle the `#[clippy::msrv]` attribute. This attribute, however, means `RustcVersion` will be heap allocated if there is only one source of an msrv (eg: `rust-version` in `Cargo.toml`). This PR optimizes for said case, while keeping the external interface the same by swapping the internal representation to `SmallVec<[RustcVersion; 2]>`. changelog: none
2 parents 73bad36 + d0b15f1 commit a529c44

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

clippy_config/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ extern crate rustc_driver;
2020
extern crate rustc_errors;
2121
extern crate rustc_session;
2222
extern crate rustc_span;
23+
extern crate smallvec;
2324

2425
mod conf;
2526
mod metadata;

clippy_config/src/msrvs.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use rustc_attr::parse_version;
33
use rustc_session::{RustcVersion, Session};
44
use rustc_span::{Symbol, sym};
55
use serde::Deserialize;
6+
use smallvec::{SmallVec, smallvec};
67
use std::fmt;
78

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

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

9596
impl Msrv {
9697
pub fn empty() -> Msrv {
97-
Msrv { stack: Vec::new() }
98+
Msrv { stack: SmallVec::new() }
9899
}
99100

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

105106
match (self.current(), cargo_msrv) {
106-
(None, Some(cargo_msrv)) => self.stack = vec![cargo_msrv],
107+
(None, Some(cargo_msrv)) => self.stack = smallvec![cargo_msrv],
107108
(Some(clippy_msrv), Some(cargo_msrv)) => {
108109
if clippy_msrv != cargo_msrv {
109110
sess.dcx().warn(format!(

0 commit comments

Comments
 (0)