Skip to content

Commit 871993f

Browse files
committed
Encode def_ident_span using the query.
1 parent df59705 commit 871993f

File tree

2 files changed

+5
-23
lines changed

2 files changed

+5
-23
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -774,17 +774,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
774774

775775
fn opt_item_ident(self, item_index: DefIndex, sess: &Session) -> Option<Ident> {
776776
let name = self.opt_item_name(item_index)?;
777-
let span = match self.root.tables.def_ident_span.get(self, item_index) {
778-
Some(lazy_span) => lazy_span.decode((self, sess)),
779-
None => {
780-
// FIXME: this weird case of a name with no span is specific to `extern crate`
781-
// items, which are supposed to be treated like `use` items and only be encoded
782-
// to metadata as `Export`s, return `None` because that's what all the callers
783-
// expect in this case.
784-
assert_eq!(self.def_kind(item_index), DefKind::ExternCrate);
785-
return None;
786-
}
787-
};
777+
let span = self.root.tables.def_ident_span.get(self, item_index)?.decode((self, sess));
788778
Some(Ident::new(name, span))
789779
}
790780

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use rustc_serialize::{opaque, Encodable, Encoder};
3131
use rustc_session::config::CrateType;
3232
use rustc_session::cstore::{ForeignModule, LinkagePreference, NativeLib};
3333
use rustc_span::hygiene::{ExpnIndex, HygieneEncodeContext, MacroKind};
34-
use rustc_span::symbol::{sym, Ident, Symbol};
34+
use rustc_span::symbol::{sym, Symbol};
3535
use rustc_span::{
3636
self, DebuggerVisualizerFile, ExternalSource, FileName, SourceFile, Span, SyntaxContext,
3737
};
@@ -1011,6 +1011,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
10111011
record!(self.tables.def_span[def_id] <- tcx.def_span(def_id));
10121012
self.encode_attrs(local_id);
10131013
record!(self.tables.expn_that_defined[def_id] <- self.tcx.expn_that_defined(def_id));
1014+
if let Some(ident_span) = tcx.def_ident_span(def_id) {
1015+
record!(self.tables.def_ident_span[def_id] <- ident_span);
1016+
}
10141017
if def_kind.has_codegen_attrs() {
10151018
record!(self.tables.codegen_fn_attrs[def_id] <- self.tcx.codegen_fn_attrs(def_id));
10161019
}
@@ -1075,7 +1078,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
10751078
assert!(f.did.is_local());
10761079
f.did.index
10771080
}));
1078-
self.encode_ident_span(def_id, variant.ident(tcx));
10791081
self.encode_item_type(def_id);
10801082
if variant.ctor_kind == CtorKind::Fn {
10811083
// FIXME(eddyb) encode signature only in `encode_enum_variant_ctor`.
@@ -1167,7 +1169,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
11671169
debug!("EncodeContext::encode_field({:?})", def_id);
11681170

11691171
record!(self.tables.kind[def_id] <- EntryKind::Field);
1170-
self.encode_ident_span(def_id, field.ident(self.tcx));
11711172
self.encode_item_type(def_id);
11721173
}
11731174

@@ -1246,7 +1247,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
12461247
record!(self.tables.kind[def_id] <- EntryKind::AssocType(container));
12471248
}
12481249
}
1249-
self.encode_ident_span(def_id, ast_item.ident);
12501250
match trait_item.kind {
12511251
ty::AssocKind::Const | ty::AssocKind::Fn => {
12521252
self.encode_item_type(def_id);
@@ -1310,7 +1310,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
13101310
record!(self.tables.kind[def_id] <- EntryKind::AssocType(container));
13111311
}
13121312
}
1313-
self.encode_ident_span(def_id, impl_item.ident(self.tcx));
13141313
self.encode_item_type(def_id);
13151314
if let Some(trait_item_def_id) = impl_item.trait_item_def_id {
13161315
self.tables.trait_item_def_id.set(def_id.index, trait_item_def_id.into());
@@ -1412,8 +1411,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14121411

14131412
debug!("EncodeContext::encode_info_for_item({:?})", def_id);
14141413

1415-
self.encode_ident_span(def_id, item.ident);
1416-
14171414
let entry_kind = match item.kind {
14181415
hir::ItemKind::Static(..) => EntryKind::Static,
14191416
hir::ItemKind::Const(_, body_id) => {
@@ -1959,7 +1956,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
19591956
record!(self.tables.kind[def_id] <- EntryKind::ForeignType);
19601957
}
19611958
}
1962-
self.encode_ident_span(def_id, nitem.ident);
19631959
self.encode_item_type(def_id);
19641960
if let hir::ForeignItemKind::Fn(..) = nitem.kind {
19651961
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
@@ -2041,10 +2037,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
20412037
}
20422038
}
20432039

2044-
fn encode_ident_span(&mut self, def_id: DefId, ident: Ident) {
2045-
record!(self.tables.def_ident_span[def_id] <- ident.span);
2046-
}
2047-
20482040
/// In some cases, along with the item itself, we also
20492041
/// encode some sub-items. Usually we want some info from the item
20502042
/// so it's easier to do that here then to wait until we would encounter

0 commit comments

Comments
 (0)