@@ -86,10 +86,10 @@ use rustc_hir::hir_id::{HirIdMap, HirIdSet};
86
86
use rustc_hir:: intravisit:: { walk_expr, FnKind , Visitor } ;
87
87
use rustc_hir:: LangItem :: { OptionNone , ResultErr , ResultOk } ;
88
88
use rustc_hir:: {
89
- self as hir, def, Arm , ArrayLen , BindingAnnotation , Block , BlockCheckMode , Body , Closure , Constness , Destination ,
90
- Expr , ExprKind , FnDecl , HirId , Impl , ImplItem , ImplItemKind , ImplItemRef , IsAsync , Item , ItemKind , LangItem , Local ,
89
+ self as hir, def, Arm , ArrayLen , BindingAnnotation , Block , BlockCheckMode , Body , Closure , Destination , Expr ,
90
+ ExprKind , FnDecl , HirId , Impl , ImplItem , ImplItemKind , ImplItemRef , IsAsync , Item , ItemKind , LangItem , Local ,
91
91
MatchSource , Mutability , Node , OwnerId , Param , Pat , PatKind , Path , PathSegment , PrimTy , QPath , Stmt , StmtKind ,
92
- TraitItem , TraitItemKind , TraitItemRef , TraitRef , TyKind , UnOp ,
92
+ TraitItem , TraitItemRef , TraitRef , TyKind , UnOp ,
93
93
} ;
94
94
use rustc_lexer:: { tokenize, TokenKind } ;
95
95
use rustc_lint:: { LateContext , Level , Lint , LintContext } ;
@@ -197,31 +197,7 @@ pub fn find_binding_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<
197
197
/// }
198
198
/// ```
199
199
pub fn in_constant ( cx : & LateContext < ' _ > , id : HirId ) -> bool {
200
- let parent_id = cx. tcx . hir ( ) . get_parent_item ( id) . def_id ;
201
- match cx. tcx . hir ( ) . get_by_def_id ( parent_id) {
202
- Node :: Item ( & Item {
203
- kind : ItemKind :: Const ( ..) | ItemKind :: Static ( ..) | ItemKind :: Enum ( ..) ,
204
- ..
205
- } )
206
- | Node :: TraitItem ( & TraitItem {
207
- kind : TraitItemKind :: Const ( ..) ,
208
- ..
209
- } )
210
- | Node :: ImplItem ( & ImplItem {
211
- kind : ImplItemKind :: Const ( ..) ,
212
- ..
213
- } )
214
- | Node :: AnonConst ( _) => true ,
215
- Node :: Item ( & Item {
216
- kind : ItemKind :: Fn ( ref sig, ..) ,
217
- ..
218
- } )
219
- | Node :: ImplItem ( & ImplItem {
220
- kind : ImplItemKind :: Fn ( ref sig, _) ,
221
- ..
222
- } ) => sig. header . constness == Constness :: Const ,
223
- _ => false ,
224
- }
200
+ cx. tcx . hir ( ) . is_inside_const_context ( id)
225
201
}
226
202
227
203
/// Checks if a `Res` refers to a constructor of a `LangItem`
0 commit comments