@@ -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 ( || {
@@ -357,25 +363,73 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
357363 }
358364
359365 fn visit_anon_const ( & mut self , constant : & ' a AnonConst ) {
360- let parent = self . create_def ( constant. id , None , DefKind :: AnonConst , constant. value . span ) ;
361- self . with_parent ( parent, |this| visit:: walk_anon_const ( this, constant) ) ;
366+ if let MgcaDisambiguation :: Direct = constant. mgca_disambiguation
367+ && self . resolver . tcx . features ( ) . min_generic_const_args ( )
368+ {
369+ self . with_direct_const_arg ( true , |this| {
370+ visit:: walk_anon_const ( this, constant) ;
371+ } ) ;
372+ } else {
373+ self . with_direct_const_arg ( false , |this| {
374+ let parent =
375+ this. create_def ( constant. id , None , DefKind :: AnonConst , constant. value . span ) ;
376+ this. with_parent ( parent, |this| visit:: walk_anon_const ( this, constant) ) ;
377+ } )
378+ }
362379 }
363380
364381 fn visit_expr ( & mut self , expr : & ' a Expr ) {
382+ let handle_const_block = |this : & mut Self , constant : & ' a AnonConst , def_kind : DefKind | {
383+ for attr in & expr. attrs {
384+ visit:: walk_attribute ( this, attr) ;
385+ }
386+
387+ let def = this. create_def ( constant. id , None , def_kind, constant. value . span ) ;
388+ this. with_direct_const_arg ( false , |this| {
389+ this. with_parent ( def, |this| visit:: walk_anon_const ( this, constant) ) ;
390+ } ) ;
391+ } ;
392+
365393 let parent_def = match expr. kind {
366394 ExprKind :: MacCall ( ..) => return self . visit_macro_invoc ( expr. id ) ,
367395 ExprKind :: Closure ( ..) | ExprKind :: Gen ( ..) => {
368396 self . create_def ( expr. id , None , DefKind :: Closure , expr. span )
369397 }
370398 ExprKind :: ConstBlock ( ref constant) => {
371- for attr in & expr. attrs {
372- visit:: walk_attribute ( self , attr) ;
399+ handle_const_block ( self , constant, DefKind :: InlineConst ) ;
400+ return ;
401+ }
402+ ExprKind :: Struct ( ref se) if self . invocation_parent . in_direct_const_arg => {
403+ let StructExpr { qself, path, fields, rest } = & * * se;
404+
405+ for init_expr in fields {
406+ if let ExprKind :: ConstBlock ( ref constant) = init_expr. expr . kind {
407+ handle_const_block ( self , constant, DefKind :: AnonConst ) ;
408+ } else {
409+ visit:: walk_expr_field ( self , init_expr) ;
410+ }
411+ }
412+
413+ if let Some ( qself) = qself {
414+ self . visit_qself ( qself) ;
373415 }
374- let def =
375- self . create_def ( constant. id , None , DefKind :: InlineConst , constant. value . span ) ;
376- self . with_parent ( def, |this| visit:: walk_anon_const ( this, constant) ) ;
416+ self . visit_path ( path) ;
417+
418+ match rest {
419+ StructRest :: Base ( expr) => self . visit_expr ( expr) ,
420+ _ => ( ) ,
421+ }
422+
377423 return ;
378424 }
425+ ExprKind :: Field ( ref init_expr, _) if self . invocation_parent . in_direct_const_arg => {
426+ if let ExprKind :: ConstBlock ( ref constant) = init_expr. kind {
427+ handle_const_block ( self , constant, DefKind :: AnonConst ) ;
428+ return ;
429+ } else {
430+ self . invocation_parent . parent_def
431+ }
432+ }
379433 _ => self . invocation_parent . parent_def ,
380434 } ;
381435
0 commit comments