]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_resolve/diagnostics.rs
Rollup merge of #68072 - JohnTitor:fix-macro-ice, r=petrochenkov
[rust.git] / src / librustc_resolve / diagnostics.rs
index c4538ddc2422627f98d538d5cb373f1622f3a875..974206797549906f2e40c5f690353338e037b385 100644 (file)
@@ -1,22 +1,21 @@
 use std::cmp::Reverse;
 
-use errors::{Applicability, DiagnosticBuilder};
 use log::debug;
 use rustc::bug;
-use rustc::hir::def::Namespace::{self, *};
-use rustc::hir::def::{self, DefKind, NonMacroAttrKind};
-use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX};
 use rustc::session::Session;
 use rustc::ty::{self, DefIdTree};
-use rustc::util::nodemap::FxHashSet;
+use rustc_data_structures::fx::FxHashSet;
+use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
 use rustc_feature::BUILTIN_ATTRIBUTES;
+use rustc_hir::def::Namespace::{self, *};
+use rustc_hir::def::{self, DefKind, NonMacroAttrKind};
+use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
 use rustc_span::hygiene::MacroKind;
 use rustc_span::source_map::SourceMap;
 use rustc_span::symbol::{kw, Symbol};
 use rustc_span::{BytePos, MultiSpan, Span};
 use syntax::ast::{self, Ident, Path};
 use syntax::print::pprust;
-use syntax::struct_span_err;
 use syntax::util::lev_distance::find_best_match_for_name;
 
 use crate::imports::{ImportDirective, ImportDirectiveSubclass, ImportResolver};
@@ -781,8 +780,14 @@ fn lookup_import_candidates_from_module<FilterFn>(
                 suggestion.candidate.to_string(),
                 Applicability::MaybeIncorrect,
             );
-            let def_span =
-                suggestion.res.opt_def_id().and_then(|def_id| self.definitions.opt_span(def_id));
+            let def_span = suggestion.res.opt_def_id().and_then(|def_id| match def_id.krate {
+                LOCAL_CRATE => self.definitions.opt_span(def_id),
+                _ => Some(
+                    self.session
+                        .source_map()
+                        .def_span(self.cstore().get_span_untracked(def_id, self.session)),
+                ),
+            });
             if let Some(span) = def_span {
                 err.span_label(
                     span,