Skip to content

Commit c696d4c

Browse files
committed
Remove a use of feed_local_crate and make it fail if used within queries
1 parent 3845be6 commit c696d4c

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

compiler/rustc_interface/src/passes.rs

+2
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,8 @@ pub static DEFAULT_QUERY_PROVIDERS: LazyLock<Providers> = LazyLock::new(|| {
608608
providers.analysis = analysis;
609609
providers.hir_crate = rustc_ast_lowering::lower_to_hir;
610610
providers.resolver_for_lowering = resolver_for_lowering;
611+
providers.stripped_cfg_items =
612+
|tcx, _| tcx.arena.alloc_from_iter(tcx.resolutions(()).stripped_cfg_items.steal());
611613
providers.early_lint_checks = early_lint_checks;
612614
proc_macro_decls::provide(providers);
613615
rustc_const_eval::provide(providers);

compiler/rustc_middle/src/query/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2230,7 +2230,6 @@ rustc_queries! {
22302230
/// Should not be called for the local crate before the resolver outputs are created, as it
22312231
/// is only fed there.
22322232
query stripped_cfg_items(cnum: CrateNum) -> &'tcx [StrippedCfgItem] {
2233-
feedable
22342233
desc { "getting cfg-ed out item names" }
22352234
separate_provide_extern
22362235
}

compiler/rustc_middle/src/ty/context.rs

+6
Original file line numberDiff line numberDiff line change
@@ -550,10 +550,16 @@ impl<T: fmt::Debug + Copy> fmt::Debug for Feed<'_, T> {
550550
/// with T-compiler and making an analysis about why your addition
551551
/// does not cause incremental compilation issues.
552552
impl<'tcx> TyCtxt<'tcx> {
553+
/// Can only be fed before queries are run, and is thus exempt from any
554+
/// incremental issues. Do not use except for the initial query feeding.
553555
pub fn feed_unit_query(self) -> TyCtxtFeed<'tcx, ()> {
554556
TyCtxtFeed { tcx: self, key: () }
555557
}
558+
559+
/// Can only be fed before queries are run, and is thus exempt from any
560+
/// incremental issues. Do not use except for the initial query feeding.
556561
pub fn feed_local_crate(self) -> TyCtxtFeed<'tcx, CrateNum> {
562+
self.dep_graph.assert_ignored();
557563
TyCtxtFeed { tcx: self, key: LOCAL_CRATE }
558564
}
559565

compiler/rustc_middle/src/ty/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub use assoc::*;
3131
pub use generic_args::*;
3232
pub use generics::*;
3333
use rustc_ast as ast;
34+
use rustc_ast::expand::StrippedCfgItem;
3435
use rustc_ast::node_id::NodeMap;
3536
pub use rustc_ast_ir::{Movability, Mutability};
3637
use rustc_attr as attr;
@@ -189,6 +190,7 @@ pub struct ResolverGlobalCtxt {
189190
pub doc_link_resolutions: FxHashMap<LocalDefId, DocLinkResMap>,
190191
pub doc_link_traits_in_scope: FxHashMap<LocalDefId, Vec<DefId>>,
191192
pub all_macro_rules: FxHashMap<Symbol, Res<ast::NodeId>>,
193+
pub stripped_cfg_items: Steal<Vec<StrippedCfgItem>>,
192194
}
193195

194196
/// 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)