@@ -46,9 +46,32 @@ fn config(mode: &str, dir: PathBuf) -> compiletest::Config {
4646 config. run_lib_path = rustc_lib_path ( ) ;
4747 config. compile_lib_path = rustc_lib_path ( ) ;
4848 }
49+
50+ // When we'll want to use `extern crate ..` for a dependency that is used
51+ // both by the crate and the compiler itself, we can't simply pass -L flags
52+ // as we'll get a duplicate matching versions. Instead, disambiguate with
53+ // `--extern dep=path`.
54+ // See https://github.com/rust-lang/rust-clippy/issues/4015.
55+ let needs_disambiguation = [ "serde" ] ;
56+ // This assumes that deps are compiled (they are for Cargo integration tests).
57+ let deps = std:: fs:: read_dir ( host_libs ( ) . join ( "deps" ) ) . unwrap ( ) ;
58+ let disambiguated = deps
59+ . filter_map ( |dep| {
60+ let path = dep. ok ( ) ?. path ( ) ;
61+ let name = path. file_name ( ) ?. to_string_lossy ( ) ;
62+ // NOTE: This only handles a single dep
63+ // https://github.com/laumann/compiletest-rs/issues/101
64+ needs_disambiguation
65+ . iter ( )
66+ . find ( |dep| name. starts_with ( & format ! ( "lib{}-" , dep) ) )
67+ . map ( |dep| format ! ( "--extern {}={}" , dep, path. display( ) ) )
68+ } )
69+ . collect :: < Vec < _ > > ( ) ;
70+
4971 config. target_rustcflags = Some ( format ! (
50- "-L {0} -L {0}/deps -Dwarnings -Zui-testing" ,
51- host_libs( ) . display( )
72+ "-L {0} -L {0}/deps -Dwarnings -Zui-testing {1}" ,
73+ host_libs( ) . display( ) ,
74+ disambiguated. join( " " )
5275 ) ) ;
5376
5477 config. mode = cfg_mode;
0 commit comments