Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add '-A unused' before user-configured compile_flags #217

Merged
merged 3 commits into from Apr 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 24 additions & 12 deletions src/runtest.rs
Expand Up @@ -1112,22 +1112,22 @@ actual:\n\
}

fn compile_test(&self) -> ProcRes {
let mut rustc = self.make_compile_args(
&self.testpaths.file, TargetLocation::ThisFile(self.make_exe_name()));

rustc.arg("-L").arg(&self.aux_output_dir_name());

match self.config.mode {
let allow_unused = match self.config.mode {
CompileFail | Ui => {
// compile-fail and ui tests tend to have tons of unused code as
// it's just testing various pieces of the compile, but we don't
// want to actually assert warnings about all this code. Instead
// let's just ignore unused code warnings by defaults and tests
// can turn it back on if needed.
rustc.args(&["-A", "unused"]);
AllowUnused::Yes
}
_ => {}
}
_ => AllowUnused::No
};

let mut rustc = self.make_compile_args(
&self.testpaths.file, TargetLocation::ThisFile(self.make_exe_name()), allow_unused);

rustc.arg("-L").arg(&self.aux_output_dir_name());

self.compose_and_run_compiler(rustc, None)
}
Expand Down Expand Up @@ -1271,7 +1271,7 @@ actual:\n\
testpaths: &aux_testpaths,
revision: self.revision
};
let mut aux_rustc = aux_cx.make_compile_args(&aux_testpaths.file, aux_output);
let mut aux_rustc = aux_cx.make_compile_args(&aux_testpaths.file, aux_output, AllowUnused::No);

let crate_type = if aux_props.no_prefer_dynamic {
None
Expand Down Expand Up @@ -1367,7 +1367,7 @@ actual:\n\
result
}

fn make_compile_args(&self, input_file: &Path, output_file: TargetLocation) -> Command {
fn make_compile_args(&self, input_file: &Path, output_file: TargetLocation, allow_unused: AllowUnused) -> Command {
let mut rustc = Command::new(&self.config.rustc_path);
rustc.arg(input_file)
.arg("-L").arg(&self.config.build_base);
Expand Down Expand Up @@ -1462,6 +1462,12 @@ actual:\n\
}
}

// Add `-A unused` before `config` flags and in-test (`props`) flags, so that they can
// overwrite this.
if let AllowUnused::Yes = allow_unused {
rustc.args(&["-A", "unused"]);
}

if self.props.force_host {
rustc.args(self.split_maybe_args(&self.config.host_rustcflags));
} else {
Expand Down Expand Up @@ -1699,7 +1705,7 @@ actual:\n\

let output_file = TargetLocation::ThisDirectory(
self.output_base_name().parent().unwrap().to_path_buf());
let mut rustc = self.make_compile_args(&self.testpaths.file, output_file);
let mut rustc = self.make_compile_args(&self.testpaths.file, output_file, AllowUnused::No);
rustc.arg("-L").arg(aux_dir)
.arg("--emit=llvm-ir");

Expand Down Expand Up @@ -2343,6 +2349,7 @@ actual:\n\
let mut rustc = self.make_compile_args(
&self.testpaths.file.with_extension(UI_FIXED),
TargetLocation::ThisFile(self.make_exe_name()),
AllowUnused::No,
);
rustc.arg("-L").arg(&self.aux_output_dir_name());
let res = self.compose_and_run_compiler(rustc, None);
Expand Down Expand Up @@ -2667,6 +2674,11 @@ enum ExpectedLine<T: AsRef<str>> {
Text(T)
}

enum AllowUnused {
Yes,
No,
}

impl<T> fmt::Debug for ExpectedLine<T>
where
T: AsRef<str> + fmt::Debug
Expand Down