Skip to content

Commit

Permalink
rustc: Disallow machine applicability in foreign macros
Browse files Browse the repository at this point in the history
Recent changes to lints disallowed lints from being emitted against code located
in foreign macros, except for future-incompatible lints. For a future
incompatible lint, however, the automatic suggestions may not be applicable!

This commit updates this code path to force all applicability suggestions made
to foreign macros to never be `MachineApplicable`. This should avoid rustfix
actually attempting fixing these suggestions, causing non-compiling code to be
produced.

Closes rust-lang/cargo#5799
  • Loading branch information
alexcrichton committed Jul 30, 2018
1 parent 0a77579 commit 3882ccf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ pub struct TestProps {
pub normalize_stderr: Vec<(String, String)>,
pub failure_status: i32,
pub run_rustfix: bool,
pub rustfix_only_machine_applicable: bool,
}

impl TestProps {
Expand Down Expand Up @@ -263,6 +264,7 @@ impl TestProps {
normalize_stderr: vec![],
failure_status: -1,
run_rustfix: false,
rustfix_only_machine_applicable: false,
}
}

Expand Down Expand Up @@ -397,6 +399,11 @@ impl TestProps {
if !self.run_rustfix {
self.run_rustfix = config.parse_run_rustfix(ln);
}

if !self.rustfix_only_machine_applicable {
self.rustfix_only_machine_applicable =
config.parse_rustfix_only_machine_applicable(ln);
}
});

if self.failure_status == -1 {
Expand Down Expand Up @@ -663,6 +670,10 @@ impl Config {
self.parse_name_directive(line, "run-rustfix")
}

fn parse_rustfix_only_machine_applicable(&self, line: &str) -> bool {
self.parse_name_directive(line, "rustfix-only-machine-applicable")
}

fn parse_edition(&self, line: &str) -> Option<String> {
self.parse_name_value_directive(line, "edition")
}
Expand Down
8 changes: 6 additions & 2 deletions src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2624,7 +2624,11 @@ impl<'test> TestCx<'test> {
let suggestions = get_suggestions_from_json(
&proc_res.stderr,
&HashSet::new(),
Filter::Everything,
if self.props.rustfix_only_machine_applicable {
Filter::MachineApplicableOnly
} else {
Filter::Everything
},
).unwrap();
let fixed_code = apply_suggestions(&unfixed_code, &suggestions).expect(&format!(
"failed to apply suggestions for {:?} with rustfix",
Expand Down Expand Up @@ -2686,7 +2690,7 @@ impl<'test> TestCx<'test> {
if !res.status.success() {
self.fatal_proc_rec("failed to compile fixed code", &res);
}
if !res.stderr.is_empty() {
if !res.stderr.is_empty() && !self.props.rustfix_only_machine_applicable {
self.fatal_proc_rec("fixed code is still producing diagnostics", &res);
}
}
Expand Down

0 comments on commit 3882ccf

Please sign in to comment.