File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -279,6 +279,14 @@ rustc_queries! {
279
279
desc { |tcx| "checking if item is const fn: `{}`" , tcx. def_path_str( key) }
280
280
}
281
281
282
+ /// Returns `true` if this is a const `impl`. **Do not call this function manually.**
283
+ ///
284
+ /// This query caches the base data for the `is_const_impl` helper function, which also
285
+ /// takes into account stability attributes (e.g., `#[rustc_const_unstable]`).
286
+ query is_const_impl_raw( key: DefId ) -> bool {
287
+ desc { |tcx| "checking if item is const impl: `{}`" , tcx. def_path_str( key) }
288
+ }
289
+
282
290
query asyncness( key: DefId ) -> hir:: IsAsync {
283
291
desc { |tcx| "checking if the function is async: `{}`" , tcx. def_path_str( key) }
284
292
}
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ use rustc::ty::query::Providers;
3
3
use rustc:: ty:: TyCtxt ;
4
4
use rustc_attr as attr;
5
5
use rustc_hir as hir;
6
- use rustc_hir:: def_id:: DefId ;
6
+ use rustc_hir:: def_id:: { DefId , LocalDefId } ;
7
7
use rustc_span:: symbol:: Symbol ;
8
8
use rustc_target:: spec:: abi:: Abi ;
9
9
@@ -119,6 +119,19 @@ pub fn provide(providers: &mut Providers<'_>) {
119
119
}
120
120
}
121
121
122
+ /// Checks whether the given item is an `impl` that has a `const` modifier.
123
+ fn is_const_impl_raw ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> bool {
124
+ let hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def_id) ;
125
+ let node = tcx. hir ( ) . get ( hir_id) ;
126
+ matches ! (
127
+ node,
128
+ hir:: Node :: Item ( hir:: Item {
129
+ kind: hir:: ItemKind :: Impl { constness: hir:: Constness :: Const , .. } ,
130
+ ..
131
+ } )
132
+ )
133
+ }
134
+
122
135
fn is_promotable_const_fn ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> bool {
123
136
is_const_fn ( tcx, def_id)
124
137
&& match tcx. lookup_const_stability ( def_id) {
@@ -148,6 +161,7 @@ pub fn provide(providers: &mut Providers<'_>) {
148
161
149
162
* providers = Providers {
150
163
is_const_fn_raw,
164
+ is_const_impl_raw : |tcx, def_id| is_const_impl_raw ( tcx, LocalDefId :: from_def_id ( def_id) ) ,
151
165
is_promotable_const_fn,
152
166
const_fn_is_allowed_fn_ptr,
153
167
..* providers
You can’t perform that action at this time.
0 commit comments