Skip to content

Commit 3f8c979

Browse files
authored
Rollup merge of #80331 - jyn514:docs, r=varkor
Add more comments to trait queries This also adds back a comment that was mistakenly removed in ac9dfc3.
2 parents 12ac312 + 979d3ce commit 3f8c979

File tree

1 file changed

+32
-13
lines changed
  • compiler/rustc_middle/src/query

1 file changed

+32
-13
lines changed

compiler/rustc_middle/src/query/mod.rs

+32-13
Original file line numberDiff line numberDiff line change
@@ -576,11 +576,13 @@ rustc_queries! {
576576
desc { |tcx| "collecting associated items of {}", tcx.def_path_str(key) }
577577
}
578578

579-
query impl_trait_ref(key: DefId) -> Option<ty::TraitRef<'tcx>> {
580-
desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(key) }
579+
/// Given an `impl_id`, return the trait it implements.
580+
/// Return `None` if this is an inherent impl.
581+
query impl_trait_ref(impl_id: DefId) -> Option<ty::TraitRef<'tcx>> {
582+
desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) }
581583
}
582-
query impl_polarity(key: DefId) -> ty::ImplPolarity {
583-
desc { |tcx| "computing implementation polarity of `{}`", tcx.def_path_str(key) }
584+
query impl_polarity(impl_id: DefId) -> ty::ImplPolarity {
585+
desc { |tcx| "computing implementation polarity of `{}`", tcx.def_path_str(impl_id) }
584586
}
585587

586588
query issue33140_self_ty(key: DefId) -> Option<ty::Ty<'tcx>> {
@@ -917,8 +919,10 @@ rustc_queries! {
917919
}
918920

919921
TypeChecking {
920-
query trait_of_item(def_id: DefId) -> Option<DefId> {
921-
desc { |tcx| "finding trait defining `{}`", tcx.def_path_str(def_id) }
922+
/// Given an `associated_item`, find the trait it belongs to.
923+
/// Return `None` if the `DefId` is not an associated item.
924+
query trait_of_item(associated_item: DefId) -> Option<DefId> {
925+
desc { |tcx| "finding trait defining `{}`", tcx.def_path_str(associated_item) }
922926
}
923927
}
924928

@@ -948,27 +952,37 @@ rustc_queries! {
948952
}
949953

950954
TypeChecking {
951-
query all_local_trait_impls(key: CrateNum) -> &'tcx BTreeMap<DefId, Vec<hir::HirId>> {
955+
/// Return all `impl` blocks in the current crate.
956+
///
957+
/// To allow caching this between crates, you must pass in [`LOCAL_CRATE`] as the crate number.
958+
/// Passing in any other crate will cause an ICE.
959+
///
960+
/// [`LOCAL_CRATE`]: rustc_hir::def_id::LOCAL_CRATE
961+
query all_local_trait_impls(local_crate: CrateNum) -> &'tcx BTreeMap<DefId, Vec<hir::HirId>> {
952962
desc { "local trait impls" }
953963
}
954-
query trait_impls_of(key: DefId) -> ty::trait_def::TraitImpls {
964+
965+
/// Given a trait `trait_id`, return all known `impl` blocks.
966+
query trait_impls_of(trait_id: DefId) -> ty::trait_def::TraitImpls {
955967
storage(ArenaCacheSelector<'tcx>)
956-
desc { |tcx| "trait impls of `{}`", tcx.def_path_str(key) }
968+
desc { |tcx| "trait impls of `{}`", tcx.def_path_str(trait_id) }
957969
}
958-
query specialization_graph_of(key: DefId) -> specialization_graph::Graph {
970+
971+
query specialization_graph_of(trait_id: DefId) -> specialization_graph::Graph {
959972
storage(ArenaCacheSelector<'tcx>)
960-
desc { |tcx| "building specialization graph of trait `{}`", tcx.def_path_str(key) }
973+
desc { |tcx| "building specialization graph of trait `{}`", tcx.def_path_str(trait_id) }
961974
cache_on_disk_if { true }
962975
}
963-
query object_safety_violations(key: DefId) -> &'tcx [traits::ObjectSafetyViolation] {
964-
desc { |tcx| "determine object safety of trait `{}`", tcx.def_path_str(key) }
976+
query object_safety_violations(trait_id: DefId) -> &'tcx [traits::ObjectSafetyViolation] {
977+
desc { |tcx| "determine object safety of trait `{}`", tcx.def_path_str(trait_id) }
965978
}
966979

967980
/// Gets the ParameterEnvironment for a given item; this environment
968981
/// will be in "user-facing" mode, meaning that it is suitable for
969982
/// type-checking etc, and it does not normalize specializable
970983
/// associated types. This is almost always what you want,
971984
/// unless you are doing MIR optimizations, in which case you
985+
/// might want to use `reveal_all()` method to change modes.
972986
query param_env(def_id: DefId) -> ty::ParamEnv<'tcx> {
973987
desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
974988
}
@@ -1229,10 +1243,15 @@ rustc_queries! {
12291243
}
12301244

12311245
TypeChecking {
1246+
/// Given a crate and a trait, look up all impls of that trait in the crate.
1247+
/// Return `(impl_id, self_ty)`.
12321248
query implementations_of_trait(_: (CrateNum, DefId))
12331249
-> &'tcx [(DefId, Option<ty::fast_reject::SimplifiedType>)] {
12341250
desc { "looking up implementations of a trait in a crate" }
12351251
}
1252+
1253+
/// Given a crate, look up all trait impls in that crate.
1254+
/// Return `(impl_id, self_ty)`.
12361255
query all_trait_implementations(_: CrateNum)
12371256
-> &'tcx [(DefId, Option<ty::fast_reject::SimplifiedType>)] {
12381257
desc { "looking up all (?) trait implementations" }

0 commit comments

Comments
 (0)