Skip to content

Commit 6c2dd25

Browse files
committed
Auto merge of #86002 - cjgillot:expn_that_defined, r=petrochenkov
Always go through the expn_that_defined query.
2 parents ac3e680 + 3f32738 commit 6c2dd25

File tree

4 files changed

+9
-16
lines changed

4 files changed

+9
-16
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ impl EncodeContext<'a, 'tcx> {
942942
});
943943
record!(self.tables.span[def_id] <- tcx.def_span(def_id));
944944
record!(self.tables.attributes[def_id] <- tcx.get_attrs(def_id));
945-
record!(self.tables.expn_that_defined[def_id] <- self.tcx.expansion_that_defined(def_id));
945+
record!(self.tables.expn_that_defined[def_id] <- self.tcx.expn_that_defined(def_id));
946946
if should_encode_visibility(def_kind) {
947947
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
948948
}

compiler/rustc_middle/src/hir/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,8 @@ pub fn provide(providers: &mut Providers) {
167167
};
168168
providers.opt_def_kind = |tcx, def_id| tcx.hir().opt_def_kind(def_id.expect_local());
169169
providers.all_local_trait_impls = |tcx, ()| &tcx.hir_crate(()).trait_impls;
170+
providers.expn_that_defined = |tcx, id| {
171+
let id = id.expect_local();
172+
tcx.definitions.expansion_that_defined(id)
173+
};
170174
}

compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ rustc_queries! {
210210
desc { |tcx| "parent module of `{}`", tcx.def_path_str(key.to_def_id()) }
211211
}
212212

213-
/// Internal helper query. Use `tcx.expansion_that_defined` instead
214213
query expn_that_defined(key: DefId) -> rustc_span::ExpnId {
214+
eval_always
215215
desc { |tcx| "expansion that defined `{}`", tcx.def_path_str(key) }
216216
}
217217

compiler/rustc_middle/src/ty/mod.rs

+3-14
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
3939
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalDefIdMap, CRATE_DEF_INDEX};
4040
use rustc_hir::{Constness, Node};
4141
use rustc_macros::HashStable;
42-
use rustc_span::hygiene::ExpnId;
4342
use rustc_span::symbol::{kw, Ident, Symbol};
4443
use rustc_span::Span;
4544
use rustc_target::abi::Align;
@@ -1862,20 +1861,11 @@ impl<'tcx> TyCtxt<'tcx> {
18621861
&& use_name
18631862
.span
18641863
.ctxt()
1865-
.hygienic_eq(def_name.span.ctxt(), self.expansion_that_defined(def_parent_def_id))
1866-
}
1867-
1868-
pub fn expansion_that_defined(self, scope: DefId) -> ExpnId {
1869-
match scope.as_local() {
1870-
// Parsing and expansion aren't incremental, so we don't
1871-
// need to go through a query for the same-crate case.
1872-
Some(scope) => self.hir().definitions().expansion_that_defined(scope),
1873-
None => self.expn_that_defined(scope),
1874-
}
1864+
.hygienic_eq(def_name.span.ctxt(), self.expn_that_defined(def_parent_def_id))
18751865
}
18761866

18771867
pub fn adjust_ident(self, mut ident: Ident, scope: DefId) -> Ident {
1878-
ident.span.normalize_to_macros_2_0_and_adjust(self.expansion_that_defined(scope));
1868+
ident.span.normalize_to_macros_2_0_and_adjust(self.expn_that_defined(scope));
18791869
ident
18801870
}
18811871

@@ -1886,8 +1876,7 @@ impl<'tcx> TyCtxt<'tcx> {
18861876
block: hir::HirId,
18871877
) -> (Ident, DefId) {
18881878
let scope =
1889-
match ident.span.normalize_to_macros_2_0_and_adjust(self.expansion_that_defined(scope))
1890-
{
1879+
match ident.span.normalize_to_macros_2_0_and_adjust(self.expn_that_defined(scope)) {
18911880
Some(actual_expansion) => {
18921881
self.hir().definitions().parent_module_of_macro_def(actual_expansion)
18931882
}

0 commit comments

Comments
 (0)