@@ -13,15 +13,15 @@ use rustc_span::hygiene::LocalExpnId;
1313use rustc_span:: { Span , Symbol , sym} ;
1414use tracing:: debug;
1515
16- use crate :: { ImplTraitContext , InvocationParent , Resolver } ;
16+ use crate :: { FxHashMap , ImplTraitContext , InvocationParent , Resolver } ;
1717
1818pub ( crate ) fn collect_definitions (
1919 resolver : & mut Resolver < ' _ , ' _ > ,
2020 fragment : & AstFragment ,
2121 expansion : LocalExpnId ,
2222) {
2323 let invocation_parent = resolver. invocation_parents [ & expansion] ;
24- let mut visitor = DefCollector { resolver, expansion, invocation_parent } ;
24+ let mut visitor = DefCollector { resolver, expansion, invocation_parent, overriden_anon_const_spans : FxHashMap :: default ( ) , } ;
2525 fragment. visit_with ( & mut visitor) ;
2626}
2727
@@ -30,6 +30,7 @@ struct DefCollector<'a, 'ra, 'tcx> {
3030 resolver : & ' a mut Resolver < ' ra , ' tcx > ,
3131 invocation_parent : InvocationParent ,
3232 expansion : LocalExpnId ,
33+ overriden_anon_const_spans : FxHashMap < NodeId , Span > ,
3334}
3435
3536impl < ' a , ' ra , ' tcx > DefCollector < ' a , ' ra , ' tcx > {
@@ -121,7 +122,13 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
121122 mutability : s. mutability ,
122123 nested : false ,
123124 } ,
124- ItemKind :: Const ( ..) => DefKind :: Const ,
125+ ItemKind :: Const ( box ConstItem { body, .. } ) => {
126+ if let Some ( anon) = body {
127+ self . overriden_anon_const_spans . insert ( anon. id , i. span ) ;
128+ }
129+
130+ DefKind :: Const
131+ }
125132 ItemKind :: Fn ( ..) | ItemKind :: Delegation ( ..) => DefKind :: Fn ,
126133 ItemKind :: MacroDef ( ident, def) => {
127134 let edition = i. span . edition ( ) ;
@@ -338,7 +345,13 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
338345 let ( ident, def_kind) = match & i. kind {
339346 AssocItemKind :: Fn ( box Fn { ident, .. } )
340347 | AssocItemKind :: Delegation ( box Delegation { ident, .. } ) => ( * ident, DefKind :: AssocFn ) ,
341- AssocItemKind :: Const ( box ConstItem { ident, .. } ) => ( * ident, DefKind :: AssocConst ) ,
348+ AssocItemKind :: Const ( box ConstItem { ident, body, .. } ) => {
349+ if let Some ( anon) = body {
350+ self . overriden_anon_const_spans . insert ( anon. id , i. span ) ;
351+ }
352+
353+ ( * ident, DefKind :: AssocConst )
354+ } ,
342355 AssocItemKind :: Type ( box TyAlias { ident, .. } ) => ( * ident, DefKind :: AssocTy ) ,
343356 AssocItemKind :: MacCall ( ..) | AssocItemKind :: DelegationMac ( ..) => {
344357 return self . visit_macro_invoc ( i. id ) ;
@@ -357,7 +370,10 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
357370 }
358371
359372 fn visit_anon_const ( & mut self , constant : & ' a AnonConst ) {
360- let parent = self . create_def ( constant. id , None , DefKind :: AnonConst , constant. value . span ) ;
373+ // TODO: i dont think this actually does anything?? what does this span even correspond to
374+ let span = self . overriden_anon_const_spans . get ( & constant. id ) . copied ( ) . unwrap_or ( constant. value . span ) ;
375+
376+ let parent = self . create_def ( constant. id , None , DefKind :: AnonConst , span) ;
361377 self . with_parent ( parent, |this| visit:: walk_anon_const ( this, constant) ) ;
362378 }
363379
0 commit comments