Add support for nounused
--extern flag
This adds `nounused` to the set of extern flags: `--extern nounused:core=/path/to/core/libcore.rlib`. The effect of this flag is to suppress `unused-crate-dependencies` warnings relating to the crate.
This commit is contained in:
parent
b21759f550
commit
9102edf208
@ -66,6 +66,7 @@ where
|
|||||||
location: ExternLocation::ExactPaths(locations),
|
location: ExternLocation::ExactPaths(locations),
|
||||||
is_private_dep: false,
|
is_private_dep: false,
|
||||||
add_prelude: true,
|
add_prelude: true,
|
||||||
|
nounused_dep: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -907,6 +907,10 @@ impl<'a> CrateLoader<'a> {
|
|||||||
// Don't worry about pathless `--extern foo` sysroot references
|
// Don't worry about pathless `--extern foo` sysroot references
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if entry.nounused_dep {
|
||||||
|
// We're not worried about this one
|
||||||
|
continue;
|
||||||
|
}
|
||||||
let name_interned = Symbol::intern(name);
|
let name_interned = Symbol::intern(name);
|
||||||
if self.used_extern_options.contains(&name_interned) {
|
if self.used_extern_options.contains(&name_interned) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -474,6 +474,11 @@ pub struct ExternEntry {
|
|||||||
/// This can be disabled with the `noprelude` option like
|
/// This can be disabled with the `noprelude` option like
|
||||||
/// `--extern noprelude:name`.
|
/// `--extern noprelude:name`.
|
||||||
pub add_prelude: bool,
|
pub add_prelude: bool,
|
||||||
|
/// The extern entry shouldn't be considered for unused dependency warnings.
|
||||||
|
///
|
||||||
|
/// `--extern nounused:std=/path/to/lib/libstd.rlib`. This is used to
|
||||||
|
/// suppress `unused-crate-dependencies` warnings.
|
||||||
|
pub nounused_dep: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
@ -512,7 +517,7 @@ impl Externs {
|
|||||||
|
|
||||||
impl ExternEntry {
|
impl ExternEntry {
|
||||||
fn new(location: ExternLocation) -> ExternEntry {
|
fn new(location: ExternLocation) -> ExternEntry {
|
||||||
ExternEntry { location, is_private_dep: false, add_prelude: false }
|
ExternEntry { location, is_private_dep: false, add_prelude: false, nounused_dep: false }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn files(&self) -> Option<impl Iterator<Item = &CanonicalizedPath>> {
|
pub fn files(&self) -> Option<impl Iterator<Item = &CanonicalizedPath>> {
|
||||||
@ -2131,6 +2136,7 @@ pub fn parse_externs(
|
|||||||
|
|
||||||
let mut is_private_dep = false;
|
let mut is_private_dep = false;
|
||||||
let mut add_prelude = true;
|
let mut add_prelude = true;
|
||||||
|
let mut nounused_dep = false;
|
||||||
if let Some(opts) = options {
|
if let Some(opts) = options {
|
||||||
if !is_unstable_enabled {
|
if !is_unstable_enabled {
|
||||||
early_error(
|
early_error(
|
||||||
@ -2152,6 +2158,7 @@ pub fn parse_externs(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
"nounused" => nounused_dep = true,
|
||||||
_ => early_error(error_format, &format!("unknown --extern option `{opt}`")),
|
_ => early_error(error_format, &format!("unknown --extern option `{opt}`")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2160,6 +2167,8 @@ pub fn parse_externs(
|
|||||||
// Crates start out being not private, and go to being private `priv`
|
// Crates start out being not private, and go to being private `priv`
|
||||||
// is specified.
|
// is specified.
|
||||||
entry.is_private_dep |= is_private_dep;
|
entry.is_private_dep |= is_private_dep;
|
||||||
|
// likewise `nounused`
|
||||||
|
entry.nounused_dep |= nounused_dep;
|
||||||
// If any flag is missing `noprelude`, then add to the prelude.
|
// If any flag is missing `noprelude`, then add to the prelude.
|
||||||
entry.add_prelude |= add_prelude;
|
entry.add_prelude |= add_prelude;
|
||||||
}
|
}
|
||||||
|
6
src/test/ui/extern-flag/no-nounused.rs
Normal file
6
src/test/ui/extern-flag/no-nounused.rs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
// aux-crate:somedep=somedep.rs
|
||||||
|
// compile-flags: -Zunstable-options -Dunused-crate-dependencies
|
||||||
|
// edition:2018
|
||||||
|
|
||||||
|
fn main() { //~ ERROR external crate `somedep` unused in `no_nounused`
|
||||||
|
}
|
10
src/test/ui/extern-flag/no-nounused.stderr
Normal file
10
src/test/ui/extern-flag/no-nounused.stderr
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
error: external crate `somedep` unused in `no_nounused`: remove the dependency or add `use somedep as _;`
|
||||||
|
--> $DIR/no-nounused.rs:5:1
|
||||||
|
|
|
||||||
|
LL | fn main() {
|
||||||
|
| ^
|
||||||
|
|
|
||||||
|
= note: requested on the command line with `-D unused-crate-dependencies`
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
7
src/test/ui/extern-flag/nounused.rs
Normal file
7
src/test/ui/extern-flag/nounused.rs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
// check-pass
|
||||||
|
// aux-crate:nounused:somedep=somedep.rs
|
||||||
|
// compile-flags: -Zunstable-options -Dunused-crate-dependencies
|
||||||
|
// edition:2018
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user