Skip to content

Rename all_crate_nums query to crates and remove useless wrapper #86749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/back/symbol_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ fn upstream_monomorphizations_provider(
tcx: TyCtxt<'_>,
(): (),
) -> DefIdMap<FxHashMap<SubstsRef<'_>, CrateNum>> {
let cnums = tcx.all_crate_nums(());
let cnums = tcx.crates(());

let mut instances: DefIdMap<FxHashMap<_, _>> = Default::default();

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
}
Lto::Fat | Lto::Thin => {
exported_symbols.insert(LOCAL_CRATE, copy_symbols(LOCAL_CRATE));
for &cnum in tcx.crates().iter() {
for &cnum in tcx.crates(()).iter() {
exported_symbols.insert(cnum, copy_symbols(cnum));
}
Some(Arc::new(exported_symbols))
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ impl CrateInfo {
};
let lang_items = tcx.lang_items();

let crates = tcx.crates();
let crates = tcx.crates(());

let n_crates = crates.len();
info.native_libraries.reserve(n_crates);
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_metadata/src/dependency_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
&& sess.crt_static(Some(ty))
&& !sess.target.crt_static_allows_dylibs)
{
for &cnum in tcx.crates().iter() {
for &cnum in tcx.crates(()).iter() {
if tcx.dep_kind(cnum).macros_only() {
continue;
}
Expand All @@ -152,7 +152,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
// Sweep all crates for found dylibs. Add all dylibs, as well as their
// dependencies, ensuring there are no conflicts. The only valid case for a
// dependency to be relied upon twice is for both cases to rely on a dylib.
for &cnum in tcx.crates().iter() {
for &cnum in tcx.crates(()).iter() {
if tcx.dep_kind(cnum).macros_only() {
continue;
}
Expand All @@ -170,7 +170,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
}

// Collect what we've got so far in the return vector.
let last_crate = tcx.crates().len();
let last_crate = tcx.crates(()).len();
let mut ret = (1..last_crate + 1)
.map(|cnum| match formats.get(&CrateNum::new(cnum)) {
Some(&RequireDynamic) => Linkage::Dynamic,
Expand All @@ -184,7 +184,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
//
// If the crate hasn't been included yet and it's not actually required
// (e.g., it's an allocator) then we skip it here as well.
for &cnum in tcx.crates().iter() {
for &cnum in tcx.crates(()).iter() {
let src = tcx.used_crate_source(cnum);
if src.dylib.is_none()
&& !formats.contains_key(&cnum)
Expand Down Expand Up @@ -281,7 +281,7 @@ fn attempt_static(tcx: TyCtxt<'_>) -> Option<DependencyList> {

// All crates are available in an rlib format, so we're just going to link
// everything in explicitly so long as it's actually required.
let last_crate = tcx.crates().len();
let last_crate = tcx.crates(()).len();
let mut ret = (1..last_crate + 1)
.map(|cnum| {
if tcx.dep_kind(CrateNum::new(cnum)) == CrateDepKind::Explicit {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ pub fn provide(providers: &mut Providers) {
// which is to say, its not deterministic in general. But
// we believe that libstd is consistently assigned crate
// num 1, so it should be enough to resolve #46112.
let mut crates: Vec<CrateNum> = (*tcx.crates()).to_owned();
let mut crates: Vec<CrateNum> = (*tcx.crates(())).to_owned();
crates.sort();

for &cnum in crates.iter() {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1668,7 +1668,7 @@ impl EncodeContext<'a, 'tcx> {

fn encode_crate_deps(&mut self) -> Lazy<[CrateDep]> {
empty_proc_macro!(self);
let crates = self.tcx.crates();
let crates = self.tcx.crates(());

let mut deps = crates
.iter()
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/middle/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ pub type CrateStoreDyn = dyn CrateStore + sync::Sync;
// positions.
pub fn used_crates(tcx: TyCtxt<'_>, prefer: LinkagePreference) -> Vec<(CrateNum, LibSource)> {
let mut libs = tcx
.crates()
.crates(())
.iter()
.cloned()
.filter_map(|cnum| {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,7 @@ rustc_queries! {
eval_always
desc { "calculating the stability index for the local crate" }
}
query all_crate_nums(_: ()) -> &'tcx [CrateNum] {
query crates(_: ()) -> &'tcx [CrateNum] {
eval_always
desc { "fetching all foreign CrateNum instances" }
}
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1259,10 +1259,6 @@ impl<'tcx> TyCtxt<'tcx> {
self.stability_index(())
}

pub fn crates(self) -> &'tcx [CrateNum] {
self.all_crate_nums(())
}

pub fn features(self) -> &'tcx rustc_feature::Features {
self.features_query(())
}
Expand Down Expand Up @@ -2819,7 +2815,7 @@ pub fn provide(providers: &mut ty::query::Providers) {
tcx.stability().local_deprecation_entry(id)
};
providers.extern_mod_stmt_cnum = |tcx, id| tcx.extern_crate_map.get(&id).cloned();
providers.all_crate_nums = |tcx, ()| tcx.arena.alloc_slice(&tcx.cstore.crates_untracked());
providers.crates = |tcx, ()| tcx.arena.alloc_slice(&tcx.cstore.crates_untracked());
providers.output_filenames = |tcx, ()| tcx.output_filenames.clone();
providers.features_query = |tcx, ()| tcx.sess.features_untracked();
providers.is_panic_runtime = |tcx, cnum| {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2248,7 +2248,7 @@ fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, N
let queue = &mut Vec::new();
let mut seen_defs: DefIdSet = Default::default();

for &cnum in tcx.crates().iter() {
for &cnum in tcx.crates(()).iter() {
let def_id = DefId { krate: cnum, index: CRATE_DEF_INDEX };

// Ignore crates that are not direct dependencies.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/query/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ impl<'sess> OnDiskCache<'sess> {
// maps to None.
fn compute_cnum_map(tcx: TyCtxt<'_>) -> UnhashMap<StableCrateId, CrateNum> {
tcx.dep_graph.with_ignore(|| {
tcx.all_crate_nums(())
tcx.crates(())
.iter()
.chain(std::iter::once(&LOCAL_CRATE))
.map(|&cnum| {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/trait_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> Trait
// Traits defined in the current crate can't have impls in upstream
// crates, so we don't bother querying the cstore.
if !trait_id.is_local() {
for &cnum in tcx.crates().iter() {
for &cnum in tcx.crates(()).iter() {
for &(impl_def_id, simplified_self_ty) in
tcx.implementations_of_trait((cnum, trait_id)).iter()
{
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/diagnostic_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fn all_diagnostic_items<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> FxHashMap<Symbol, De
let mut collector = FxHashMap::default();

// Collect diagnostic items in other crates.
for &cnum in tcx.crates().iter().chain(std::iter::once(&LOCAL_CRATE)) {
for &cnum in tcx.crates(()).iter().chain(std::iter::once(&LOCAL_CRATE)) {
for (&name, &def_id) in tcx.diagnostic_items(cnum).iter() {
collect_item(tcx, &mut collector, name, def_id);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ fn get_lang_items(tcx: TyCtxt<'_>, (): ()) -> LanguageItems {
let mut collector = LanguageItemCollector::new(tcx);

// Collect lang items in other crates.
for &cnum in tcx.crates().iter() {
for &cnum in tcx.crates(()).iter() {
for &(def_id, item_index) in tcx.defined_lang_items(cnum).iter() {
collector.collect_item(item_index, def_id);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
if !remaining_lib_features.is_empty() {
check_features(&mut remaining_lib_features, &local_defined_features);

for &cnum in tcx.crates() {
for &cnum in tcx.crates(()) {
if remaining_lib_features.is_empty() {
break;
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/weak_lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn verify<'tcx>(tcx: TyCtxt<'tcx>, items: &lang_items::LanguageItems) {
}

let mut missing = FxHashSet::default();
for &cnum in tcx.crates().iter() {
for &cnum in tcx.crates(()).iter() {
for &item in tcx.missing_lang_items(cnum).iter() {
missing.insert(item);
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_save_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ impl<'tcx> SaveContext<'tcx> {

// List external crates used by the current crate.
pub fn get_external_crates(&self) -> Vec<ExternalCrateData> {
let mut result = Vec::with_capacity(self.tcx.crates().len());
let mut result = Vec::with_capacity(self.tcx.crates(()).len());

for &n in self.tcx.crates().iter() {
for &n in self.tcx.crates(()).iter() {
let span = match self.tcx.extern_crate(n.as_def_id()) {
Some(&ExternCrate { span, .. }) => span,
None => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1591,7 +1591,7 @@ fn compute_all_traits(tcx: TyCtxt<'_>, (): ()) -> &[DefId] {
_ => {}
}
}
for &cnum in tcx.crates().iter() {
for &cnum in tcx.crates(()).iter() {
let def_id = DefId { krate: cnum, index: CRATE_DEF_INDEX };
handle_external_res(tcx, &mut traits, &mut external_mods, Res::Def(DefKind::Mod, def_id));
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ crate fn krate(cx: &mut DocContext<'_>) -> Crate {
cx.cache.owned_box_did = cx.tcx.lang_items().owned_box();

let mut externs = Vec::new();
for &cnum in cx.tcx.crates().iter() {
for &cnum in cx.tcx.crates(()).iter() {
externs.push((cnum, cnum.clean(cx)));
// Analyze doc-reachability for extern items
LibEmbargoVisitor::new(cx).visit_lib(cnum);
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/passes/collect_trait_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ crate fn collect_trait_impls(krate: Crate, cx: &mut DocContext<'_>) -> Crate {

let mut new_items = Vec::new();

for &cnum in cx.tcx.crates().iter() {
for &cnum in cx.tcx.crates(()).iter() {
for &(did, _) in cx.tcx.all_trait_implementations(cnum).iter() {
cx.tcx.sess.prof.generic_activity("build_extern_trait_impl").run(|| {
inline::build_impl(cx, None, did, None, &mut new_items);
Expand Down Expand Up @@ -85,7 +85,7 @@ crate fn collect_trait_impls(krate: Crate, cx: &mut DocContext<'_>) -> Crate {
}
});

// `tcx.crates()` doesn't include the local crate, and `tcx.all_trait_implementations`
// `tcx.crates(())` doesn't include the local crate, and `tcx.all_trait_implementations`
// doesn't work with it anyway, so pull them from the HIR map instead
let mut extra_attrs = Vec::new();
for &trait_did in cx.tcx.all_traits(()).iter() {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ pub fn path_to_res(cx: &LateContext<'_>, path: &[&str]) -> Res {
_ => return Res::Err,
};
let tcx = cx.tcx;
let crates = tcx.crates();
let crates = tcx.crates(());
let krate = try_res!(crates.iter().find(|&&num| tcx.crate_name(num).as_str() == krate));
let first = try_res!(item_child_by_name(tcx, krate.as_def_id(), first));
let last = path
Expand Down