Skip to content

Commit dea587a

Browse files
committed
Auto merge of #9938 - weihanglo:issue-9857, r=ehuss
Skip all `cargo fix` that tends to write to registry cache. Skip all `cargo fix` that tends to write to registry cache. This is a temporary hack for #9857. The real fix may need to touch rustc.
2 parents ec38c84 + 0565daf commit dea587a

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

src/cargo/ops/fix.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ fn rustfix_crate(
514514
// We'll generate new errors below.
515515
file.errors_applying_fixes.clear();
516516
}
517-
rustfix_and_fix(&mut fixes, rustc, filename, args)?;
517+
rustfix_and_fix(&mut fixes, rustc, filename, args, config)?;
518518
let mut progress_yet_to_be_made = false;
519519
for (path, file) in fixes.files.iter_mut() {
520520
if file.errors_applying_fixes.is_empty() {
@@ -556,6 +556,7 @@ fn rustfix_and_fix(
556556
rustc: &ProcessBuilder,
557557
filename: &Path,
558558
args: &FixArgs,
559+
config: &Config,
559560
) -> Result<(), Error> {
560561
// If not empty, filter by these lints.
561562
// TODO: implement a way to specify this.
@@ -609,6 +610,8 @@ fn rustfix_and_fix(
609610
// Collect suggestions by file so we can apply them one at a time later.
610611
let mut file_map = HashMap::new();
611612
let mut num_suggestion = 0;
613+
// It's safe since we won't read any content under home dir.
614+
let home_path = config.home().as_path_unlocked();
612615
for suggestion in suggestions {
613616
trace!("suggestion");
614617
// Make sure we've got a file associated with this suggestion and all
@@ -627,6 +630,11 @@ fn rustfix_and_fix(
627630
continue;
628631
};
629632

633+
// Do not write into registry cache. See rust-lang/cargo#9857.
634+
if Path::new(&file_name).starts_with(home_path) {
635+
continue;
636+
}
637+
630638
if !file_names.clone().all(|f| f == &file_name) {
631639
trace!("rejecting as it changes multiple files: {:?}", suggestion);
632640
continue;

tests/testsuite/fix.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,3 +1791,47 @@ fn non_edition_lint_migration() {
17911791
// Check that it made the edition migration.
17921792
assert!(contents.contains("from_utf8(crate::foo::FOO)"));
17931793
}
1794+
1795+
// For rust-lang/cargo#9857
1796+
#[cargo_test]
1797+
fn fix_in_dependency() {
1798+
Package::new("bar", "1.0.0")
1799+
.file(
1800+
"src/lib.rs",
1801+
r#"
1802+
#[macro_export]
1803+
macro_rules! m {
1804+
($i:tt) => {
1805+
let $i = 1;
1806+
};
1807+
}
1808+
"#,
1809+
)
1810+
.publish();
1811+
1812+
let p = project()
1813+
.file(
1814+
"Cargo.toml",
1815+
r#"
1816+
[package]
1817+
name = "foo"
1818+
version = "0.1.0"
1819+
1820+
[dependencies]
1821+
bar = "1.0"
1822+
"#,
1823+
)
1824+
.file(
1825+
"src/lib.rs",
1826+
r#"
1827+
pub fn foo() {
1828+
bar::m!(abc);
1829+
}
1830+
"#,
1831+
)
1832+
.build();
1833+
1834+
p.cargo("fix --allow-no-vcs")
1835+
.with_stderr_does_not_contain("[FIXED] [..]")
1836+
.run();
1837+
}

0 commit comments

Comments
 (0)