Skip to content

Commit 7c8549d

Browse files
Move query providers
1 parent 6e984fb commit 7c8549d

File tree

3 files changed

+35
-32
lines changed

3 files changed

+35
-32
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 0 additions & 25 deletions
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;
@@ -2259,30 +2258,6 @@ pub fn provide(providers: &mut Providers) {
22592258
})
22602259
},
22612260

2262-
// TODO: Uplift these into
2263-
traits: |tcx, LocalCrate| {
2264-
let mut traits = Vec::new();
2265-
for id in tcx.hir().items() {
2266-
if matches!(tcx.def_kind(id.owner_id), DefKind::Trait | DefKind::TraitAlias) {
2267-
traits.push(id.owner_id.to_def_id())
2268-
}
2269-
}
2270-
2271-
tcx.arena.alloc_slice(&traits)
2272-
},
2273-
trait_impls_in_crate: |tcx, LocalCrate| {
2274-
let mut trait_impls = Vec::new();
2275-
for id in tcx.hir().items() {
2276-
if matches!(tcx.def_kind(id.owner_id), DefKind::Impl { .. })
2277-
&& tcx.impl_trait_ref(id.owner_id).is_some()
2278-
{
2279-
trait_impls.push(id.owner_id.to_def_id())
2280-
}
2281-
}
2282-
2283-
tcx.arena.alloc_slice(&trait_impls)
2284-
},
2285-
22862261
..*providers
22872262
}
22882263
}

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,6 +1992,8 @@ pub fn provide(providers: &mut Providers) {
19921992
*providers = Providers {
19931993
trait_impls_of: trait_def::trait_impls_of_provider,
19941994
incoherent_impls: trait_def::incoherent_impls_provider,
1995+
trait_impls_in_crate: trait_def::trait_impls_in_crate_provider,
1996+
traits: trait_def::traits_provider,
19951997
const_param_default: consts::const_param_default,
19961998
vtable_allocation: vtable::vtable_allocation_provider,
19971999
..*providers

compiler/rustc_middle/src/ty/trait_def.rs

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
use crate::traits::specialization_graph;
2-
use crate::ty::fast_reject::{self, SimplifiedType, TreatParams, TreatProjections};
3-
use crate::ty::{Ident, Ty, TyCtxt};
4-
use hir::def_id::LOCAL_CRATE;
1+
use rustc_data_structures::fx::FxIndexMap;
2+
use rustc_errors::ErrorGuaranteed;
53
use rustc_hir as hir;
4+
use rustc_hir::def::DefKind;
65
use rustc_hir::def_id::DefId;
6+
use rustc_hir::def_id::LOCAL_CRATE;
7+
use rustc_macros::HashStable;
78
use std::iter;
89

9-
use rustc_data_structures::fx::FxIndexMap;
10-
use rustc_errors::ErrorGuaranteed;
11-
use rustc_macros::HashStable;
10+
use crate::query::LocalCrate;
11+
use crate::traits::specialization_graph;
12+
use crate::ty::fast_reject::{self, SimplifiedType, TreatParams, TreatProjections};
13+
use crate::ty::{Ident, Ty, TyCtxt};
1214

1315
/// A trait's definition with type information.
1416
#[derive(HashStable, Encodable, Decodable)]
@@ -279,3 +281,27 @@ pub(super) fn incoherent_impls_provider(
279281

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

0 commit comments

Comments
 (0)