File tree Expand file tree Collapse file tree 3 files changed +20
-7
lines changed Expand file tree Collapse file tree 3 files changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,6 @@ const FIX_ENV: &str = "__CARGO_FIX_PLZ";
22
22
const BROKEN_CODE_ENV : & str = "__CARGO_FIX_BROKEN_CODE" ;
23
23
const PREPARE_FOR_ENV : & str = "__CARGO_FIX_PREPARE_FOR" ;
24
24
const EDITION_ENV : & str = "__CARGO_FIX_EDITION" ;
25
-
26
25
const IDIOMS_ENV : & str = "__CARGO_FIX_IDIOMS" ;
27
26
28
27
pub struct FixOptions < ' a > {
@@ -258,9 +257,10 @@ fn rustfix_crate(
258
257
// process at a time. If two invocations concurrently check a crate then
259
258
// it's likely to corrupt it.
260
259
//
261
- // Currently we do this by assigning the name on our lock to the first
262
- // argument that looks like a Rust file.
263
- let _lock = LockServerClient :: lock ( & lock_addr. parse ( ) ?, filename) ?;
260
+ // Currently we do this by assigning the name on our lock to the manifest
261
+ // directory.
262
+ let dir = env:: var ( "CARGO_MANIFEST_DIR" ) . expect ( "CARGO_MANIFEST_DIR is missing?" ) ;
263
+ let _lock = LockServerClient :: lock ( & lock_addr. parse ( ) ?, dir) ?;
264
264
265
265
// Next up this is a bit suspicious, but we *iteratively* execute rustc and
266
266
// collect suggestions to feed to rustfix. Once we hit our limit of times to
Original file line number Diff line number Diff line change 14
14
use std:: collections:: HashMap ;
15
15
use std:: io:: { BufRead , BufReader , Read , Write } ;
16
16
use std:: net:: { SocketAddr , TcpListener , TcpStream } ;
17
- use std:: path:: Path ;
18
17
use std:: sync:: atomic:: { AtomicBool , Ordering } ;
19
18
use std:: sync:: { Arc , Mutex } ;
20
19
use std:: thread:: { self , JoinHandle } ;
@@ -156,11 +155,11 @@ impl Drop for LockServerStarted {
156
155
}
157
156
158
157
impl LockServerClient {
159
- pub fn lock ( addr : & SocketAddr , name : & Path ) -> Result < LockServerClient , Error > {
158
+ pub fn lock ( addr : & SocketAddr , name : impl AsRef < [ u8 ] > ) -> Result < LockServerClient , Error > {
160
159
let mut client = TcpStream :: connect ( & addr)
161
160
. with_context ( |_| "failed to connect to parent lock server" ) ?;
162
161
client
163
- . write_all ( name. display ( ) . to_string ( ) . as_bytes ( ) )
162
+ . write_all ( name. as_ref ( ) )
164
163
. and_then ( |_| client. write_all ( b"\n " ) )
165
164
. with_context ( |_| "failed to write to lock server" ) ?;
166
165
let mut buf = [ 0 ] ;
Original file line number Diff line number Diff line change @@ -1235,3 +1235,17 @@ fn fix_to_broken_code() {
1235
1235
"pub fn foo() { let x = 3; drop(x); }"
1236
1236
) ;
1237
1237
}
1238
+
1239
+ #[ test]
1240
+ fn fix_with_common ( ) {
1241
+ let p = project ( )
1242
+ . file ( "src/lib.rs" , "" )
1243
+ . file ( "tests/t1.rs" , "mod common; #[test] fn t1() { common::try(); }" )
1244
+ . file ( "tests/t2.rs" , "mod common; #[test] fn t2() { common::try(); }" )
1245
+ . file ( "tests/common/mod.rs" , "pub fn try() {}" )
1246
+ . build ( ) ;
1247
+
1248
+ p. cargo ( "fix --edition --allow-no-vcs" ) . run ( ) ;
1249
+
1250
+ assert_eq ! ( p. read_file( "tests/common/mod.rs" ) , "pub fn r#try() {}" ) ;
1251
+ }
You can’t perform that action at this time.
0 commit comments