@@ -74,6 +74,12 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
7474 self . invocation_parent . impl_trait_context = orig_itc;
7575 }
7676
77+ fn with_direct_const_arg < F : FnOnce ( & mut Self ) > ( & mut self , is_direct : bool , f : F ) {
78+ let orig = mem:: replace ( & mut self . invocation_parent . in_direct_const_arg , is_direct) ;
79+ f ( self ) ;
80+ self . invocation_parent . in_direct_const_arg = orig;
81+ }
82+
7783 fn collect_field ( & mut self , field : & ' a FieldDef , index : Option < usize > ) {
7884 let index = |this : & Self | {
7985 index. unwrap_or_else ( || {
@@ -363,27 +369,61 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
363369 if let MgcaDisambiguation :: Direct = constant. mgca_disambiguation
364370 && self . resolver . tcx . features ( ) . min_generic_const_args ( )
365371 {
366- visit:: walk_anon_const ( self , constant) ;
372+ self . with_direct_const_arg ( true , |this| {
373+ visit:: walk_anon_const ( this, constant) ;
374+ } ) ;
367375 return ;
368376 }
369-
370- let parent = self . create_def ( constant. id , None , DefKind :: AnonConst , constant. value . span ) ;
371- self . with_parent ( parent, |this| visit:: walk_anon_const ( this, constant) ) ;
377+
378+ self . with_direct_const_arg ( false , |this| {
379+ let parent =
380+ this. create_def ( constant. id , None , DefKind :: AnonConst , constant. value . span ) ;
381+ this. with_parent ( parent, |this| visit:: walk_anon_const ( this, constant) ) ;
382+ } )
372383 }
373384
374385 fn visit_expr ( & mut self , expr : & ' a Expr ) {
386+ let handle_const_block = |this : & mut Self , constant : & ' a AnonConst , def_kind : DefKind | {
387+ for attr in & expr. attrs {
388+ visit:: walk_attribute ( this, attr) ;
389+ }
390+
391+ let def = this. create_def ( constant. id , None , def_kind, constant. value . span ) ;
392+ this. with_direct_const_arg ( false , |this| {
393+ this. with_parent ( def, |this| visit:: walk_anon_const ( this, constant) ) ;
394+ } ) ;
395+ } ;
396+
375397 let parent_def = match expr. kind {
376398 ExprKind :: MacCall ( ..) => return self . visit_macro_invoc ( expr. id ) ,
377399 ExprKind :: Closure ( ..) | ExprKind :: Gen ( ..) => {
378400 self . create_def ( expr. id , None , DefKind :: Closure , expr. span )
379401 }
380402 ExprKind :: ConstBlock ( ref constant) => {
381- for attr in & expr. attrs {
382- visit:: walk_attribute ( self , attr) ;
403+ handle_const_block ( self , constant, DefKind :: InlineConst ) ;
404+ return ;
405+ }
406+ ExprKind :: Struct ( ref se) if self . invocation_parent . in_direct_const_arg => {
407+ let StructExpr { qself, path, fields, rest } = & * * se;
408+
409+ for init_expr in fields {
410+ if let ExprKind :: ConstBlock ( ref constant) = init_expr. expr . kind {
411+ handle_const_block ( self , constant, DefKind :: AnonConst ) ;
412+ } else {
413+ visit:: walk_expr_field ( self , init_expr) ;
414+ }
415+ }
416+
417+ if let Some ( qself) = qself {
418+ self . visit_qself ( qself) ;
419+ }
420+ self . visit_path ( path) ;
421+
422+ match rest {
423+ StructRest :: Base ( expr) => self . visit_expr ( expr) ,
424+ _ => ( ) ,
383425 }
384- let def =
385- self . create_def ( constant. id , None , DefKind :: InlineConst , constant. value . span ) ;
386- self . with_parent ( def, |this| visit:: walk_anon_const ( this, constant) ) ;
426+
387427 return ;
388428 }
389429 _ => self . invocation_parent . parent_def ,
0 commit comments