Skip to content

Commit 6477fd8

Browse files
committed
Make TyCtxtFeed::def_id private.
1 parent a0c3880 commit 6477fd8

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
497497
self.tcx.hir().def_key(self.local_def_id(node_id)),
498498
);
499499

500-
let def_id = self.tcx.create_def(parent, data).def_id;
500+
let def_id = self.tcx.create_def(parent, data).def_id();
501501

502502
debug!("create_def: def_id_to_node_id[{:?}] <-> {:?}", def_id, node_id);
503503
self.resolver.node_id_to_def_id.insert(node_id, def_id);

compiler/rustc_middle/src/ty/context.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -1010,12 +1010,19 @@ pub struct FreeRegionInfo {
10101010
pub is_impl_item: bool,
10111011
}
10121012

1013+
/// This struct should only be created by `create_def`.
10131014
#[derive(Copy, Clone)]
10141015
pub struct TyCtxtFeed<'tcx> {
10151016
pub tcx: TyCtxt<'tcx>,
1016-
pub def_id: LocalDefId,
1017-
/// This struct should only be created by `create_def`.
1018-
_priv: (),
1017+
// Do not allow direct access, as downstream code must not mutate this field.
1018+
def_id: LocalDefId,
1019+
}
1020+
1021+
impl<'tcx> TyCtxtFeed<'tcx> {
1022+
#[inline(always)]
1023+
pub fn def_id(&self) -> LocalDefId {
1024+
self.def_id
1025+
}
10191026
}
10201027

10211028
/// The central data structure of the compiler. It stores references
@@ -1507,7 +1514,7 @@ impl<'tcx> TyCtxt<'tcx> {
15071514
// - this write will have happened before these queries are called.
15081515
let def_id = self.definitions.write().create_def(parent, data);
15091516

1510-
TyCtxtFeed { tcx: self, def_id, _priv: () }
1517+
TyCtxtFeed { tcx: self, def_id }
15111518
}
15121519

15131520
pub fn iter_local_def_id(self) -> impl Iterator<Item = LocalDefId> + 'tcx {

compiler/rustc_middle/src/ty/query.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ macro_rules! define_feedable {
334334
$($(#[$attr])*
335335
#[inline(always)]
336336
pub fn $name(self, value: $V) -> query_stored::$name<'tcx> {
337-
let key = self.def_id.into_query_param();
337+
let key = self.def_id().into_query_param();
338338
opt_remap_env_constness!([$($modifiers)*][key]);
339339

340340
let tcx = self.tcx;

0 commit comments

Comments
 (0)