X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_ast%2Fsrc%2Ftokenstream.rs;h=dd01fc8ffc506db7b26bd63a1cf94af6286e3709;hb=af1d16e82ddc27166438e8bc2a520087862f12af;hp=fabd43a1618a4387fa8af8680fe8a52f17af90d1;hpb=5773e8baf017956849f821d5c85837ca1162b4ae;p=rust.git diff --git a/compiler/rustc_ast/src/tokenstream.rs b/compiler/rustc_ast/src/tokenstream.rs index fabd43a1618..dd01fc8ffc5 100644 --- a/compiler/rustc_ast/src/tokenstream.rs +++ b/compiler/rustc_ast/src/tokenstream.rs @@ -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) { + 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)]