diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2024-02-19 16:07:48 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2024-03-05 05:53:33 +0000 |
| commit | 3845be6b376f405671850dd37c92864aac7b07c2 (patch) | |
| tree | 7076738178099a67e3fd6e4edd3f8f1676bd5762 /compiler/rustc_middle/src/ty | |
| parent | 890dd586503fe3a212fc3dc346ea7f0196ca8c29 (diff) | |
| download | rust-3845be6b376f405671850dd37c92864aac7b07c2.tar.gz rust-3845be6b376f405671850dd37c92864aac7b07c2.zip | |
Prevent feeding `CRATE_DEF_ID` queries outside the resolver
Diffstat (limited to 'compiler/rustc_middle/src/ty')
| -rw-r--r-- | compiler/rustc_middle/src/ty/context.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 032d973dcc7..b568364517f 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -545,6 +545,10 @@ impl<T: fmt::Debug + Copy> fmt::Debug for Feed<'_, T> { } } +/// Some workarounds to use cases that cannot use `create_def`. +/// Do not add new ways to create `TyCtxtFeed` without consulting +/// with T-compiler and making an analysis about why your addition +/// does not cause incremental compilation issues. impl<'tcx> TyCtxt<'tcx> { pub fn feed_unit_query(self) -> TyCtxtFeed<'tcx, ()> { TyCtxtFeed { tcx: self, key: () } @@ -553,8 +557,12 @@ impl<'tcx> TyCtxt<'tcx> { TyCtxtFeed { tcx: self, key: LOCAL_CRATE } } - pub fn feed_local_crate_def_id(self) -> TyCtxtFeed<'tcx, LocalDefId> { - TyCtxtFeed { tcx: self, key: CRATE_DEF_ID } + /// Only used in the resolver to register the `CRATE_DEF_ID` `DefId` and feed + /// some queries for it. It will panic if used twice. + pub fn create_local_crate_def_id(self, span: Span) -> TyCtxtFeed<'tcx, LocalDefId> { + let key = self.untracked().source_span.push(span); + assert_eq!(key, CRATE_DEF_ID); + TyCtxtFeed { tcx: self, key } } /// In order to break cycles involving `AnonConst`, we need to set the expected type by side |
