Skip to content

Commit 7973d93

Browse files
authoredJun 3, 2020
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
2 parents f94c0df + 3dd6f2c commit 7973d93

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed
 

‎src/librustc_metadata/creader.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_middle::middle::cstore::{
1818
CrateSource, ExternCrate, ExternCrateSource, MetadataLoaderDyn,
1919
};
2020
use rustc_middle::ty::TyCtxt;
21-
use rustc_session::config::{self, CrateType};
21+
use rustc_session::config::{self, CrateType, ExternLocation};
2222
use rustc_session::lint;
2323
use rustc_session::output::validate_crate_name;
2424
use rustc_session::search_paths::PathKind;
@@ -850,7 +850,11 @@ impl<'a> CrateLoader<'a> {
850850
// Make a point span rather than covering the whole file
851851
let span = krate.span.shrink_to_lo();
852852
// Complain about anything left over
853-
for (name, _) in self.sess.opts.externs.iter() {
853+
for (name, entry) in self.sess.opts.externs.iter() {
854+
if let ExternLocation::FoundInLibrarySearchDirectories = entry.location {
855+
// Don't worry about pathless `--extern foo` sysroot references
856+
continue;
857+
}
854858
if !self.used_extern_options.contains(&Symbol::intern(name)) {
855859
self.sess.parse_sess.buffer_lint(
856860
lint::builtin::UNUSED_CRATE_DEPENDENCIES,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Pathless --extern references don't count
2+
3+
// edition:2018
4+
// check-pass
5+
// aux-crate:bar=bar.rs
6+
// compile-flags:--extern proc_macro
7+
8+
#![warn(unused_crate_dependencies)]
9+
10+
use bar as _;
11+
12+
fn main() {}

0 commit comments

Comments
 (0)
Please sign in to comment.