@@ -1872,68 +1872,75 @@ pub fn extern_args(
18721872 let no_embed_metadata = build_runner. bcx . gctx . cli_unstable ( ) . no_embed_metadata ;
18731873
18741874 // Closure to add one dependency to `result`.
1875- let mut link_to =
1876- |dep : & UnitDep , extern_crate_name : InternedString , noprelude : bool | -> CargoResult < ( ) > {
1877- let mut value = OsString :: new ( ) ;
1878- let mut opts = Vec :: new ( ) ;
1879- let is_public_dependency_enabled = unit
1880- . pkg
1881- . manifest ( )
1882- . unstable_features ( )
1883- . require ( Feature :: public_dependency ( ) )
1884- . is_ok ( )
1885- || build_runner. bcx . gctx . cli_unstable ( ) . public_dependency ;
1886- if !dep. public && unit. target . is_lib ( ) && is_public_dependency_enabled {
1887- opts. push ( "priv" ) ;
1888- * unstable_opts = true ;
1889- }
1890- if noprelude {
1891- opts. push ( "noprelude" ) ;
1892- * unstable_opts = true ;
1893- }
1894- if !opts. is_empty ( ) {
1895- value. push ( opts. join ( "," ) ) ;
1896- value. push ( ":" ) ;
1897- }
1898- value. push ( extern_crate_name. as_str ( ) ) ;
1899- value. push ( "=" ) ;
1900-
1901- let mut pass = |file| {
1902- let mut value = value. clone ( ) ;
1903- value. push ( file) ;
1904- result. push ( OsString :: from ( "--extern" ) ) ;
1905- result. push ( value) ;
1906- } ;
1875+ let mut link_to = |dep : & UnitDep ,
1876+ extern_crate_name : InternedString ,
1877+ noprelude : bool ,
1878+ nounused : bool |
1879+ -> CargoResult < ( ) > {
1880+ let mut value = OsString :: new ( ) ;
1881+ let mut opts = Vec :: new ( ) ;
1882+ let is_public_dependency_enabled = unit
1883+ . pkg
1884+ . manifest ( )
1885+ . unstable_features ( )
1886+ . require ( Feature :: public_dependency ( ) )
1887+ . is_ok ( )
1888+ || build_runner. bcx . gctx . cli_unstable ( ) . public_dependency ;
1889+ if !dep. public && unit. target . is_lib ( ) && is_public_dependency_enabled {
1890+ opts. push ( "priv" ) ;
1891+ * unstable_opts = true ;
1892+ }
1893+ if noprelude {
1894+ opts. push ( "noprelude" ) ;
1895+ * unstable_opts = true ;
1896+ }
1897+ if nounused {
1898+ opts. push ( "nounused" ) ;
1899+ * unstable_opts = true ;
1900+ }
1901+ if !opts. is_empty ( ) {
1902+ value. push ( opts. join ( "," ) ) ;
1903+ value. push ( ":" ) ;
1904+ }
1905+ value. push ( extern_crate_name. as_str ( ) ) ;
1906+ value. push ( "=" ) ;
1907+
1908+ let mut pass = |file| {
1909+ let mut value = value. clone ( ) ;
1910+ value. push ( file) ;
1911+ result. push ( OsString :: from ( "--extern" ) ) ;
1912+ result. push ( value) ;
1913+ } ;
19071914
1908- let outputs = build_runner. outputs ( & dep. unit ) ?;
1915+ let outputs = build_runner. outputs ( & dep. unit ) ?;
19091916
1910- if build_runner. only_requires_rmeta ( unit, & dep. unit ) || dep. unit . mode . is_check ( ) {
1911- // Example: rlib dependency for an rlib, rmeta is all that is required.
1912- let output = outputs
1913- . iter ( )
1914- . find ( |output| output. flavor == FileFlavor :: Rmeta )
1915- . expect ( "failed to find rmeta dep for pipelined dep" ) ;
1916- pass ( & output. path ) ;
1917- } else {
1918- // Example: a bin needs `rlib` for dependencies, it cannot use rmeta.
1919- for output in outputs. iter ( ) {
1920- if output. flavor == FileFlavor :: Linkable {
1921- pass ( & output. path ) ;
1922- }
1923- // If we use -Zembed-metadata=no, we also need to pass the path to the
1924- // corresponding .rmeta file to the linkable artifact, because the
1925- // normal dependency (rlib) doesn't contain the full metadata.
1926- else if no_embed_metadata && output. flavor == FileFlavor :: Rmeta {
1927- pass ( & output. path ) ;
1928- }
1917+ if build_runner. only_requires_rmeta ( unit, & dep. unit ) || dep. unit . mode . is_check ( ) {
1918+ // Example: rlib dependency for an rlib, rmeta is all that is required.
1919+ let output = outputs
1920+ . iter ( )
1921+ . find ( |output| output. flavor == FileFlavor :: Rmeta )
1922+ . expect ( "failed to find rmeta dep for pipelined dep" ) ;
1923+ pass ( & output. path ) ;
1924+ } else {
1925+ // Example: a bin needs `rlib` for dependencies, it cannot use rmeta.
1926+ for output in outputs. iter ( ) {
1927+ if output. flavor == FileFlavor :: Linkable {
1928+ pass ( & output. path ) ;
1929+ }
1930+ // If we use -Zembed-metadata=no, we also need to pass the path to the
1931+ // corresponding .rmeta file to the linkable artifact, because the
1932+ // normal dependency (rlib) doesn't contain the full metadata.
1933+ else if no_embed_metadata && output. flavor == FileFlavor :: Rmeta {
1934+ pass ( & output. path ) ;
19291935 }
19301936 }
1931- Ok ( ( ) )
1932- } ;
1937+ }
1938+ Ok ( ( ) )
1939+ } ;
19331940
19341941 for dep in deps {
19351942 if dep. unit . target . is_linkable ( ) && !dep. unit . mode . is_doc ( ) {
1936- link_to ( dep, dep. extern_crate_name , dep. noprelude ) ?;
1943+ link_to ( dep, dep. extern_crate_name , dep. noprelude , dep . nounused ) ?;
19371944 }
19381945 }
19391946 if unit. target . proc_macro ( ) {
0 commit comments