Call def_span inside span_if_local.

This commit is contained in:
Camille GILLOT 2022-03-30 16:51:25 +02:00
parent 16f9f7c7b1
commit df59705301
2 changed files with 6 additions and 2 deletions

View File

@ -1012,7 +1012,7 @@ impl<'hir> Map<'hir> {
}
pub fn span_if_local(self, id: DefId) -> Option<Span> {
id.as_local().and_then(|id| self.opt_span(self.local_def_id_to_hir_id(id)))
if id.is_local() { Some(self.tcx.def_span(id)) } else { None }
}
pub fn res_span(self, res: Res) -> Option<Span> {

View File

@ -121,7 +121,11 @@ pub fn provide(providers: &mut Providers) {
providers.hir_attrs =
|tcx, id| tcx.hir_crate(()).owners[id].as_owner().map_or(AttributeMap::EMPTY, |o| &o.attrs);
providers.source_span = |tcx, def_id| tcx.resolutions(()).definitions.def_span(def_id);
providers.def_span = |tcx, def_id| tcx.hir().span_if_local(def_id).unwrap_or(DUMMY_SP);
providers.def_span = |tcx, def_id| {
let def_id = def_id.expect_local();
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
tcx.hir().opt_span(hir_id).unwrap_or(DUMMY_SP)
};
providers.def_ident_span = |tcx, def_id| {
let def_id = def_id.expect_local();
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);