]> git.lizzy.rs Git - rust.git/commitdiff
rustc: track the Span's of definitions across crates.
authorEduard-Mihai Burtescu <edy.burt@gmail.com>
Wed, 23 Nov 2016 23:39:13 +0000 (01:39 +0200)
committerEduard-Mihai Burtescu <edy.burt@gmail.com>
Wed, 30 Nov 2016 02:48:56 +0000 (04:48 +0200)
18 files changed:
src/librustc/hir/map/mod.rs
src/librustc/middle/cstore.rs
src/librustc/ty/error.rs
src/librustc/ty/mod.rs
src/librustc_borrowck/borrowck/fragments.rs
src/librustc_driver/pretty.rs
src/librustc_metadata/cstore_impl.rs
src/librustc_metadata/decoder.rs
src/librustc_metadata/encoder.rs
src/librustc_metadata/schema.rs
src/librustc_trans/debuginfo/namespace.rs
src/librustc_trans/debuginfo/utils.rs
src/librustc_typeck/astconv.rs
src/librustc_typeck/check/dropck.rs
src/librustc_typeck/check/method/suggest.rs
src/librustc_typeck/check/mod.rs
src/librustc_typeck/check/wfcheck.rs
src/librustc_typeck/check/writeback.rs

index 434e34e7003df1fd9a4cbfd20733a395e281af7b..6ce6f6896df29cca0134a636ec79d8f2b01c03dd 100644 (file)
@@ -760,47 +760,40 @@ pub fn nodes_matching_suffix<'a>(&'a self, parts: &'a [String])
         }
     }
 
-    pub fn opt_span(&self, id: NodeId) -> Option<Span> {
-        let sp = match self.find(id) {
-            Some(NodeItem(item)) => item.span,
-            Some(NodeForeignItem(foreign_item)) => foreign_item.span,
-            Some(NodeTraitItem(trait_method)) => trait_method.span,
-            Some(NodeImplItem(ref impl_item)) => impl_item.span,
-            Some(NodeVariant(variant)) => variant.span,
-            Some(NodeField(field)) => field.span,
-            Some(NodeExpr(expr)) => expr.span,
-            Some(NodeStmt(stmt)) => stmt.span,
-            Some(NodeTy(ty)) => ty.span,
-            Some(NodeTraitRef(tr)) => tr.path.span,
-            Some(NodeLocal(pat)) => pat.span,
-            Some(NodePat(pat)) => pat.span,
-            Some(NodeBlock(block)) => block.span,
-            Some(NodeStructCtor(_)) => self.expect_item(self.get_parent(id)).span,
-            Some(NodeTyParam(ty_param)) => ty_param.span,
-            Some(NodeVisibility(&Visibility::Restricted { ref path, .. })) => path.span,
-            _ => return None,
-        };
-        Some(sp)
-    }
-
     pub fn span(&self, id: NodeId) -> Span {
         self.read(id); // reveals span from node
-        self.opt_span(id)
-            .unwrap_or_else(|| bug!("AstMap.span: could not find span for id {:?}", id))
+        match self.find_entry(id) {
+            Some(EntryItem(_, item)) => item.span,
+            Some(EntryForeignItem(_, foreign_item)) => foreign_item.span,
+            Some(EntryTraitItem(_, trait_method)) => trait_method.span,
+            Some(EntryImplItem(_, impl_item)) => impl_item.span,
+            Some(EntryVariant(_, variant)) => variant.span,
+            Some(EntryField(_, field)) => field.span,
+            Some(EntryExpr(_, expr)) => expr.span,
+            Some(EntryStmt(_, stmt)) => stmt.span,
+            Some(EntryTy(_, ty)) => ty.span,
+            Some(EntryTraitRef(_, tr)) => tr.path.span,
+            Some(EntryLocal(_, pat)) => pat.span,
+            Some(EntryPat(_, pat)) => pat.span,
+            Some(EntryBlock(_, block)) => block.span,
+            Some(EntryStructCtor(_, _)) => self.expect_item(self.get_parent(id)).span,
+            Some(EntryLifetime(_, lifetime)) => lifetime.span,
+            Some(EntryTyParam(_, ty_param)) => ty_param.span,
+            Some(EntryVisibility(_, &Visibility::Restricted { ref path, .. })) => path.span,
+            Some(EntryVisibility(_, v)) => bug!("unexpected Visibility {:?}", v),
+
+            Some(RootCrate) => self.krate().span,
+            Some(RootInlinedParent(parent)) => parent.body.span,
+            Some(NotPresent) | None => {
+                bug!("hir::map::Map::span: id not in map: {:?}", id)
+            }
+        }
     }
 
     pub fn span_if_local(&self, id: DefId) -> Option<Span> {
         self.as_local_node_id(id).map(|id| self.span(id))
     }
 
