]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_metadata/src/creader.rs
Auto merge of #81635 - michaelwoerister:structured_def_path_hash, r=pnkfelix
[rust.git] / compiler / rustc_metadata / src / creader.rs
index 42e4f1f8fff15f4abd0bf4ce7dfd88213b34efef..b5506acf73522994001b95b828c8177924028747 100644 (file)
@@ -16,8 +16,9 @@
 use rustc_middle::middle::cstore::{CrateDepKind, CrateSource, ExternCrate};
 use rustc_middle::middle::cstore::{ExternCrateSource, MetadataLoaderDyn};
 use rustc_middle::ty::TyCtxt;
+use rustc_serialize::json::ToJson;
 use rustc_session::config::{self, CrateType, ExternLocation};
-use rustc_session::lint;
+use rustc_session::lint::{self, BuiltinLintDiagnostics, ExternDepSpec};
 use rustc_session::output::validate_crate_name;
 use rustc_session::search_paths::PathKind;
 use rustc_session::{CrateDisambiguator, Session};
@@ -27,6 +28,7 @@
 use rustc_target::spec::{PanicStrategy, TargetTriple};
 
 use proc_macro::bridge::client::ProcMacro;
+use std::collections::BTreeMap;
 use std::path::Path;
 use std::{cmp, env};
 use tracing::{debug, info};
@@ -897,8 +899,25 @@ fn report_unused_deps(&mut self, krate: &ast::Crate) {
                 // 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(
+            if self.used_extern_options.contains(&Symbol::intern(name)) {
+                continue;
+            }
+
+            // Got a real unused --extern
+            let diag = match self.sess.opts.extern_dep_specs.get(name) {
+                Some(loc) => BuiltinLintDiagnostics::ExternDepSpec(name.clone(), loc.into()),
+                None => {
+                    // If we don't have a specific location, provide a json encoding of the `--extern`
+                    // option.
+                    let meta: BTreeMap<String, String> =
+                        std::iter::once(("name".to_string(), name.to_string())).collect();
+                    BuiltinLintDiagnostics::ExternDepSpec(
+                        name.clone(),
+                        ExternDepSpec::Json(meta.to_json()),
+                    )
+                }
+            };
+            self.sess.parse_sess.buffer_lint_with_diagnostic(
                     lint::builtin::UNUSED_CRATE_DEPENDENCIES,
                     span,
                     ast::CRATE_NODE_ID,
@@ -907,8 +926,8 @@ fn report_unused_deps(&mut self, krate: &ast::Crate) {
                         name,
                         self.local_crate_name,
                         name),
+                    diag,
                 );
-            }
         }
     }