mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
Skip all cargo fix
that tends to write to registry cache.
This commit is contained in:
parent
790b01f1e7
commit
0565dafd87
@ -514,7 +514,7 @@ fn rustfix_crate(
|
||||
// We'll generate new errors below.
|
||||
file.errors_applying_fixes.clear();
|
||||
}
|
||||
rustfix_and_fix(&mut fixes, rustc, filename, args)?;
|
||||
rustfix_and_fix(&mut fixes, rustc, filename, args, config)?;
|
||||
let mut progress_yet_to_be_made = false;
|
||||
for (path, file) in fixes.files.iter_mut() {
|
||||
if file.errors_applying_fixes.is_empty() {
|
||||
@ -556,6 +556,7 @@ fn rustfix_and_fix(
|
||||
rustc: &ProcessBuilder,
|
||||
filename: &Path,
|
||||
args: &FixArgs,
|
||||
config: &Config,
|
||||
) -> Result<(), Error> {
|
||||
// If not empty, filter by these lints.
|
||||
// TODO: implement a way to specify this.
|
||||
@ -609,6 +610,8 @@ fn rustfix_and_fix(
|
||||
// Collect suggestions by file so we can apply them one at a time later.
|
||||
let mut file_map = HashMap::new();
|
||||
let mut num_suggestion = 0;
|
||||
// It's safe since we won't read any content under home dir.
|
||||
let home_path = config.home().as_path_unlocked();
|
||||
for suggestion in suggestions {
|
||||
trace!("suggestion");
|
||||
// Make sure we've got a file associated with this suggestion and all
|
||||
@ -627,6 +630,11 @@ fn rustfix_and_fix(
|
||||
continue;
|
||||
};
|
||||
|
||||
// Do not write into registry cache. See rust-lang/cargo#9857.
|
||||
if Path::new(&file_name).starts_with(home_path) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if !file_names.clone().all(|f| f == &file_name) {
|
||||
trace!("rejecting as it changes multiple files: {:?}", suggestion);
|
||||
continue;
|
||||
|
@ -1791,3 +1791,47 @@ fn non_edition_lint_migration() {
|
||||
// Check that it made the edition migration.
|
||||
assert!(contents.contains("from_utf8(crate::foo::FOO)"));
|
||||
}
|
||||
|
||||
// For rust-lang/cargo#9857
|
||||
#[cargo_test]
|
||||
fn fix_in_dependency() {
|
||||
Package::new("bar", "1.0.0")
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#[macro_export]
|
||||
macro_rules! m {
|
||||
($i:tt) => {
|
||||
let $i = 1;
|
||||
};
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.publish();
|
||||
|
||||
let p = project()
|
||||
.file(
|
||||
"Cargo.toml",
|
||||
r#"
|
||||
[package]
|
||||
name = "foo"
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
bar = "1.0"
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
pub fn foo() {
|
||||
bar::m!(abc);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.build();
|
||||
|
||||
p.cargo("fix --allow-no-vcs")
|
||||
.with_stderr_does_not_contain("[FIXED] [..]")
|
||||
.run();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user