-    pub fn def_id_span(&self, def_id: DefId, fallback: Span) -> Span {
-        if let Some(node_id) = self.as_local_node_id(def_id) {
-            self.opt_span(node_id).unwrap_or(fallback)
-        } else {
-            fallback
-        }
-    }
-
     pub fn node_to_string(&self, id: NodeId) -> String {
         node_id_to_string(self, id, true)
     }
index d055506a38226b8277316b9a3f4a729544cac274..484e2f1535e7aaaacdb63d01afe454d61976ce13 100644 (file)
@@ -260,6 +260,7 @@ pub struct ExternCrate {
 pub trait CrateStore<'tcx> {
     // item info
     fn describe_def(&self, def: DefId) -> Option<Def>;
+    fn def_span(&self, sess: &Session, def: DefId) -> Span;
     fn stability(&self, def: DefId) -> Option<attr::Stability>;
     fn deprecation(&self, def: DefId) -> Option<attr::Deprecation>;
     fn visibility(&self, def: DefId) -> ty::Visibility;
@@ -404,6 +405,7 @@ pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
 impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
     // item info
     fn describe_def(&self, def: DefId) -> Option<Def> { bug!("describe_def") }
+    fn def_span(&self, sess: &Session, def: DefId) -> Span { bug!("def_span") }
     fn stability(&self, def: DefId) -> Option<attr::Stability> { bug!("stability") }
     fn deprecation(&self, def: DefId) -> Option<attr::Deprecation> { bug!("deprecation") }
     fn visibility(&self, def: DefId) -> ty::Visibility { bug!("visibility") }
index 9b345c2d02329b5f1f6ca1e7a3a7da130cdb01b8..b14148cf38f99ff1c8ccb36d574497a93f12a483 100644 (file)
@@ -291,10 +291,7 @@ pub fn note_and_explain_type_err(self,
                                           expected.ty,
                                           found.ty));
 
