File tree Expand file tree Collapse file tree 2 files changed +15
-21
lines changed Expand file tree Collapse file tree 2 files changed +15
-21
lines changed Original file line number Diff line number Diff line change @@ -280,7 +280,7 @@ fn convert_tokens<C: TokenConvertor>(conv: &mut C) -> tt::Subtree {
280280 parent. subtree . token_trees . extend ( entry. subtree . token_trees ) ;
281281 }
282282
283- let subtree = stack. into_first ( ) . subtree ;
283+ let subtree = stack. into_last ( ) . subtree ;
284284 if let [ tt:: TokenTree :: Subtree ( first) ] = & * subtree. token_trees {
285285 first. clone ( )
286286 } else {
Original file line number Diff line number Diff line change 1- //! A [`Vec`] that is guaranteed to at least contain one element .
1+ //! See [`NonEmptyVec`] .
22
3- pub struct NonEmptyVec < T > ( Vec < T > ) ;
3+ /// A [`Vec`] that is guaranteed to at least contain one element.
4+ pub struct NonEmptyVec < T > {
5+ first : T ,
6+ rest : Vec < T > ,
7+ }
48
59impl < T > NonEmptyVec < T > {
610 #[ inline]
7- pub fn new ( initial : T ) -> Self {
8- NonEmptyVec ( vec ! [ initial ] )
11+ pub fn new ( first : T ) -> Self {
12+ NonEmptyVec { first , rest : Vec :: new ( ) }
913 }
1014
1115 #[ inline]
1216 pub fn last_mut ( & mut self ) -> & mut T {
13- match self . 0 . last_mut ( ) {
14- Some ( it) => it,
15- None => unreachable ! ( ) ,
16- }
17+ self . rest . last_mut ( ) . unwrap_or ( & mut self . first )
1718 }
1819
1920 #[ inline]
2021 pub fn pop ( & mut self ) -> Option < T > {
21- if self . 0 . len ( ) <= 1 {
22- None
23- } else {
24- self . 0 . pop ( )
25- }
22+ self . rest . pop ( )
2623 }
2724
2825 #[ inline]
2926 pub fn push ( & mut self , value : T ) {
30- self . 0 . push ( value)
27+ self . rest . push ( value)
3128 }
3229
3330 #[ inline]
3431 pub fn len ( & self ) -> usize {
35- self . 0 . len ( )
32+ 1 + self . rest . len ( )
3633 }
3734
3835 #[ inline]
39- pub fn into_first ( mut self ) -> T {
40- match self . 0 . pop ( ) {
41- Some ( it) => it,
42- None => unreachable ! ( ) ,
43- }
36+ pub fn into_last ( mut self ) -> T {
37+ self . rest . pop ( ) . unwrap_or ( self . first )
4438 }
4539}
You can’t perform that action at this time.
0 commit comments