1
1
use rustc_hir as hir;
2
- use rustc_hir:: def_id:: { DefId , LocalDefId } ;
2
+ use rustc_hir:: def_id:: DefId ;
3
3
use rustc_middle:: hir:: map:: blocks:: FnLikeNode ;
4
4
use rustc_middle:: ty:: query:: Providers ;
5
5
use rustc_middle:: ty:: TyCtxt ;
@@ -34,8 +34,14 @@ pub fn is_unstable_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Symbol> {
34
34
}
35
35
36
36
pub fn is_parent_const_impl_raw ( tcx : TyCtxt < ' _ > , hir_id : hir:: HirId ) -> bool {
37
- let parent_id = tcx. hir ( ) . get_parent_did ( hir_id) ;
38
- if !parent_id. is_top_level_module ( ) { is_const_impl_raw ( tcx, parent_id) } else { false }
37
+ let parent_id = tcx. hir ( ) . get_parent_node ( hir_id) ;
38
+ matches ! (
39
+ tcx. hir( ) . get( parent_id) ,
40
+ hir:: Node :: Item ( hir:: Item {
41
+ kind: hir:: ItemKind :: Impl ( hir:: Impl { constness: hir:: Constness :: Const , .. } ) ,
42
+ ..
43
+ } )
44
+ )
39
45
}
40
46
41
47
/// Checks whether the function has a `const` modifier or, in case it is an intrinsic, whether
@@ -70,19 +76,6 @@ fn is_const_fn_raw(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
70
76
}
71
77
}
72
78
73
- /// Checks whether the given item is an `impl` that has a `const` modifier.
74
- fn is_const_impl_raw ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> bool {
75
- let hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def_id) ;
76
- let node = tcx. hir ( ) . get ( hir_id) ;
77
- matches ! (
78
- node,
79
- hir:: Node :: Item ( hir:: Item {
80
- kind: hir:: ItemKind :: Impl ( hir:: Impl { constness: hir:: Constness :: Const , .. } ) ,
81
- ..
82
- } )
83
- )
84
- }
85
-
86
79
fn is_promotable_const_fn ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> bool {
87
80
is_const_fn ( tcx, def_id)
88
81
&& match tcx. lookup_const_stability ( def_id) {
@@ -103,10 +96,5 @@ fn is_promotable_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
103
96
}
104
97
105
98
pub fn provide ( providers : & mut Providers ) {
106
- * providers = Providers {
107
- is_const_fn_raw,
108
- is_const_impl_raw : |tcx, def_id| is_const_impl_raw ( tcx, def_id. expect_local ( ) ) ,
109
- is_promotable_const_fn,
110
- ..* providers
111
- } ;
99
+ * providers = Providers { is_const_fn_raw, is_promotable_const_fn, ..* providers } ;
112
100
}
0 commit comments