@@ -86,10 +86,10 @@ use rustc_hir::hir_id::{HirIdMap, HirIdSet};
8686use rustc_hir:: intravisit:: { walk_expr, FnKind , Visitor } ;
8787use rustc_hir:: LangItem :: { OptionNone , ResultErr , ResultOk } ;
8888use 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 ,
9191 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 ,
9393} ;
9494use rustc_lexer:: { tokenize, TokenKind } ;
9595use rustc_lint:: { LateContext , Level , Lint , LintContext } ;
@@ -197,31 +197,7 @@ pub fn find_binding_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<
197197/// }
198198/// ```
199199pub 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)
225201}
226202
227203/// Checks if a `Res` refers to a constructor of a `LangItem`
0 commit comments