You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Auto merge of #13220 - ehuss:fix_in_dependency, r=weihanglo
Fix fix::fix_in_dependency to not rely on rustc
This changes the `fix::fix_in_dependency` test so that it does not rely on the behavior of rustc.
This test is checking the behavior when rustc includes a suggestion diagnostic that modifies a file in CARGO_HOME from a dependency. rustc should not be emitting suggestions that point outside of the current crate, but there are some known bugs where it does this. #9938 added a workaround for this to avoid writing to CARGO_HOME.
However, the current test was relying on one of those bugs in rustc to exhibit its behavior. rust-lang/rust#119204 is fixing that particular behavior. Instead of relying on issues in rustc, this PR changes the test so that the test creates a fake `rustc` executable that will emit a hard-coded JSON message that tells `cargo fix` to modify a file in CARGO_HOME. This should be stable as it is no longer relying on rustc.
Testing or validating this change is a little tricky. You have to essentially comment out [these three lines](https://github.com/rust-lang/cargo/blob/4f70d1781a2b2d3611087e1ee6e8096903c9b73a/src/cargo/ops/fix.rs#L654-L656) from the original #9938 change, and verify that the test fails (it says "Fixed" in the output). With those three lines in place, it should pass.
"message": "`#[warn(unused_variables)]` on by default",
1981
+
"code": null,
1982
+
"level": "note",
1983
+
"spans":
1984
+
[],
1985
+
"children":
1986
+
[],
1987
+
"rendered": null
1988
+
},
1989
+
{
1990
+
"message": "if this is intentional, prefix it with an underscore",
1991
+
"code": null,
1992
+
"level": "help",
1993
+
"spans":
1994
+
[
1995
+
{
1996
+
"file_name": "__BAR_PATH__/bar-1.0.0/src/lib.rs",
1997
+
"byte_start": 127,
1998
+
"byte_end": 129,
1999
+
"line_start": 5,
2000
+
"line_end": 5,
2001
+
"column_start": 29,
2002
+
"column_end": 31,
2003
+
"is_primary": true,
2004
+
"text":
2005
+
[
2006
+
{
2007
+
"text": " let $i = 1;",
2008
+
"highlight_start": 29,
2009
+
"highlight_end": 31
2010
+
}
2011
+
],
2012
+
"label": null,
2013
+
"suggested_replacement": "_abc",
2014
+
"suggestion_applicability": "MachineApplicable",
2015
+
"expansion": null
2016
+
}
2017
+
],
2018
+
"children":
2019
+
[],
2020
+
"rendered": null
2021
+
}
2022
+
],
2023
+
"rendered": "warning: unused variable: `abc`\n --> __BAR_PATH__/bar-1.0.0/src/lib.rs:5:29\n |\n5 | let $i = 1;\n | ^^ help: if this is intentional, prefix it with an underscore: `_abc`\n |\n = note: `#[warn(unused_variables)]` on by default\n\n"
2024
+
}"#.replace("\n", ""));
2025
+
}
2026
+
}
2027
+
"##.replace("__BAR_PATH__",&bar_path_str))
2028
+
.build();
2029
+
rustc.cargo("build").run();
2030
+
let rustc_bin = rustc.bin("rustc-replay");
1899
2031
1900
-
p.cargo("fix --allow-no-vcs")
1901
-
.with_stderr_does_not_contain("[FIXED] [..]")
2032
+
// The output here should not say `Fixed`.
2033
+
//
2034
+
// It is OK to compare the full diagnostic output here because the text is
2035
+
// hard-coded in rustc-replay. Normally tests should not be checking the
0 commit comments