@@ -1945,7 +1945,7 @@ pub enum NestedName {
19451945 Unqualified (
19461946 CvQualifiers ,
19471947 Option < RefQualifier > ,
1948- PrefixHandle ,
1948+ Option < PrefixHandle > ,
19491949 UnqualifiedName ,
19501950 ) ,
19511951
@@ -1987,8 +1987,17 @@ impl Parse for NestedName {
19871987 } ;
19881988
19891989 match substitutable {
1990+ Some ( & Substitutable :: Prefix ( Prefix :: Unqualified ( ref name) ) ) => Ok ( (
1991+ NestedName :: Unqualified ( cv_qualifiers, ref_qualifier, None , name. clone ( ) ) ,
1992+ tail,
1993+ ) ) ,
19901994 Some ( & Substitutable :: Prefix ( Prefix :: Nested ( ref prefix, ref name) ) ) => Ok ( (
1991- NestedName :: Unqualified ( cv_qualifiers, ref_qualifier, prefix. clone ( ) , name. clone ( ) ) ,
1995+ NestedName :: Unqualified (
1996+ cv_qualifiers,
1997+ ref_qualifier,
1998+ Some ( prefix. clone ( ) ) ,
1999+ name. clone ( ) ,
2000+ ) ,
19922001 tail,
19932002 ) ) ,
19942003 Some ( & Substitutable :: Prefix ( Prefix :: Template ( ..) ) ) => Ok ( (
@@ -2020,9 +2029,10 @@ impl NestedName {
20202029 // Not public because the prefix means different things for different
20212030 // variants, and for `::Template` it actually contains part of what
20222031 // conceptually belongs to `<nested-name>`.
2023- fn prefix ( & self ) -> & PrefixHandle {
2032+ fn prefix ( & self ) -> Option < & PrefixHandle > {
20242033 match * self {
2025- NestedName :: Unqualified ( _, _, ref p, _) | NestedName :: Template ( _, _, ref p) => p,
2034+ NestedName :: Unqualified ( _, _, ref p, _) => p. as_ref ( ) ,
2035+ NestedName :: Template ( _, _, ref p) => Some ( p) ,
20262036 }
20272037 }
20282038}
@@ -2041,9 +2051,11 @@ where
20412051 match * self {
20422052 NestedName :: Unqualified ( _, _, ref p, ref name) => {
20432053 ctx. push_demangle_node ( DemangleNodeType :: NestedName ) ;
2044- p. demangle ( ctx, scope) ?;
2045- if name. accepts_double_colon ( ) {
2046- ctx. write_str ( "::" ) ?;
2054+ if let Some ( p) = p. as_ref ( ) {
2055+ p. demangle ( ctx, scope) ?;
2056+ if name. accepts_double_colon ( ) {
2057+ ctx. write_str ( "::" ) ?;
2058+ }
20472059 }
20482060 name. demangle ( ctx, scope) ?;
20492061 ctx. pop_demangle_node ( ) ;
@@ -2086,15 +2098,17 @@ impl<'a> GetLeafName<'a> for NestedName {
20862098 match * self {
20872099 NestedName :: Unqualified ( _, _, ref prefix, ref name) => name
20882100 . get_leaf_name ( subs)
2089- . or_else ( || prefix. get_leaf_name ( subs) ) ,
2101+ . or_else ( || prefix. as_ref ( ) . and_then ( |p| p . get_leaf_name ( subs) ) ) ,
20902102 NestedName :: Template ( _, _, ref prefix) => prefix. get_leaf_name ( subs) ,
20912103 }
20922104 }
20932105}
20942106
20952107impl IsCtorDtorConversion for NestedName {
20962108 fn is_ctor_dtor_conversion ( & self , subs : & SubstitutionTable ) -> bool {
2097- self . prefix ( ) . is_ctor_dtor_conversion ( subs)
2109+ self . prefix ( )
2110+ . map ( |p| p. is_ctor_dtor_conversion ( subs) )
2111+ . unwrap_or ( false )
20982112 }
20992113}
21002114
@@ -8572,7 +8586,7 @@ mod tests {
85728586 b"NS0_3abcE..." => {
85738587 Name :: Nested ( NestedName :: Unqualified ( CvQualifiers :: default ( ) ,
85748588 None ,
8575- PrefixHandle :: BackReference ( 1 ) ,
8589+ Some ( PrefixHandle :: BackReference ( 1 ) ) ,
85768590 UnqualifiedName :: Source ( SourceName ( Identifier {
85778591 start: 5 ,
85788592 end: 8 ,
@@ -8693,7 +8707,7 @@ mod tests {
86938707 const_: true ,
86948708 } ,
86958709 Some ( RefQualifier :: RValueRef ) ,
8696- PrefixHandle :: BackReference ( 0 ) ,
8710+ Some ( PrefixHandle :: BackReference ( 0 ) ) ,
86978711 UnqualifiedName :: Source (
86988712 SourceName ( Identifier {
86998713 start: 6 ,
@@ -8710,7 +8724,7 @@ mod tests {
87108724 const_: false ,
87118725 } ,
87128726 Some ( RefQualifier :: RValueRef ) ,
8713- PrefixHandle :: BackReference ( 0 ) ,
8727+ Some ( PrefixHandle :: BackReference ( 0 ) ) ,
87148728 UnqualifiedName :: Source (
87158729 SourceName ( Identifier {
87168730 start: 5 ,
@@ -8727,7 +8741,7 @@ mod tests {
87278741 const_: false ,
87288742 } ,
87298743 None ,
8730- PrefixHandle :: BackReference ( 0 ) ,
8744+ Some ( PrefixHandle :: BackReference ( 0 ) ) ,
87318745 UnqualifiedName :: Source (
87328746 SourceName ( Identifier {
87338747 start: 4 ,
@@ -8736,6 +8750,23 @@ mod tests {
87368750 b"..." ,
87378751 [ ]
87388752 }
8753+ b"NK1fE..." => {
8754+ NestedName :: Unqualified (
8755+ CvQualifiers {
8756+ restrict: false ,
8757+ volatile: false ,
8758+ const_: true ,
8759+ } ,
8760+ None ,
8761+ None ,
8762+ UnqualifiedName :: Source (
8763+ SourceName ( Identifier {
8764+ start: 3 ,
8765+ end: 4 ,
8766+ } ) ) ) ,
8767+ b"..." ,
8768+ [ ]
8769+ }
87398770 b"NKOS_3abcIJEEE..." => {
87408771 NestedName :: Template (
87418772 CvQualifiers {
@@ -8802,7 +8833,6 @@ mod tests {
88028833 }
88038834 Err => {
88048835 // Ends with a prefix that is not a name or template.
8805- b"NS_E..." => Error :: UnexpectedText ,
88068836 b"NS_DttrEE..." => Error :: UnexpectedText ,
88078837
88088838 b"zzz" => Error :: UnexpectedText ,
0 commit comments