Rollup merge of #72900 - jsgf:no-unused-pathless, r=petrochenkov
Don't count pathless --extern 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. r? @petrochenkov
This commit is contained in:
commit
7973d9381f
2 changed files with 18 additions and 2 deletions
|
@ -18,7 +18,7 @@ use rustc_middle::middle::cstore::{
|
||||||
CrateSource, ExternCrate, ExternCrateSource, MetadataLoaderDyn,
|
CrateSource, ExternCrate, ExternCrateSource, MetadataLoaderDyn,
|
||||||
};
|
};
|
||||||
use rustc_middle::ty::TyCtxt;
|
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::lint;
|
||||||
use rustc_session::output::validate_crate_name;
|
use rustc_session::output::validate_crate_name;
|
||||||
use rustc_session::search_paths::PathKind;
|
use rustc_session::search_paths::PathKind;
|
||||||
|
@ -850,7 +850,11 @@ impl<'a> CrateLoader<'a> {
|
||||||
// Make a point span rather than covering the whole file
|
// Make a point span rather than covering the whole file
|
||||||
let span = krate.span.shrink_to_lo();
|
let span = krate.span.shrink_to_lo();
|
||||||
// Complain about anything left over
|
// 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)) {
|
if !self.used_extern_options.contains(&Symbol::intern(name)) {
|
||||||
self.sess.parse_sess.buffer_lint(
|
self.sess.parse_sess.buffer_lint(
|
||||||
lint::builtin::UNUSED_CRATE_DEPENDENCIES,
|
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…
Add table
Add a link
Reference in a new issue