]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_ast/src/tokenstream.rs
Improve doc comment desugaring.
[rust.git] / compiler / rustc_ast / src / tokenstream.rs
index fabd43a1618a4387fa8af8680fe8a52f17af90d1..dd01fc8ffc506db7b26bd63a1cf94af6286e3709 100644 (file)
@@ -614,6 +614,15 @@ pub fn next_ref(&mut self) -> Option<&TokenTree> {
     pub fn look_ahead(&self, n: usize) -> Option<&TokenTree> {
         self.stream.0.get(self.index + n)
     }
+
+    // Replace the previously obtained token tree with `tts`, and rewind to
+    // just before them.
+    pub fn replace_prev_and_rewind(&mut self, tts: Vec<TokenTree>) {
+        assert!(self.index > 0);
+        self.index -= 1;
+        let stream = Lrc::make_mut(&mut self.stream.0);
+        stream.splice(self.index..self.index + 1, tts);
+    }
 }
 
 #[derive(Debug, Copy, Clone, PartialEq, Encodable, Decodable, HashStable_Generic)]