Skip to content

Commit c6143a2

Browse files
committed
Remove a use of feed_local_crate and make it fail if used within queries
1 parent 9e394f1 commit c6143a2

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

compiler/rustc_interface/src/passes.rs

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::interface::{Compiler, Result};
33
use crate::proc_macro_decls;
44
use crate::util;
55

6+
use ast::expand::StrippedCfgItem;
67
use rustc_ast::{self as ast, visit};
78
use rustc_borrowck as mir_borrowck;
89
use rustc_codegen_ssa::traits::CodegenBackend;
@@ -18,6 +19,7 @@ use rustc_lint::{unerased_lint_store, BufferedEarlyLint, EarlyCheckNode, LintSto
1819
use rustc_metadata::creader::CStore;
1920
use rustc_middle::arena::Arena;
2021
use rustc_middle::dep_graph::DepGraph;
22+
use rustc_middle::query::LocalCrate;
2123
use rustc_middle::ty::{self, GlobalCtxt, RegisteredTools, TyCtxt};
2224
use rustc_middle::util::Providers;
2325
use rustc_mir_build as mir_build;
@@ -554,6 +556,10 @@ fn resolver_for_lowering<'tcx>(
554556
tcx.arena.alloc(Steal::new((untracked_resolver_for_lowering, Lrc::new(krate))))
555557
}
556558

559+
fn stripped_cfg_items(tcx: TyCtxt<'_>, _: LocalCrate) -> &'_ [StrippedCfgItem] {
560+
tcx.arena.alloc_from_iter(tcx.resolutions(()).stripped_cfg_items.steal())
561+
}
562+
557563
pub(crate) fn write_dep_info(tcx: TyCtxt<'_>) {
558564
// Make sure name resolution and macro expansion is run for
559565
// the side-effect of providing a complete set of all
@@ -608,6 +614,7 @@ pub static DEFAULT_QUERY_PROVIDERS: LazyLock<Providers> = LazyLock::new(|| {
608614
providers.analysis = analysis;
609615
providers.hir_crate = rustc_ast_lowering::lower_to_hir;
610616
providers.resolver_for_lowering = resolver_for_lowering;
617+
providers.stripped_cfg_items = stripped_cfg_items;
611618
providers.early_lint_checks = early_lint_checks;
612619
proc_macro_decls::provide(providers);
613620
rustc_const_eval::provide(providers);

compiler/rustc_middle/src/query/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2211,7 +2211,6 @@ rustc_queries! {
22112211
/// Should not be called for the local crate before the resolver outputs are created, as it
22122212
/// is only fed there.
22132213
query stripped_cfg_items(cnum: CrateNum) -> &'tcx [StrippedCfgItem] {
2214-
feedable
22152214
desc { "getting cfg-ed out item names" }
22162215
separate_provide_extern
22172216
}

compiler/rustc_middle/src/ty/context.rs

+6
Original file line numberDiff line numberDiff line change
@@ -553,10 +553,16 @@ impl<T: fmt::Debug + Copy> fmt::Debug for Feed<'_, T> {
553553
/// with T-compiler and making an analysis about why your addition
554554
/// does not cause incremental compilation issues.
555555
impl<'tcx> TyCtxt<'tcx> {
556+
/// Can only be fed before queries are run, and is thus exempt from any
557+
/// incremental issues. Do not use except for the initial query feeding.
556558
pub fn feed_unit_query(self) -> TyCtxtFeed<'tcx, ()> {
557559
TyCtxtFeed { tcx: self, key: () }
558560
}
561+
562+
/// Can only be fed before queries are run, and is thus exempt from any
563+
/// incremental issues. Do not use except for the initial query feeding.
559564
pub fn feed_local_crate(self) -> TyCtxtFeed<'tcx, CrateNum> {
565+
self.dep_graph.assert_ignored();
560566
TyCtxtFeed { tcx: self, key: LOCAL_CRATE }
561567
}
562568

compiler/rustc_middle/src/ty/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use crate::ty::fast_reject::SimplifiedType;
2828
use crate::ty::util::Discr;
2929
pub use adt::*;
3030
pub use assoc::*;
31+
use ast::expand::StrippedCfgItem;
3132
pub use generic_args::*;
3233
pub use generics::*;
3334
use rustc_ast as ast;
@@ -188,6 +189,7 @@ pub struct ResolverGlobalCtxt {
188189
pub doc_link_resolutions: FxHashMap<LocalDefId, DocLinkResMap>,
189190
pub doc_link_traits_in_scope: FxHashMap<LocalDefId, Vec<DefId>>,
190191
pub all_macro_rules: FxHashMap<Symbol, Res<ast::NodeId>>,
192+
pub stripped_cfg_items: Steal<Vec<StrippedCfgItem>>,
191193
}
192194

193195
/// Resolutions that should only be used for lowering.

compiler/rustc_resolve/src/lib.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -1559,13 +1559,16 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
15591559
let confused_type_with_std_module = self.confused_type_with_std_module;
15601560
let effective_visibilities = self.effective_visibilities;
15611561

1562-
self.tcx.feed_local_crate().stripped_cfg_items(self.tcx.arena.alloc_from_iter(
1563-
self.stripped_cfg_items.into_iter().filter_map(|item| {
1564-
let parent_module =
1565-
self.node_id_to_def_id.get(&item.parent_module)?.key().to_def_id();
1566-
Some(StrippedCfgItem { parent_module, name: item.name, cfg: item.cfg })
1567-
}),
1568-
));
1562+
let stripped_cfg_items = Steal::new(
1563+
self.stripped_cfg_items
1564+
.into_iter()
1565+
.filter_map(|item| {
1566+
let parent_module =
1567+
self.node_id_to_def_id.get(&item.parent_module)?.key().to_def_id();
1568+
Some(StrippedCfgItem { parent_module, name: item.name, cfg: item.cfg })
1569+
})
1570+
.collect(),
1571+
);
15691572

15701573
let global_ctxt = ResolverGlobalCtxt {
15711574
expn_that_defined,
@@ -1582,6 +1585,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
15821585
doc_link_resolutions: self.doc_link_resolutions,
15831586
doc_link_traits_in_scope: self.doc_link_traits_in_scope,
15841587
all_macro_rules: self.all_macro_rules,
1588+
stripped_cfg_items,
15851589
};
15861590
let ast_lowering = ty::ResolverAstLowering {
15871591
legacy_const_generic_args: self.legacy_const_generic_args,

0 commit comments

Comments
 (0)