rustc: Disallow machine applicability in foreign macros
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
This commit is contained in:
parent
54628c8ea8
commit
ca762ba954
8 changed files with 217 additions and 35 deletions
|
|
@ -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 {
|
||||
|
|
@ -263,6 +264,7 @@ impl TestProps {
|
|||
normalize_stderr: vec![],
|
||||
failure_status: -1,
|
||||
run_rustfix: false,
|
||||
rustfix_only_machine_applicable: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -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 {
|
||||
|
|
@ -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")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue