Skip to content

Commit df59705

Browse files
committed
Call def_span inside span_if_local.
1 parent 16f9f7c commit df59705

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

compiler/rustc_middle/src/hir/map/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ impl<'hir> Map<'hir> {
10121012
}
10131013

10141014
pub fn span_if_local(self, id: DefId) -> Option<Span> {
1015-
id.as_local().and_then(|id| self.opt_span(self.local_def_id_to_hir_id(id)))
1015+
if id.is_local() { Some(self.tcx.def_span(id)) } else { None }
10161016
}
10171017

10181018
pub fn res_span(self, res: Res) -> Option<Span> {

compiler/rustc_middle/src/hir/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ pub fn provide(providers: &mut Providers) {
121121
providers.hir_attrs =
122122
|tcx, id| tcx.hir_crate(()).owners[id].as_owner().map_or(AttributeMap::EMPTY, |o| &o.attrs);
123123
providers.source_span = |tcx, def_id| tcx.resolutions(()).definitions.def_span(def_id);
124-
providers.def_span = |tcx, def_id| tcx.hir().span_if_local(def_id).unwrap_or(DUMMY_SP);
124+
providers.def_span = |tcx, def_id| {
125+
let def_id = def_id.expect_local();
126+
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
127+
tcx.hir().opt_span(hir_id).unwrap_or(DUMMY_SP)
128+
};
125129
providers.def_ident_span = |tcx, def_id| {
126130
let def_id = def_id.expect_local();
127131
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);

0 commit comments

Comments
 (0)