Don't count pathless --extern options for unused-crate-dependencies warnings
`--extern proc_macro` is used to add the proc_macro crate to the extern prelude for all procmacros. In general pathless `--extern` only references sysroot/standard libraries and so should be exempt from unused-crate-dependencies warnings.
This commit is contained in:
parent
ad4bc3323b
commit
3dd6f2cd75
@ -18,7 +18,7 @@ use rustc_middle::middle::cstore::{
|
||||
CrateSource, ExternCrate, ExternCrateSource, MetadataLoaderDyn,
|
||||
};
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_session::config::{self, CrateType};
|
||||
use rustc_session::config::{self, CrateType, ExternLocation};
|
||||
use rustc_session::lint;
|
||||
use rustc_session::output::validate_crate_name;
|
||||
use rustc_session::search_paths::PathKind;
|
||||
@ -850,7 +850,11 @@ impl<'a> CrateLoader<'a> {
|
||||
// Make a point span rather than covering the whole file
|
||||
let span = krate.span.shrink_to_lo();
|
||||
// Complain about anything left over
|
||||
for (name, _) in self.sess.opts.externs.iter() {
|
||||
for (name, entry) in self.sess.opts.externs.iter() {
|
||||
if let ExternLocation::FoundInLibrarySearchDirectories = entry.location {
|
||||
// Don't worry about pathless `--extern foo` sysroot references
|
||||
continue;
|
||||
}
|
||||
if !self.used_extern_options.contains(&Symbol::intern(name)) {
|
||||
self.sess.parse_sess.buffer_lint(
|
||||
lint::builtin::UNUSED_CRATE_DEPENDENCIES,
|
||||
|
12
src/test/ui/unused-crate-deps/ignore-pathless-extern.rs
Normal file
12
src/test/ui/unused-crate-deps/ignore-pathless-extern.rs
Normal file
@ -0,0 +1,12 @@
|
||||
// Pathless --extern references don't count
|
||||
|
||||
// edition:2018
|
||||
// check-pass
|
||||
// aux-crate:bar=bar.rs
|
||||
// compile-flags:--extern proc_macro
|
||||
|
||||
#![warn(unused_crate_dependencies)]
|
||||
|
||||
use bar as _;
|
||||
|
||||
fn main() {}
|
Loading…
x
Reference in New Issue
Block a user