@@ -55,8 +55,8 @@ impl PpAnn for NoAnn {}
5555
5656pub struct Comments < ' a > {
5757 sm : & ' a SourceMap ,
58- comments : Vec < Comment > ,
59- current : usize ,
58+ // Stored in reverse order so we can consume them by popping.
59+ reversed_comments : Vec < Comment > ,
6060}
6161
6262/// Returns `None` if the first `col` chars of `s` contain a non-whitespace char.
@@ -182,19 +182,17 @@ fn gather_comments(sm: &SourceMap, path: FileName, src: String) -> Vec<Comment>
182182
183183impl < ' a > Comments < ' a > {
184184 pub fn new ( sm : & ' a SourceMap , filename : FileName , input : String ) -> Comments < ' a > {
185- let comments = gather_comments ( sm, filename, input) ;
186- Comments { sm, comments, current : 0 }
185+ let mut comments = gather_comments ( sm, filename, input) ;
186+ comments. reverse ( ) ;
187+ Comments { sm, reversed_comments : comments }
187188 }
188189
189190 fn peek ( & self ) -> Option < & Comment > {
190- self . comments . get ( self . current )
191+ self . reversed_comments . last ( )
191192 }
192193
193- // FIXME: This shouldn't probably clone lmao
194194 fn next ( & mut self ) -> Option < Comment > {
195- let cmnt = self . comments . get ( self . current ) . cloned ( ) ;
196- self . current += 1 ;
197- cmnt
195+ self . reversed_comments . pop ( )
198196 }
199197
200198 fn trailing_comment (
0 commit comments