Skip to content

Commit 37a6103

Browse files
committed
introduce the query opt_const_param_of
1 parent 2111d6f commit 37a6103

File tree

3 files changed

+169
-125
lines changed

3 files changed

+169
-125
lines changed

src/librustc_middle/query/mod.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,25 @@ rustc_queries! {
8989
desc { |tcx| "HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) }
9090
}
9191

92+
/// Computes the `DefId` of the corresponding const parameter in case the `key` is a
93+
/// const argument and returns `None` otherwise.
94+
///
95+
/// ```rust
96+
/// let a = foo::<7>();
97+
/// // ^ Calling `opt_const_param_of` for this argument,
98+
///
99+
/// fn foo<const N: usize>()
100+
/// // ^ returns this `DefId`.
101+
///
102+
/// fn bar() {
103+
/// // ^ While calling `opt_const_param_of` for other bodies returns `None`.
104+
/// }
105+
/// ```
106+
query opt_const_param_of(key: LocalDefId) -> Option<DefId> {
107+
desc { |tcx| "computing the optional const parameter of `{}`", tcx.def_path_str(key.to_def_id()) }
108+
// FIXME: consider storing this query on disk.
109+
}
110+
92111
/// Records the type of every item.
93112
query type_of(key: DefId) -> Ty<'tcx> {
94113
desc { |tcx| "computing type of `{}`", tcx.def_path_str(key) }

src/librustc_typeck/collect.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ fn collect_mod_item_types(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
6464

6565
pub fn provide(providers: &mut Providers) {
6666
*providers = Providers {
67+
opt_const_param_of: type_of::opt_const_param_of,
6768
type_of: type_of::type_of,
6869
generics_of,
6970
predicates_of,

0 commit comments

Comments
 (0)