Skip to content

Commit 33409fb

Browse files
make to_rustc_arg more generic & rename
(doesn't really change anything but i think it's fun)
1 parent 20e59b1 commit 33409fb

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

kani-driver/src/call_cargo.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::session::{
99
setup_cargo_command_inner,
1010
};
1111
use crate::util;
12-
use crate::util::args::{CargoArg, CommandWrapper as _, KaniArg, PassTo, to_rustc_arg};
12+
use crate::util::args::{CargoArg, CommandWrapper as _, KaniArg, PassTo, encode_as_rustc_arg};
1313
use anyhow::{Context, Result, bail};
1414
use cargo_metadata::diagnostic::{Diagnostic, DiagnosticLevel};
1515
use cargo_metadata::{
@@ -81,11 +81,13 @@ crate-type = ["lib"]
8181
// In theory, these could be passed just to the local crate rather than all crates,
8282
// but the `cargo build` command we use for building `std` doesn't allow you to pass `rustc`
8383
// arguments, so we have to pass them through the environment variable instead.
84-
rustc_args.push(to_rustc_arg(&self.kani_compiler_local_flags()));
84+
rustc_args.push(encode_as_rustc_arg(&self.kani_compiler_local_flags()));
8585

8686
// Ignore global assembly, since `compiler_builtins` has some.
87-
rustc_args
88-
.push(to_rustc_arg(&[KaniArg::from("--ignore-global-asm"), self.reachability_arg()]));
87+
rustc_args.push(encode_as_rustc_arg(&[
88+
KaniArg::from("--ignore-global-asm"),
89+
self.reachability_arg(),
90+
]));
8991

9092
let mut cargo_args: Vec<CargoArg> = vec!["build".into()];
9193
cargo_args.append(&mut cargo_config_args());
@@ -148,7 +150,7 @@ crate-type = ["lib"]
148150

149151
let lib_path = lib_folder().unwrap();
150152
let mut rustc_args = self.kani_rustc_flags(LibConfig::new(lib_path));
151-
rustc_args.push(to_rustc_arg(&self.kani_compiler_dependency_flags()));
153+
rustc_args.push(encode_as_rustc_arg(&self.kani_compiler_dependency_flags()));
152154

153155
let mut cargo_args: Vec<CargoArg> = vec!["rustc".into()];
154156
if let Some(path) = &self.args.cargo.manifest_path {
@@ -217,7 +219,7 @@ crate-type = ["lib"]
217219
.arg("--") // Add this delimiter so we start passing args to rustc and not Cargo
218220
.env("RUSTC", &self.kani_compiler)
219221
.pass_rustc_args(&rustc_args, PassTo::AllCrates)
220-
.pass_rustc_arg(to_rustc_arg(&kani_pkg_args), PassTo::OnlyLocalCrate)
222+
.pass_rustc_arg(encode_as_rustc_arg(&kani_pkg_args), PassTo::OnlyLocalCrate)
221223
// This is only required for stable but is a no-op for nightly channels
222224
.env("RUSTC_BOOTSTRAP", "1")
223225
.env("CARGO_TERM_PROGRESS_WHEN", "never");

kani-driver/src/call_single_file.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::path::{Path, PathBuf};
77
use std::process::Command;
88

99
use crate::session::{KaniSession, lib_folder};
10-
use crate::util::args::{CommandWrapper, KaniArg, PassTo, RustcArg, to_rustc_arg};
10+
use crate::util::args::{CommandWrapper, KaniArg, PassTo, RustcArg, encode_as_rustc_arg};
1111

1212
pub struct LibConfig {
1313
args: Vec<RustcArg>,
@@ -80,7 +80,7 @@ impl KaniSession {
8080
// rustc ones.
8181
let mut cmd = Command::new(&self.kani_compiler);
8282

83-
cmd.pass_rustc_arg(to_rustc_arg(&kani_args), PassTo::OnlyLocalCrate)
83+
cmd.pass_rustc_arg(encode_as_rustc_arg(&kani_args), PassTo::OnlyLocalCrate)
8484
.pass_rustc_args(&rustc_args, PassTo::OnlyLocalCrate);
8585

8686
// This is only required for stable but is a no-op for nightly channels

kani-driver/src/util.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,15 @@ pub(crate) mod args {
165165
/// reachability checks will force recompilation if they were disabled in previous build.
166166
/// For more details on this caching mechanism, see the
167167
/// [fingerprint documentation](https://github.com/rust-lang/cargo/blob/82c3bb79e3a19a5164e33819ef81bfc2c984bc56/src/cargo/core/compiler/fingerprint/mod.rs)
168-
pub fn to_rustc_arg(kani_args: &[KaniArg]) -> RustcArg {
168+
pub fn encode_as_rustc_arg<'a>(kani_args: impl IntoIterator<Item = &'a KaniArg>) -> RustcArg {
169169
format!(
170170
r#"-Cllvm-args={}"#,
171-
kani_args.iter().map(KaniArg::as_inner).cloned().collect::<Vec<String>>().join(" ")
171+
kani_args
172+
.into_iter()
173+
.map(KaniArg::as_inner)
174+
.cloned()
175+
.collect::<Vec<String>>()
176+
.join(" ")
172177
)
173178
.into()
174179
}

0 commit comments

Comments
 (0)