Skip to content

Commit af80477

Browse files
committed
Refactor StableMir to avoid some clones.
Pass `args` to `run` instead of storing it in a field. This avoids the need to clone it within `run`. Also, change `args` from `Vec<String>` to `&[String]`, avoiding the need for some vecs and clones.
1 parent 055a27d commit af80477

23 files changed

+43
-42
lines changed

compiler/rustc_smir/src/rustc_internal/mod.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ where
256256
/// // Your code goes in here.
257257
/// # ControlFlow::Continue(())
258258
/// }
259-
/// # let args = vec!["--verbose".to_string()];
259+
/// # let args = &["--verbose".to_string()];
260260
/// let result = run!(args, analyze_code);
261261
/// # assert_eq!(result, Err(CompilerError::Skipped))
262262
/// # }
@@ -278,7 +278,7 @@ where
278278
/// // Your code goes in here.
279279
/// # ControlFlow::Continue(())
280280
/// }
281-
/// # let args = vec!["--verbose".to_string()];
281+
/// # let args = &["--verbose".to_string()];
282282
/// # let extra_args = vec![];
283283
/// let result = run!(args, || analyze_code(extra_args));
284284
/// # assert_eq!(result, Err(CompilerError::Skipped))
@@ -340,7 +340,6 @@ macro_rules! run_driver {
340340
C: Send,
341341
F: FnOnce($(optional!($with_tcx TyCtxt))?) -> ControlFlow<B, C> + Send,
342342
{
343-
args: Vec<String>,
344343
callback: Option<F>,
345344
result: Option<ControlFlow<B, C>>,
346345
}
@@ -352,14 +351,14 @@ macro_rules! run_driver {
352351
F: FnOnce($(optional!($with_tcx TyCtxt))?) -> ControlFlow<B, C> + Send,
353352
{
354353
/// Creates a new `StableMir` instance, with given test_function and arguments.
355-
pub fn new(args: Vec<String>, callback: F) -> Self {
356-
StableMir { args, callback: Some(callback), result: None }
354+
pub fn new(callback: F) -> Self {
355+
StableMir { callback: Some(callback), result: None }
357356
}
358357

359358
/// Runs the compiler against given target and tests it with `test_function`
360-
pub fn run(&mut self) -> Result<C, CompilerError<B>> {
359+
pub fn run(&mut self, args: &[String]) -> Result<C, CompilerError<B>> {
361360
let compiler_result = rustc_driver::catch_fatal_errors(|| -> interface::Result::<()> {
362-
run_compiler(&self.args.clone(), self);
361+
run_compiler(&args, self);
363362
Ok(())
364363
});
365364
match (compiler_result, self.result.take()) {
@@ -409,7 +408,7 @@ macro_rules! run_driver {
409408
}
410409
}
411410

412-
StableMir::new($args, $callback).run()
411+
StableMir::new($callback).run($args)
413412
}};
414413
}
415414

tests/ui-fulldeps/stable-mir/check_abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ fn get_item<'a>(
145145
fn main() {
146146
let path = "alloc_input.rs";
147147
generate_input(&path).unwrap();
148-
let args = vec![
148+
let args = &[
149149
"rustc".to_string(),
150150
"--crate-type=lib".to_string(),
151151
"--crate-name".to_string(),

tests/ui-fulldeps/stable-mir/check_allocation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ fn get_item<'a>(
219219
fn main() {
220220
let path = "alloc_input.rs";
221221
generate_input(&path).unwrap();
222-
let args = vec![
222+
let args = &[
223223
"rustc".to_string(),
224224
"--edition=2021".to_string(),
225225
"--crate-name".to_string(),

tests/ui-fulldeps/stable-mir/check_assoc_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn check_items<T: CrateDef>(items: &[T], expected: &[&str]) {
8585
fn main() {
8686
let path = "assoc_items.rs";
8787
generate_input(&path).unwrap();
88-
let args = vec![
88+
let args = &[
8989
"rustc".to_string(),
9090
"--crate-type=lib".to_string(),
9191
"--crate-name".to_string(),

tests/ui-fulldeps/stable-mir/check_attribute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fn get_item<'a>(
5757
fn main() {
5858
let path = "attribute_input.rs";
5959
generate_input(&path).unwrap();
60-
let args = vec![
60+
let args = &[
6161
"rustc".to_string(),
6262
"--crate-type=lib".to_string(),
6363
"--crate-name".to_string(),

tests/ui-fulldeps/stable-mir/check_binop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl<'a> MirVisitor for Visitor<'a> {
8181
fn main() {
8282
let path = "binop_input.rs";
8383
generate_input(&path).unwrap();
84-
let args = vec!["rustc".to_string(), "--crate-type=lib".to_string(), path.to_string()];
84+
let args = &["rustc".to_string(), "--crate-type=lib".to_string(), path.to_string()];
8585
run!(args, test_binops).unwrap();
8686
}
8787

tests/ui-fulldeps/stable-mir/check_crate_defs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fn contains<T: CrateDef + std::fmt::Debug>(items: &[T], expected: &[&str]) {
8484
fn main() {
8585
let path = "crate_definitions.rs";
8686
generate_input(&path).unwrap();
87-
let args = vec![
87+
let args = &[
8888
"rustc".to_string(),
8989
"--crate-type=lib".to_string(),
9090
"--crate-name".to_string(),

tests/ui-fulldeps/stable-mir/check_def_ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fn check_fn_def(ty: Ty) {
7676
fn main() {
7777
let path = "defs_ty_input.rs";
7878
generate_input(&path).unwrap();
79-
let args = vec![
79+
let args = &[
8080
"rustc".to_string(),
8181
"-Cpanic=abort".to_string(),
8282
"--crate-name".to_string(),

tests/ui-fulldeps/stable-mir/check_defs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ fn get_instances(body: mir::Body) -> Vec<Instance> {
112112
fn main() {
113113
let path = "defs_input.rs";
114114
generate_input(&path).unwrap();
115-
let args = vec![
115+
let args = &[
116116
"rustc".to_string(),
117117
"-Cpanic=abort".to_string(),
118118
"--crate-name".to_string(),

tests/ui-fulldeps/stable-mir/check_foreign.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn test_foreign() -> ControlFlow<()> {
5858
fn main() {
5959
let path = "foreign_input.rs";
6060
generate_input(&path).unwrap();
61-
let args = vec![
61+
let args = &[
6262
"rustc".to_string(),
6363
"-Cpanic=abort".to_string(),
6464
"--crate-type=lib".to_string(),

0 commit comments

Comments
 (0)