11use rustc_hir as hir;
2- use rustc_hir:: def_id:: { DefId , LocalDefId } ;
2+ use rustc_hir:: def_id:: DefId ;
33use rustc_middle:: hir:: map:: blocks:: FnLikeNode ;
44use rustc_middle:: ty:: query:: Providers ;
55use rustc_middle:: ty:: TyCtxt ;
@@ -34,8 +34,14 @@ pub fn is_unstable_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Symbol> {
3434}
3535
3636pub 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+ )
3945}
4046
4147/// 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 {
7076 }
7177}
7278
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-
8679fn is_promotable_const_fn ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> bool {
8780 is_const_fn ( tcx, def_id)
8881 && match tcx. lookup_const_stability ( def_id) {
@@ -103,10 +96,5 @@ fn is_promotable_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
10396}
10497
10598pub 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 } ;
112100}
0 commit comments