-                match
-                    self.map.as_local_node_id(expected.def_id)
-                            .and_then(|node_id| self.map.opt_span(node_id))
-                {
+                match self.map.span_if_local(expected.def_id) {
                     Some(span) => {
                         db.span_note(span, "a default was defined here...");
                     }
@@ -308,10 +305,7 @@ pub fn note_and_explain_type_err(self,
                     expected.origin_span,
                     "...that was applied to an unconstrained type variable here");
 
-                match
-                    self.map.as_local_node_id(found.def_id)
-                            .and_then(|node_id| self.map.opt_span(node_id))
-                {
+                match self.map.span_if_local(found.def_id) {
                     Some(span) => {
                         db.span_note(span, "a second default was defined here...");
                     }
index 9a92e9e70feb4e65681b36c07e59db7ada659871..7387a48c98984a216fd84e3cb2dc43a26e621b0f 100644 (file)
@@ -2370,6 +2370,14 @@ pub fn opt_def_path(self, id: DefId) -> Option<ast_map::DefPath> {
         }
     }
 
+    pub fn def_span(self, def_id: DefId) -> Span {
+        if let Some(id) = self.map.as_local_node_id(def_id) {
+            self.map.span(id)
+        } else {
+            self.sess.cstore.def_span(&self.sess, def_id)
+        }
+    }
+
     pub fn item_name(self, id: DefId) -> ast::Name {
         if let Some(id) = self.map.as_local_node_id(id) {
             self.map.name(id)
index 515868c460d071571639eb9395014fc1a4f5370b..b0a1b3498545fad7ba47b133cab54bdde9862c67 100644 (file)
@@ -496,8 +496,8 @@ fn add_fragment_siblings_for_extension<'a, 'tcx>(this: &MoveData<'tcx>,
         },
 
         ref ty => {
-            let opt_span = origin_id.and_then(|id|tcx.map.opt_span(id));
-            span_bug!(opt_span.unwrap_or(DUMMY_SP),
+            let span = origin_id.map_or(DUMMY_SP, |id| tcx.map.span(id));
+            span_bug!(span,
                       "type {:?} ({:?}) is not fragmentable",
                       parent_ty, ty);
         }
index f85077766516d940a8264dec6fc63a3168a7daad..b055b043723e4ab769304d1a249fa2feff74cd38 100644 (file)
@@ -1006,11 +1006,7 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
                                                got {:?}",
                                               node);
 
-                        // Point to what was found, if there's an accessible span.
-                        match tcx.map.opt_span(nodeid) {
-                            Some(sp) => tcx.sess.span_fatal(sp, &message),
-                            None => tcx.sess.fatal(&message),
-                        }
+                        tcx.sess.span_fatal(tcx.map.span(nodeid), &message)
                     }
                 }
             }
index 573b2f6d2a60cd9c500ecc820f9954dd3fc6785d..c41c3afb83ed5682aab1fd7cdaeac2ddda70ad49 100644 (file)
@@ -32,7 +32,7 @@
 use syntax::attr;
 use syntax::parse::new_parser_from_source_str;
 use syntax::symbol::Symbol;
-use syntax_pos::mk_sp;
+use syntax_pos::{mk_sp, Span};
 use rustc::hir::svh::Svh;
 use rustc_back::target::Target;
 use rustc::hir;
@@ -43,6 +43,11 @@ fn describe_def(&self, def: DefId) -> Option<Def> {
         self.get_crate_data(def.krate).get_def(def.index)
     }
 
+    fn def_span(&self, sess: &Session, def: DefId) -> Span {
+        self.dep_graph.read(DepNode::MetaData(def));
+        self.get_crate_data(def.krate).get_span(def.index, sess)
+    }
+
     fn stability(&self, def: DefId) -> Option<attr::Stability> {
         self.dep_graph.read(DepNode::MetaData(def));
         self.get_crate_data(def.krate).get_stability(def.index)
@@ -383,20 +388,23 @@ fn load_macro(&self, id: DefId, sess: &Session) -> LoadedMacro {
         let local_span = mk_sp(lo, parser.prev_span.hi);
 
         // Mark the attrs as used
-        for attr in &def.attrs {
+        let attrs = data.get_item_attrs(id.index);
+        for attr in &attrs {
             attr::mark_used(attr);
         }
 
+        let name = data.def_key(id.index).disambiguated_data.data
+            .get_opt_name().expect("no name in load_macro");
         sess.imported_macro_spans.borrow_mut()
-            .insert(local_span, (def.name.as_str().to_string(), def.span));
+            .insert(local_span, (name.to_string(), data.get_span(id.index, sess)));
 
         LoadedMacro::MacroRules(ast::MacroDef {
-            ident: ast::Ident::with_empty_ctxt(def.name),
+            ident: ast::Ident::with_empty_ctxt(name),
             id: ast::DUMMY_NODE_ID,
             span: local_span,
             imported_from: None, // FIXME
-            allow_internal_unstable: attr::contains_name(&def.attrs, "allow_internal_unstable"),
-            attrs: def.attrs,
+            allow_internal_unstable: attr::contains_name(&attrs, "allow_internal_unstable"),
+            attrs: attrs,
             body: body,
         })
     }
index d5b08927a06f10402ee549646a2733a71543279c..088364f98346a7596d2e00a6bf7abc698f280912 100644 (file)
@@ -25,6 +25,7 @@
 use rustc::hir::def::{self, Def, CtorKind};
 use rustc::hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE};
 use rustc::middle::lang_items;
+use rustc::session::Session;
 use rustc::ty::{self, Ty, TyCtxt};
 use rustc::ty::subst::Substs;
 
@@ -47,8 +48,9 @@
 
 pub struct DecodeContext<'a, 'tcx: 'a> {
     opaque: opaque::Decoder<'a>,
-    tcx: Option<TyCtxt<'a, 'tcx, 'tcx>>,
     cdata: Option<&'a CrateMetadata>,
+    sess: Option<&'a Session>,
+    tcx: Option<TyCtxt<'a, 'tcx, 'tcx>>,
     from_id_range: IdRange,
     to_id_range: IdRange,
 
@@ -61,22 +63,21 @@ pub struct DecodeContext<'a, 'tcx: 'a> {
 /// Abstract over the various ways one can create metadata decoders.
 pub trait Metadata<'a, 'tcx>: Copy {
     fn raw_bytes(self) -> &'a [u8];
-    fn cdata(self) -> Option<&'a CrateMetadata> {
-        None
-    }
-    fn tcx(self) -> Option<TyCtxt<'a, 'tcx, 'tcx>> {
-        None
-    }
+    fn cdata(self) -> Option<&'a CrateMetadata> { None }
+    fn sess(self) -> Option<&'a Session> { None }
+    fn tcx(self) -> Option<TyCtxt<'a, 'tcx, 'tcx>> { None }
 
     fn decoder(self, pos: usize) -> DecodeContext<'a, 'tcx> {
         let id_range = IdRange {
             min: NodeId::from_u32(u32::MIN),
             max: NodeId::from_u32(u32::MAX),
         };
+        let tcx = self.tcx();
         DecodeContext {
             opaque: opaque::Decoder::new(self.raw_bytes(), pos),
             cdata: self.cdata(),
-            tcx: self.tcx(),
+            sess: self.sess().or(tcx.map(|tcx| tcx.sess)),
+            tcx: tcx,
             from_id_range: id_range,
             to_id_range: id_range,
             last_filemap_index: 0,
@@ -104,6 +105,18 @@ fn cdata(self) -> Option<&'a CrateMetadata> {
     }
 }
 
+impl<'a, 'tcx> Metadata<'a, 'tcx> for (&'a CrateMetadata, &'a Session) {
+    fn raw_bytes(self) -> &'a [u8] {
+        self.0.raw_bytes()
+    }
+    fn cdata(self) -> Option<&'a CrateMetadata> {
+        Some(self.0)
+    }
+    fn sess(self) -> Option<&'a Session> {
+        Some(&self.1)
+    }
+}
+
 impl<'a, 'tcx> Metadata<'a, 'tcx> for (&'a CrateMetadata, TyCtxt<'a, 'tcx, 'tcx>) {
     fn raw_bytes(self) -> &'a [u8] {
         self.0.raw_bytes()
@@ -280,8 +293,8 @@ fn specialized_decode(&mut self) -> Result<Span, Self::Error> {
         let lo = BytePos::decode(self)?;
         let hi = BytePos::decode(self)?;
 
-        let tcx = if let Some(tcx) = self.tcx {
-            tcx
+        let sess = if let Some(sess) = self.sess {
+            sess
         } else {
             return Ok(syntax_pos::mk_sp(lo, hi));
         };
@@ -299,7 +312,7 @@ fn specialized_decode(&mut self) -> Result<Span, Self::Error> {
             (lo, hi)
         };
 
-        let imported_filemaps = self.cdata().imported_filemaps(&tcx.sess.codemap());
+        let imported_filemaps = self.cdata().imported_filemaps(&sess.codemap());
         let filemap = {
             // Optimize for the case that most spans within a translated item
             // originate from the same filemap.
@@ -528,6 +541,10 @@ pub fn get_def(&self, index: DefIndex) -> Option<Def> {
         }
     }
 
+    pub fn get_span(&self, index: DefIndex, sess: &Session) -> Span {
+        self.entry(index).span.decode((self, sess))
+    }
+
     pub fn get_trait_def(&self,
                          item_id: DefIndex,
                          tcx: TyCtxt<'a, 'tcx, 'tcx>)
index 4839c409335ea8fb5dfbba579cbfca491b10bfd8..6abc81d74dc0ad041699328bbe440dd4242dbd80 100644 (file)
@@ -275,6 +275,7 @@ fn encode_enum_variant_info(&mut self,
         Entry {
             kind: EntryKind::Variant(self.lazy(&data)),
             visibility: enum_vis.simplify(),
+            span: self.lazy(&tcx.def_span(def_id)),
             def_key: self.encode_def_key(def_id),
             attributes: self.encode_attributes(&tcx.get_attrs(def_id)),
             children: self.lazy_seq(variant.fields.iter().map(|f| {
@@ -313,6 +314,7 @@ fn encode_info_for_mod(&mut self,
         Entry {
             kind: EntryKind::Mod(self.lazy(&data)),
             visibility: vis.simplify(),
+            span: self.lazy(&md.inner),
             def_key: self.encode_def_key(def_id),
             attributes: self.encode_attributes(attrs),
             children: self.lazy_seq(md.item_ids.iter().map(|item_id| {
@@ -393,6 +395,7 @@ fn encode_field(&mut self,
         Entry {
             kind: EntryKind::Field,
             visibility: field.vis.simplify(),
+            span: self.lazy(&tcx.def_span(def_id)),
             def_key: self.encode_def_key(def_id),
             attributes: self.encode_attributes(&variant_data.fields()[field_index].attrs),
             children: LazySeq::empty(),
@@ -426,6 +429,7 @@ fn encode_struct_ctor(&mut self, (adt_def_id, def_id): (DefId, DefId)) -> Entry<
         Entry {
             kind: EntryKind::Struct(self.lazy(&data)),
             visibility: struct_vis.simplify(),
+            span: self.lazy(&tcx.def_span(def_id)),
             def_key: self.encode_def_key(def_id),
             attributes: LazySeq::empty(),
             children: LazySeq::empty(),
@@ -492,6 +496,7 @@ fn encode_info_for_trait_item(&mut self, def_id: DefId) -> Entry<'tcx> {
         Entry {
             kind: kind,
             visibility: trait_item.vis.simplify(),
+            span: self.lazy(&ast_item.span),
             def_key: self.encode_def_key(def_id),
             attributes: self.encode_attributes(&ast_item.attrs),
             children: LazySeq::empty(),
@@ -580,6 +585,7 @@ fn encode_info_for_impl_item(&mut self, def_id: DefId) -> Entry<'tcx> {
         Entry {
             kind: kind,
             visibility: impl_item.vis.simplify(),
+            span: self.lazy(&ast_item.span),
             def_key: self.encode_def_key(def_id),
             attributes: self.encode_attributes(&ast_item.attrs),
             children: LazySeq::empty(),
@@ -743,6 +749,7 @@ fn encode_info_for_item(&mut self, (def_id, item): (DefId, &'tcx hir::Item)) ->
         Entry {
             kind: kind,
             visibility: item.vis.simplify(),
+            span: self.lazy(&item.span),
             def_key: self.encode_def_key(def_id),
             attributes: self.encode_attributes(&item.attrs),
             children: match item.node {
@@ -850,18 +857,15 @@ fn encode_info_for_item(&mut self, (def_id, item): (DefId, &'tcx hir::Item)) ->
     /// Serialize the text of exported macros
     fn encode_info_for_macro_def(&mut self, macro_def: &hir::MacroDef) -> Entry<'tcx> {
         let def_id = self.tcx.map.local_def_id(macro_def.id);
-        let macro_def = MacroDef {
-            name: macro_def.name,
-            attrs: macro_def.attrs.to_vec(),
-            span: macro_def.span,
-            body: ::syntax::print::pprust::tts_to_string(&macro_def.body)
-        };
         Entry {
-            kind: EntryKind::MacroDef(self.lazy(&macro_def)),
+            kind: EntryKind::MacroDef(self.lazy(&MacroDef {
+                body: ::syntax::print::pprust::tts_to_string(&macro_def.body)
+            })),
             visibility: ty::Visibility::Public,
+            span: self.lazy(&macro_def.span),
             def_key: self.encode_def_key(def_id),
 
-            attributes: LazySeq::empty(),
+            attributes: self.encode_attributes(&macro_def.attrs),
             children: LazySeq::empty(),
             stability: None,
             deprecation: None,
@@ -960,6 +964,7 @@ fn encode_info_for_foreign_item(&mut self,
         Entry {
             kind: kind,
             visibility: nitem.vis.simplify(),
+            span: self.lazy(&nitem.span),
             def_key: self.encode_def_key(def_id),
             attributes: self.encode_attributes(&nitem.attrs),
             children: LazySeq::empty(),
@@ -1038,9 +1043,11 @@ fn encode_info_for_expr(&mut self, expr: &hir::Expr) {
 
 impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
     fn encode_info_for_anon_ty(&mut self, def_id: DefId) -> Entry<'tcx> {
+        let tcx = self.tcx;
         Entry {
             kind: EntryKind::Type,
             visibility: ty::Visibility::Public,
+            span: self.lazy(&tcx.def_span(def_id)),
             def_key: self.encode_def_key(def_id),
             attributes: LazySeq::empty(),
             children: LazySeq::empty(),
@@ -1069,6 +1076,7 @@ fn encode_info_for_closure(&mut self, def_id: DefId) -> Entry<'tcx> {
         Entry {
             kind: EntryKind::Closure(self.lazy(&data)),
             visibility: ty::Visibility::Public,
+            span: self.lazy(&tcx.def_span(def_id)),
             def_key: self.encode_def_key(def_id),
             attributes: self.encode_attributes(&tcx.get_attrs(def_id)),
             children: LazySeq::empty(),
@@ -1163,11 +1171,9 @@ fn encode_codemap(&mut self) -> LazySeq<syntax_pos::FileMap> {
         let all_filemaps = codemap.files.borrow();
         self.lazy_seq_ref(all_filemaps.iter()
             .filter(|filemap| {
-                // No need to export empty filemaps, as they can't contain spans
-                // that need translation.
-                // Also no need to re-export imported filemaps, as any downstream
+                // No need to re-export imported filemaps, as any downstream
                 // crate will import them from their original source.
-                !filemap.lines.borrow().is_empty() && !filemap.is_imported()
+                !filemap.is_imported()
             })
             .map(|filemap| &**filemap))
     }
index 32e89f64f0ec1516b2049e8f5a46bafefde83342..c2acb2e0d7002694911b5906d8d5e384402addd4 100644 (file)
@@ -197,18 +197,11 @@ pub struct TraitImpls {
     pub impls: LazySeq<DefIndex>,
 }
 
-#[derive(RustcEncodable, RustcDecodable)]
-pub struct MacroDef {
-    pub name: ast::Name,
-    pub attrs: Vec<ast::Attribute>,
-    pub span: Span,
-    pub body: String,
-}
-
 #[derive(RustcEncodable, RustcDecodable)]
 pub struct Entry<'tcx> {
     pub kind: EntryKind<'tcx>,
     pub visibility: ty::Visibility,
+    pub span: Lazy<Span>,
     pub def_key: Lazy<hir::map::DefKey>,
     pub attributes: LazySeq<ast::Attribute>,
     pub children: LazySeq<DefIndex>,
@@ -257,6 +250,11 @@ pub struct ModData {
     pub reexports: LazySeq<def::Export>,
 }
 
+#[derive(RustcEncodable, RustcDecodable)]
+pub struct MacroDef {
+    pub body: String,
+}
+
 #[derive(RustcEncodable, RustcDecodable)]
 pub struct FnData {
     pub constness: hir::Constness,
index a0477c9fc1eee2ea93c9759edad86b4d0750e341..521dd7530beeabcbf79d1a663091a777235c966b 100644 (file)
@@ -69,7 +69,7 @@ pub fn item_namespace(ccx: &CrateContext, def_id: DefId) -> DIScope {
     };
 
     let namespace_name = CString::new(namespace_name.as_bytes()).unwrap();
-    let span = ccx.tcx().map.def_id_span(def_id, DUMMY_SP);
+    let span = ccx.tcx().def_span(def_id);
     let (file, line) = if span != DUMMY_SP {
         let loc = span_start(ccx, span);
         (file_metadata(ccx, &loc.file.name, &loc.file.abs_path), loc.line as c_uint)
index 3cdac485fecc990dc32f8b3d8c0227ea94787e51..7cac9172a9c8b18975ef6ad3233b77e1bf048d8f 100644 (file)
@@ -79,7 +79,7 @@ pub fn get_namespace_and_span_for_item(cx: &CrateContext, def_id: DefId)
     });
 
     // Try to get some span information, if we have an inlined item.
-    let definition_span = cx.tcx().map.def_id_span(def_id, syntax_pos::DUMMY_SP);
+    let definition_span = cx.tcx().def_span(def_id);
 
     (containing_scope, definition_span)
 }
index bb7b62533001db17b633a294ca0f93615511af6e..bad014df6fd2a886b49d77ebbca7e5b497ad71da 100644 (file)
@@ -1222,8 +1222,7 @@ fn one_bound_for_assoc_type(&self,
                 self.tcx().associated_items(b.def_id()).find(|item| {
                     item.kind == ty::AssociatedKind::Type && item.name == assoc_name
                 })
-                .and_then(|item| self.tcx().map.as_local_node_id(item.def_id))
-                .and_then(|node_id| self.tcx().map.opt_span(node_id))
+                .and_then(|item| self.tcx().map.span_if_local(item.def_id))
             });
 
             let mut err = struct_span_err!(
index 8868d1e54f4b9661362b845c5d769e4734b8de1e..6fe268bdb2c775d658ef39fcbd6d7d5b98193225 100644 (file)
@@ -21,7 +21,7 @@
 use util::nodemap::FxHashSet;
 
 use syntax::ast;
-use syntax_pos::{self, Span};
+use syntax_pos::Span;
 
 /// check_drop_impl confirms that the Drop implementation identfied by
 /// `drop_impl_did` is not any more specialized than the type it is
@@ -59,7 +59,7 @@ pub fn check_drop_impl(ccx: &CrateCtxt, drop_impl_did: DefId) -> Result<(), ()>
         _ => {
             // Destructors only work on nominal types.  This was
             // already checked by coherence, so we can panic here.
-            let span = ccx.tcx.map.def_id_span(drop_impl_did, syntax_pos::DUMMY_SP);
+            let span = ccx.tcx.def_span(drop_impl_did);
             span_bug!(span,
                       "should have been rejected by coherence check: {}",
                       dtor_self_type);
@@ -88,7 +88,7 @@ fn ensure_drop_params_and_item_params_correspond<'a, 'tcx>(
         let named_type = tcx.item_type(self_type_did);
         let named_type = named_type.subst(tcx, &infcx.parameter_environment.free_substs);
 
-        let drop_impl_span = tcx.map.def_id_span(drop_impl_did, syntax_pos::DUMMY_SP);
+        let drop_impl_span = tcx.def_span(drop_impl_did);
         let fresh_impl_substs =
             infcx.fresh_substs_for_item(drop_impl_span, drop_impl_did);
         let fresh_impl_self_ty = drop_impl_ty.subst(tcx, fresh_impl_substs);
@@ -173,7 +173,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'a, 'tcx>(
 
     let self_type_node_id = tcx.map.as_local_node_id(self_type_did).unwrap();
 
-    let drop_impl_span = tcx.map.def_id_span(drop_impl_did, syntax_pos::DUMMY_SP);
+    let drop_impl_span = tcx.def_span(drop_impl_did);
 
     // We can assume the predicates attached to struct/enum definition
     // hold.
index 6598790355e8243f977f27bce3ba60631f3ced87..bcf18ff66fad3d1b45f3ed9fe352410a8e11bcf5 100644 (file)
@@ -124,7 +124,7 @@ pub fn report_method_error(&self,
                     }
                     CandidateSource::TraitSource(trait_did) => {
                         let item = self.associated_item(trait_did, item_name).unwrap();
-                        let item_span = self.tcx.map.def_id_span(item.def_id, span);
+                        let item_span = self.tcx.def_span(item.def_id);
                         span_note!(err,
                                    item_span,
                                    "candidate #{} is defined in the trait `{}`",
index 0c4e5e4fa0dfc4d88a1a99370d8ea079ea1ddbb8..e25b6d56112c5e7f09a2e617fceb59234c04e3c1 100644 (file)
@@ -1754,7 +1754,7 @@ fn instantiate_anon_types<T: TypeFoldable<'tcx>>(&self, value: &T) -> T {
                 let item_predicates = self.tcx.item_predicates(def_id);
                 let bounds = item_predicates.instantiate(self.tcx, substs);
 
-                let span = self.tcx.map.def_id_span(def_id, codemap::DUMMY_SP);
+                let span = self.tcx.def_span(def_id);
                 for predicate in bounds.predicates {
                     // Change the predicate to refer to the type variable,
                     // which will be the concrete type, instead of the TyAnon.
index b6d0ff03a07abb87953446b1b6ba714b5563cbdf..ae336a2f79eacf942fa3ec27b005a5e11e7ff410 100644 (file)
@@ -188,7 +188,7 @@ fn check_trait_or_impl_item(&mut self,
                     fcx.register_wf_obligation(ty, span, code.clone());
                 }
                 ty::AssociatedKind::Method => {
-                    reject_shadowing_type_parameters(fcx.tcx, span, item.def_id);
+                    reject_shadowing_type_parameters(fcx.tcx, item.def_id);
                     let method_ty = fcx.tcx.item_type(item.def_id);
                     let method_ty = fcx.instantiate_type_scheme(span, free_substs, &method_ty);
                     let predicates = fcx.instantiate_bounds(span, item.def_id, free_substs);
@@ -581,7 +581,7 @@ fn report_bivariance(&self,
     }
 }
 
-fn reject_shadowing_type_parameters(tcx: TyCtxt, span: Span, def_id: DefId) {
+fn reject_shadowing_type_parameters(tcx: TyCtxt, def_id: DefId) {
     let generics = tcx.item_generics(def_id);
     let parent = tcx.item_generics(generics.parent.unwrap());
     let impl_params: FxHashMap<_, _> = parent.types
@@ -592,17 +592,12 @@ fn reject_shadowing_type_parameters(tcx: TyCtxt, span: Span, def_id: DefId) {
     for method_param in &generics.types {
         if impl_params.contains_key(&method_param.name) {
             // Tighten up the span to focus on only the shadowing type
-            let shadow_node_id = tcx.map.as_local_node_id(method_param.def_id).unwrap();
-            let type_span = match tcx.map.opt_span(shadow_node_id) {
-                Some(osp) => osp,
-                None => span
-            };
+            let type_span = tcx.def_span(method_param.def_id);
 
             // The expectation here is that the original trait declaration is
             // local so it should be okay to just unwrap everything.
-            let trait_def_id = impl_params.get(&method_param.name).unwrap();
-            let trait_node_id = tcx.map.as_local_node_id(*trait_def_id).unwrap();
-            let trait_decl_span = tcx.map.opt_span(trait_node_id).unwrap();
+            let trait_def_id = impl_params[&method_param.name];
+            let trait_decl_span = tcx.def_span(trait_def_id);
             error_194(tcx, type_span, trait_decl_span, method_param.name);
         }
     }
index 84b0303e5cfbb4a9fa97b76ff740c188613b07b9..56de75995fd2e820bc4929c1a74eeb51ebbaa82f 100644 (file)
@@ -24,7 +24,7 @@
 use std::cell::Cell;
 
 use syntax::ast;
-use syntax_pos::{DUMMY_SP, Span};
+use syntax_pos::Span;
 
 use rustc::hir::print::pat_to_string;
 use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
@@ -542,7 +542,7 @@ fn span(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Span {
             }
             ResolvingClosure(did) |
             ResolvingAnonTy(did) => {
-                tcx.map.def_id_span(did, DUMMY_SP)
+                tcx.def_span(did)
             }
             ResolvingDeferredObligation(span) => span
         }