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