Skip to content

Commit a1f5dd2

Browse files
fix(workspace): specify RUSTFLAGS through cargo and fix linter warnings
Wihtout it, the .vscode/settings.json was setting a `RUSTFLAGS` value that was not shared by the cargo cli version, causing unneccessary rebuilds between `cargo build` and an editor save.
1 parent 280d7a0 commit a1f5dd2

File tree

7 files changed

+12
-14
lines changed

7 files changed

+12
-14
lines changed

.cargo/config.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build]
2+
rustflags = ["--cfg", "codspeed"]

.vscode/settings.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
{
2-
"rust-analyzer.cargo.extraEnv": {
3-
"RUSTFLAGS": "--cfg codspeed"
4-
},
52
"rust-analyzer.cargo.features": "all",
63
"editor.formatOnSave": true,
74
"rust-analyzer.checkOnSave": true,

crates/cargo-codspeed/src/app.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,8 @@ pub fn run(args: impl Iterator<Item = OsString>) -> Result<()> {
7878
features,
7979
profile,
8080
} => {
81-
let features = features.map(|f| {
82-
f.split(|c| c == ' ' || c == ',')
83-
.map(|s| s.to_string())
84-
.collect_vec()
85-
});
81+
let features =
82+
features.map(|f| f.split([' ', ',']).map(|s| s.to_string()).collect_vec());
8683
let packages = Packages::from_flags(
8784
package_selection.workspace,
8885
package_selection.exclude,

crates/cargo-codspeed/src/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub fn build_benches(
123123
format!("{} {}", bench.package.name(), bench.target.name()),
124124
&style::ACTIVE,
125125
)?;
126-
let is_root_package = ws.current_opt().map_or(false, |p| p == bench.package);
126+
let is_root_package = ws.current_opt() == Some(bench.package);
127127
let benches_names = vec![bench.target.name()];
128128
let compile_opts = get_compile_options(
129129
context,

crates/cargo-codspeed/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use std::{env::args_os, process::exit};
1010
fn main() {
1111
let mut args_vec = args_os().collect_vec();
1212

13-
// let mut args_iter = args_os().into_iter();
1413
if args_vec.len() >= 2 && args_vec[1] == "codspeed" {
1514
args_vec[1] = "cargo codspeed".into();
1615
args_vec = args_vec.into_iter().skip(1).collect_vec();

crates/criterion_compat/src/compat/bencher.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct Bencher<'a> {
1515
_marker: std::marker::PhantomData<&'a ()>,
1616
}
1717

18-
impl<'a> Bencher<'a> {
18+
impl Bencher<'_> {
1919
pub fn new(codspeed: Rc<RefCell<CodSpeed>>, uri: String) -> Self {
2020
Bencher {
2121
codspeed,
@@ -123,7 +123,10 @@ impl<'a> Bencher<'a> {
123123
drop(black_box(input));
124124
}
125125
}
126+
}
126127

128+
#[cfg(feature = "async")]
129+
impl<'a> Bencher<'a> {
127130
#[cfg(feature = "async")]
128131
pub fn to_async<'b, A: AsyncExecutor>(&'b mut self, runner: A) -> AsyncBencher<'a, 'b, A> {
129132
AsyncBencher { b: self, runner }
@@ -137,7 +140,7 @@ pub struct AsyncBencher<'a, 'b, A: AsyncExecutor> {
137140
}
138141

139142
#[cfg(feature = "async")]
140-
impl<'a, 'b, A: AsyncExecutor> AsyncBencher<'a, 'b, A> {
143+
impl<A: AsyncExecutor> AsyncBencher<'_, '_, A> {
141144
#[allow(clippy::await_holding_refcell_ref)]
142145
#[inline(never)]
143146
pub fn iter<O, R, F>(&mut self, mut routine: R)

crates/criterion_compat/src/compat/group.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub struct BenchmarkGroup<'a, M: Measurement = WallTime> {
1717
_marker: PhantomData<&'a M>,
1818
}
1919

20-
impl<'a, M: Measurement> BenchmarkGroup<'a, M> {
20+
impl<M: Measurement> BenchmarkGroup<'_, M> {
2121
pub fn new(criterion: &mut Criterion<M>, group_name: String) -> BenchmarkGroup<M> {
2222
BenchmarkGroup::<M> {
2323
codspeed: criterion
@@ -79,7 +79,7 @@ impl<'a, M: Measurement> BenchmarkGroup<'a, M> {
7979

8080
// Dummy methods
8181
#[allow(unused_variables)]
82-
impl<'a, M: Measurement> BenchmarkGroup<'a, M> {
82+
impl<M: Measurement> BenchmarkGroup<'_, M> {
8383
pub fn sample_size(&mut self, n: usize) -> &mut Self {
8484
self
8585
}

0 commit comments

Comments
 (0)