Skip to content

Commit d4fa564

Browse files
Move query providers
1 parent b5d0608 commit d4fa564

File tree

3 files changed

+35
-31
lines changed

3 files changed

+35
-31
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

-25
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use rustc_hir_pretty::id_to_string;
1313
use rustc_middle::middle::dependency_format::Linkage;
1414
use rustc_middle::middle::exported_symbols::metadata_symbol_name;
1515
use rustc_middle::mir::interpret;
16-
use rustc_middle::query::LocalCrate;
1716
use rustc_middle::query::Providers;
1817
use rustc_middle::traits::specialization_graph;
1918
use rustc_middle::ty::codec::TyEncoder;
@@ -2298,30 +2297,6 @@ pub fn provide(providers: &mut Providers) {
22982297
})
22992298
},
23002299

2301-
// TODO: Uplift these into
2302-
traits: |tcx, LocalCrate| {
2303-
let mut traits = Vec::new();
2304-
for id in tcx.hir().items() {
2305-
if matches!(tcx.def_kind(id.owner_id), DefKind::Trait | DefKind::TraitAlias) {
2306-
traits.push(id.owner_id.to_def_id())
2307-
}
2308-
}
2309-
2310-
tcx.arena.alloc_slice(&traits)
2311-
},
2312-
trait_impls_in_crate: |tcx, LocalCrate| {
2313-
let mut trait_impls = Vec::new();
2314-
for id in tcx.hir().items() {
2315-
if matches!(tcx.def_kind(id.owner_id), DefKind::Impl { .. })
2316-
&& tcx.impl_trait_ref(id.owner_id).is_some()
2317-
{
2318-
trait_impls.push(id.owner_id.to_def_id())
2319-
}
2320-
}
2321-
2322-
tcx.arena.alloc_slice(&trait_impls)
2323-
},
2324-
23252300
..*providers
23262301
}
23272302
}

compiler/rustc_middle/src/ty/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2082,6 +2082,8 @@ pub fn provide(providers: &mut Providers) {
20822082
*providers = Providers {
20832083
trait_impls_of: trait_def::trait_impls_of_provider,
20842084
incoherent_impls: trait_def::incoherent_impls_provider,
2085+
trait_impls_in_crate: trait_def::trait_impls_in_crate_provider,
2086+
traits: trait_def::traits_provider,
20852087
const_param_default: consts::const_param_default,
20862088
vtable_allocation: vtable::vtable_allocation_provider,
20872089
..*providers

compiler/rustc_middle/src/ty/trait_def.rs

+33-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
use crate::traits::specialization_graph;
2-
use crate::ty::fast_reject::{self, SimplifiedType, TreatParams};
3-
use crate::ty::{Ident, Ty, TyCtxt};
4-
use hir::def_id::LOCAL_CRATE;
5-
use rustc_hir as hir;
6-
use rustc_hir::def_id::DefId;
71
use std::iter;
82
use tracing::debug;
93

104
use rustc_data_structures::fx::FxIndexMap;
115
use rustc_errors::ErrorGuaranteed;
6+
use rustc_hir as hir;
7+
use rustc_hir::def::DefKind;
8+
use rustc_hir::def_id::DefId;
9+
use rustc_hir::def_id::LOCAL_CRATE;
1210
use rustc_macros::{Decodable, Encodable, HashStable};
1311

12+
use crate::query::LocalCrate;
13+
use crate::traits::specialization_graph;
14+
use crate::ty::fast_reject::{self, SimplifiedType, TreatParams};
15+
use crate::ty::{Ident, Ty, TyCtxt};
16+
1417
/// A trait's definition with type information.
1518
#[derive(HashStable, Encodable, Decodable)]
1619
pub struct TraitDef {
@@ -274,3 +277,27 @@ pub(super) fn incoherent_impls_provider(
274277

275278
Ok(tcx.arena.alloc_slice(&impls))
276279
}
280+
281+
pub(super) fn traits_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> &[DefId] {
282+
let mut traits = Vec::new();
283+
for id in tcx.hir().items() {
284+
if matches!(tcx.def_kind(id.owner_id), DefKind::Trait | DefKind::TraitAlias) {
285+
traits.push(id.owner_id.to_def_id())
286+
}
287+
}
288+
289+
tcx.arena.alloc_slice(&traits)
290+
}
291+
292+
pub(super) fn trait_impls_in_crate_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> &[DefId] {
293+
let mut trait_impls = Vec::new();
294+
for id in tcx.hir().items() {
295+
if matches!(tcx.def_kind(id.owner_id), DefKind::Impl { .. })
296+
&& tcx.impl_trait_ref(id.owner_id).is_some()
297+
{
298+
trait_impls.push(id.owner_id.to_def_id())
299+
}
300+
}
301+
302+
tcx.arena.alloc_slice(&trait_impls)
303+
}

0 commit comments

Comments
 (0)