Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo fix: fix targets with shared sources. #6434

Merged
merged 1 commit into from
Dec 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/cargo/ops/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const FIX_ENV: &str = "__CARGO_FIX_PLZ";
const BROKEN_CODE_ENV: &str = "__CARGO_FIX_BROKEN_CODE";
const PREPARE_FOR_ENV: &str = "__CARGO_FIX_PREPARE_FOR";
const EDITION_ENV: &str = "__CARGO_FIX_EDITION";

const IDIOMS_ENV: &str = "__CARGO_FIX_IDIOMS";

pub struct FixOptions<'a> {
Expand Down Expand Up @@ -258,9 +257,10 @@ fn rustfix_crate(
// process at a time. If two invocations concurrently check a crate then
// it's likely to corrupt it.
//
// Currently we do this by assigning the name on our lock to the first
// argument that looks like a Rust file.
let _lock = LockServerClient::lock(&lock_addr.parse()?, filename)?;
// Currently we do this by assigning the name on our lock to the manifest
// directory.
let dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR is missing?");
let _lock = LockServerClient::lock(&lock_addr.parse()?, dir)?;

// Next up this is a bit suspicious, but we *iteratively* execute rustc and
// collect suggestions to feed to rustfix. Once we hit our limit of times to
Expand Down
5 changes: 2 additions & 3 deletions src/cargo/util/lockserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use std::collections::HashMap;
use std::io::{BufRead, BufReader, Read, Write};
use std::net::{SocketAddr, TcpListener, TcpStream};
use std::path::Path;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex};
use std::thread::{self, JoinHandle};
Expand Down Expand Up @@ -156,11 +155,11 @@ impl Drop for LockServerStarted {
}

impl LockServerClient {
pub fn lock(addr: &SocketAddr, name: &Path) -> Result<LockServerClient, Error> {
pub fn lock(addr: &SocketAddr, name: impl AsRef<[u8]>) -> Result<LockServerClient, Error> {
let mut client = TcpStream::connect(&addr)
.with_context(|_| "failed to connect to parent lock server")?;
client
.write_all(name.display().to_string().as_bytes())
.write_all(name.as_ref())
.and_then(|_| client.write_all(b"\n"))
.with_context(|_| "failed to write to lock server")?;
let mut buf = [0];
Expand Down
14 changes: 14 additions & 0 deletions tests/testsuite/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1235,3 +1235,17 @@ fn fix_to_broken_code() {
"pub fn foo() { let x = 3; drop(x); }"
);
}

#[test]
fn fix_with_common() {
let p = project()
.file("src/lib.rs", "")
.file("tests/t1.rs", "mod common; #[test] fn t1() { common::try(); }")
.file("tests/t2.rs", "mod common; #[test] fn t2() { common::try(); }")
.file("tests/common/mod.rs", "pub fn try() {}")
.build();

p.cargo("fix --edition --allow-no-vcs").run();

assert_eq!(p.read_file("tests/common/mod.rs"), "pub fn r#try() {}");
}