blob: 5c2dd8a8d61a0ac45a0bfc639acd2b6acc8f9778 [file] [log] [blame]
David Tolnay7c3e77d2018-01-06 17:42:53 -08001//! A stably addressed token buffer supporting efficient traversal based on a
2//! cheaply copyable cursor.
Michael Layzell2a60e252017-05-31 21:36:47 -04003//!
David Tolnay461d98e2018-01-07 11:07:19 -08004//! *This module is available if Syn is built with the `"parsing"` feature.*
Michael Layzell2a60e252017-05-31 21:36:47 -04005
David Tolnay57cf7522018-12-31 17:10:45 -05006// This module is heavily commented as it contains most of the unsafe code in
7// Syn, and caution should be used when editing it. The public-facing interface
8// is 100% safe but the implementation is fragile internally.
David Tolnay7c3e77d2018-01-06 17:42:53 -08009
David Tolnay278f9e32018-08-14 22:41:11 -070010#[cfg(all(
Chih-Hung Hsieh467ea212019-10-31 17:36:47 -070011 not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "wasi"))),
David Tolnay278f9e32018-08-14 22:41:11 -070012 feature = "proc-macro"
13))]
Chih-Hung Hsieh467ea212019-10-31 17:36:47 -070014use crate::proc_macro as pm;
David Tolnay66cb0c42018-08-31 09:01:30 -070015use proc_macro2::{Delimiter, Group, Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree};
Michael Layzell2a60e252017-05-31 21:36:47 -040016
Michael Layzell2a60e252017-05-31 21:36:47 -040017use std::marker::PhantomData;
David Tolnay94d2b792018-04-29 12:26:10 -070018use std::ptr;
Michael Layzell2a60e252017-05-31 21:36:47 -040019
Chih-Hung Hsieh467ea212019-10-31 17:36:47 -070020use crate::Lifetime;
David Tolnay66cb0c42018-08-31 09:01:30 -070021
David Tolnay7c3e77d2018-01-06 17:42:53 -080022/// Internal type which is used instead of `TokenTree` to represent a token tree
23/// within a `TokenBuffer`.
Michael Layzell2a60e252017-05-31 21:36:47 -040024enum Entry {
David Tolnay7c3e77d2018-01-06 17:42:53 -080025 // Mimicking types from proc-macro.
David Tolnay582a45e2018-09-08 17:56:31 -070026 Group(Group, TokenBuffer),
Alex Crichtona74a1c82018-05-16 10:20:44 -070027 Ident(Ident),
28 Punct(Punct),
Alex Crichton9a4dca22018-03-28 06:32:19 -070029 Literal(Literal),
David Tolnay7c3e77d2018-01-06 17:42:53 -080030 // End entries contain a raw pointer to the entry from the containing
31 // token tree, or null if this is the outermost level.
Michael Layzell2a60e252017-05-31 21:36:47 -040032 End(*const Entry),
33}
34
David Tolnay7c3e77d2018-01-06 17:42:53 -080035/// A buffer that can be efficiently traversed multiple times, unlike
36/// `TokenStream` which requires a deep copy in order to traverse more than
37/// once.
38///
David Tolnay461d98e2018-01-07 11:07:19 -080039/// *This type is available if Syn is built with the `"parsing"` feature.*
David Tolnaydfc886b2018-01-06 08:03:09 -080040pub struct TokenBuffer {
Michael Layzell2a60e252017-05-31 21:36:47 -040041 // NOTE: Do not derive clone on this - there are raw pointers inside which
David Tolnaydfc886b2018-01-06 08:03:09 -080042 // will be messed up. Moving the `TokenBuffer` itself is safe as the actual
Michael Layzell2a60e252017-05-31 21:36:47 -040043 // backing slices won't be moved.
44 data: Box<[Entry]>,
45}
46
David Tolnaydfc886b2018-01-06 08:03:09 -080047impl TokenBuffer {
Michael Layzell2a60e252017-05-31 21:36:47 -040048 // NOTE: DO NOT MUTATE THE `Vec` RETURNED FROM THIS FUNCTION ONCE IT
49 // RETURNS, THE ADDRESS OF ITS BACKING MEMORY MUST REMAIN STABLE.
David Tolnaydfc886b2018-01-06 08:03:09 -080050 fn inner_new(stream: TokenStream, up: *const Entry) -> TokenBuffer {
Alex Crichtonf9e8f1a2017-07-05 18:20:44 -070051 // Build up the entries list, recording the locations of any Groups
Michael Layzell2a60e252017-05-31 21:36:47 -040052 // in the list to be processed later.
53 let mut entries = Vec::new();
54 let mut seqs = Vec::new();
David Tolnay50fa4682017-12-26 23:17:22 -050055 for tt in stream {
Alex Crichton9a4dca22018-03-28 06:32:19 -070056 match tt {
Alex Crichtona74a1c82018-05-16 10:20:44 -070057 TokenTree::Ident(sym) => {
58 entries.push(Entry::Ident(sym));
Michael Layzell2a60e252017-05-31 21:36:47 -040059 }
Alex Crichtona74a1c82018-05-16 10:20:44 -070060 TokenTree::Punct(op) => {
61 entries.push(Entry::Punct(op));
Michael Layzell2a60e252017-05-31 21:36:47 -040062 }
Alex Crichton9a4dca22018-03-28 06:32:19 -070063 TokenTree::Literal(l) => {
64 entries.push(Entry::Literal(l));
Michael Layzell2a60e252017-05-31 21:36:47 -040065 }
Alex Crichton9a4dca22018-03-28 06:32:19 -070066 TokenTree::Group(g) => {
Michael Layzell2a60e252017-05-31 21:36:47 -040067 // Record the index of the interesting entry, and store an
68 // `End(null)` there temporarially.
David Tolnay582a45e2018-09-08 17:56:31 -070069 seqs.push((entries.len(), g));
Michael Layzell2a60e252017-05-31 21:36:47 -040070 entries.push(Entry::End(ptr::null()));
71 }
72 }
73 }
74 // Add an `End` entry to the end with a reference to the enclosing token
75 // stream which was passed in.
76 entries.push(Entry::End(up));
77
78 // NOTE: This is done to ensure that we don't accidentally modify the
79 // length of the backing buffer. The backing buffer must remain at a
80 // constant address after this point, as we are going to store a raw
81 // pointer into it.
82 let mut entries = entries.into_boxed_slice();
David Tolnay582a45e2018-09-08 17:56:31 -070083 for (idx, group) in seqs {
Michael Layzell2a60e252017-05-31 21:36:47 -040084 // We know that this index refers to one of the temporary
85 // `End(null)` entries, and we know that the last entry is
86 // `End(up)`, so the next index is also valid.
87 let seq_up = &entries[idx + 1] as *const Entry;
88
Alex Crichtonf9e8f1a2017-07-05 18:20:44 -070089 // The end entry stored at the end of this Entry::Group should
90 // point to the Entry which follows the Group in the list.
David Tolnay582a45e2018-09-08 17:56:31 -070091 let inner = Self::inner_new(group.stream(), seq_up);
92 entries[idx] = Entry::Group(group, inner);
Michael Layzell2a60e252017-05-31 21:36:47 -040093 }
94
David Tolnaydfc886b2018-01-06 08:03:09 -080095 TokenBuffer { data: entries }
Michael Layzell2a60e252017-05-31 21:36:47 -040096 }
97
David Tolnay7c3e77d2018-01-06 17:42:53 -080098 /// Creates a `TokenBuffer` containing all the tokens from the input
99 /// `TokenStream`.
hcpl4b72a382018-04-04 14:50:24 +0300100 ///
101 /// *This method is available if Syn is built with both the `"parsing"` and
102 /// `"proc-macro"` features.*
David Tolnay278f9e32018-08-14 22:41:11 -0700103 #[cfg(all(
Chih-Hung Hsieh467ea212019-10-31 17:36:47 -0700104 not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "wasi"))),
David Tolnay278f9e32018-08-14 22:41:11 -0700105 feature = "proc-macro"
106 ))]
David Tolnay7c3e77d2018-01-06 17:42:53 -0800107 pub fn new(stream: pm::TokenStream) -> TokenBuffer {
108 Self::new2(stream.into())
109 }
110
111 /// Creates a `TokenBuffer` containing all the tokens from the input
112 /// `TokenStream`.
113 pub fn new2(stream: TokenStream) -> TokenBuffer {
Michael Layzell2a60e252017-05-31 21:36:47 -0400114 Self::inner_new(stream, ptr::null())
115 }
116
David Tolnay7c3e77d2018-01-06 17:42:53 -0800117 /// Creates a cursor referencing the first token in the buffer and able to
118 /// traverse until the end of the buffer.
Michael Layzell2a60e252017-05-31 21:36:47 -0400119 pub fn begin(&self) -> Cursor {
David Tolnay51382052017-12-27 13:46:21 -0500120 unsafe { Cursor::create(&self.data[0], &self.data[self.data.len() - 1]) }
Michael Layzell2a60e252017-05-31 21:36:47 -0400121 }
122}
123
David Tolnay7c3e77d2018-01-06 17:42:53 -0800124/// A cheaply copyable cursor into a `TokenBuffer`.
125///
126/// This cursor holds a shared reference into the immutable data which is used
127/// internally to represent a `TokenStream`, and can be efficiently manipulated
128/// and copied around.
Michael Layzell2a60e252017-05-31 21:36:47 -0400129///
David Tolnaydfc886b2018-01-06 08:03:09 -0800130/// An empty `Cursor` can be created directly, or one may create a `TokenBuffer`
Michael Layzell2a60e252017-05-31 21:36:47 -0400131/// object and get a cursor to its first token with `begin()`.
132///
133/// Two cursors are equal if they have the same location in the same input
134/// stream, and have the same scope.
David Tolnay7c3e77d2018-01-06 17:42:53 -0800135///
David Tolnay461d98e2018-01-07 11:07:19 -0800136/// *This type is available if Syn is built with the `"parsing"` feature.*
Michael Layzell2a60e252017-05-31 21:36:47 -0400137#[derive(Copy, Clone, Eq, PartialEq)]
138pub struct Cursor<'a> {
David Tolnay56924f42018-09-02 08:24:58 -0700139 // The current entry which the `Cursor` is pointing at.
Michael Layzell2a60e252017-05-31 21:36:47 -0400140 ptr: *const Entry,
David Tolnay56924f42018-09-02 08:24:58 -0700141 // This is the only `Entry::End(..)` object which this cursor is allowed to
142 // point at. All other `End` objects are skipped over in `Cursor::create`.
Michael Layzell2a60e252017-05-31 21:36:47 -0400143 scope: *const Entry,
David Tolnay56924f42018-09-02 08:24:58 -0700144 // Cursor is covariant in 'a. This field ensures that our pointers are still
145 // valid.
Michael Layzell2a60e252017-05-31 21:36:47 -0400146 marker: PhantomData<&'a Entry>,
147}
148
Michael Layzell2a60e252017-05-31 21:36:47 -0400149impl<'a> Cursor<'a> {
David Tolnay7c3e77d2018-01-06 17:42:53 -0800150 /// Creates a cursor referencing a static empty TokenStream.
Michael Layzell2a60e252017-05-31 21:36:47 -0400151 pub fn empty() -> Self {
Michael Layzell69cf9082017-06-03 12:15:58 -0400152 // It's safe in this situation for us to put an `Entry` object in global
153 // storage, despite it not actually being safe to send across threads
Alex Crichtona74a1c82018-05-16 10:20:44 -0700154 // (`Ident` is a reference into a thread-local table). This is because
155 // this entry never includes a `Ident` object.
Michael Layzell69cf9082017-06-03 12:15:58 -0400156 //
157 // This wrapper struct allows us to break the rules and put a `Sync`
158 // object in global storage.
159 struct UnsafeSyncEntry(Entry);
160 unsafe impl Sync for UnsafeSyncEntry {}
David Tolnay51382052017-12-27 13:46:21 -0500161 static EMPTY_ENTRY: UnsafeSyncEntry = UnsafeSyncEntry(Entry::End(0 as *const Entry));
Michael Layzell69cf9082017-06-03 12:15:58 -0400162
Michael Layzell2a60e252017-05-31 21:36:47 -0400163 Cursor {
Michael Layzell69cf9082017-06-03 12:15:58 -0400164 ptr: &EMPTY_ENTRY.0,
165 scope: &EMPTY_ENTRY.0,
Michael Layzell2a60e252017-05-31 21:36:47 -0400166 marker: PhantomData,
167 }
168 }
169
170 /// This create method intelligently exits non-explicitly-entered
171 /// `None`-delimited scopes when the cursor reaches the end of them,
172 /// allowing for them to be treated transparently.
173 unsafe fn create(mut ptr: *const Entry, scope: *const Entry) -> Self {
174 // NOTE: If we're looking at a `End(..)`, we want to advance the cursor
175 // past it, unless `ptr == scope`, which means that we're at the edge of
176 // our cursor's scope. We should only have `ptr != scope` at the exit
David Tolnayc10676a2017-12-27 23:42:36 -0500177 // from None-delimited groups entered with `ignore_none`.
Michael Layzell2a60e252017-05-31 21:36:47 -0400178 while let Entry::End(exit) = *ptr {
179 if ptr == scope {
180 break;
181 }
182 ptr = exit;
183 }
184
185 Cursor {
Chih-Hung Hsieh467ea212019-10-31 17:36:47 -0700186 ptr,
187 scope,
Michael Layzell2a60e252017-05-31 21:36:47 -0400188 marker: PhantomData,
189 }
190 }
191
192 /// Get the current entry.
193 fn entry(self) -> &'a Entry {
194 unsafe { &*self.ptr }
195 }
196
197 /// Bump the cursor to point at the next token after the current one. This
198 /// is undefined behavior if the cursor is currently looking at an
199 /// `Entry::End`.
200 unsafe fn bump(self) -> Cursor<'a> {
201 Cursor::create(self.ptr.offset(1), self.scope)
202 }
203
David Tolnayc10676a2017-12-27 23:42:36 -0500204 /// If the cursor is looking at a `None`-delimited group, move it to look at
205 /// the first token inside instead. If the group is empty, this will move
206 /// the cursor past the `None`-delimited group.
Michael Layzell2a60e252017-05-31 21:36:47 -0400207 ///
208 /// WARNING: This mutates its argument.
209 fn ignore_none(&mut self) {
Chih-Hung Hsieh467ea212019-10-31 17:36:47 -0700210 if let Entry::Group(group, buf) = self.entry() {
David Tolnay582a45e2018-09-08 17:56:31 -0700211 if group.delimiter() == Delimiter::None {
212 // NOTE: We call `Cursor::create` here to make sure that
213 // situations where we should immediately exit the span after
214 // entering it are handled correctly.
215 unsafe {
216 *self = Cursor::create(&buf.data[0], self.scope);
217 }
Michael Layzell2a60e252017-05-31 21:36:47 -0400218 }
219 }
220 }
221
David Tolnay7c3e77d2018-01-06 17:42:53 -0800222 /// Checks whether the cursor is currently pointing at the end of its valid
223 /// scope.
Michael Layzell2a60e252017-05-31 21:36:47 -0400224 pub fn eof(self) -> bool {
225 // We're at eof if we're at the end of our scope.
226 self.ptr == self.scope
227 }
228
David Tolnay7c3e77d2018-01-06 17:42:53 -0800229 /// If the cursor is pointing at a `Group` with the given delimiter, returns
230 /// a cursor into that group and one pointing to the next `TokenTree`.
David Tolnay65729482017-12-31 16:14:50 -0500231 pub fn group(mut self, delim: Delimiter) -> Option<(Cursor<'a>, Span, Cursor<'a>)> {
David Tolnayc10676a2017-12-27 23:42:36 -0500232 // If we're not trying to enter a none-delimited group, we want to
Michael Layzell2a60e252017-05-31 21:36:47 -0400233 // ignore them. We have to make sure to _not_ ignore them when we want
234 // to enter them, of course. For obvious reasons.
David Tolnayc10676a2017-12-27 23:42:36 -0500235 if delim != Delimiter::None {
Michael Layzell2a60e252017-05-31 21:36:47 -0400236 self.ignore_none();
237 }
238
Chih-Hung Hsieh467ea212019-10-31 17:36:47 -0700239 if let Entry::Group(group, buf) = self.entry() {
David Tolnay582a45e2018-09-08 17:56:31 -0700240 if group.delimiter() == delim {
241 return Some((buf.begin(), group.span(), unsafe { self.bump() }));
Michael Layzell2a60e252017-05-31 21:36:47 -0400242 }
Michael Layzell2a60e252017-05-31 21:36:47 -0400243 }
David Tolnayc10676a2017-12-27 23:42:36 -0500244
245 None
Michael Layzell2a60e252017-05-31 21:36:47 -0400246 }
247
Alex Crichtona74a1c82018-05-16 10:20:44 -0700248 /// If the cursor is pointing at a `Ident`, returns it along with a cursor
David Tolnay7c3e77d2018-01-06 17:42:53 -0800249 /// pointing at the next `TokenTree`.
David Tolnay55a5f3a2018-05-20 18:00:51 -0700250 pub fn ident(mut self) -> Option<(Ident, Cursor<'a>)> {
Michael Layzell2a60e252017-05-31 21:36:47 -0400251 self.ignore_none();
Chih-Hung Hsieh467ea212019-10-31 17:36:47 -0700252 match self.entry() {
253 Entry::Ident(ident) => Some((ident.clone(), unsafe { self.bump() })),
David Tolnay51382052017-12-27 13:46:21 -0500254 _ => None,
Michael Layzell2a60e252017-05-31 21:36:47 -0400255 }
256 }
257
Alex Crichtona74a1c82018-05-16 10:20:44 -0700258 /// If the cursor is pointing at an `Punct`, returns it along with a cursor
David Tolnay7c3e77d2018-01-06 17:42:53 -0800259 /// pointing at the next `TokenTree`.
David Tolnay55a5f3a2018-05-20 18:00:51 -0700260 pub fn punct(mut self) -> Option<(Punct, Cursor<'a>)> {
Michael Layzell2a60e252017-05-31 21:36:47 -0400261 self.ignore_none();
Chih-Hung Hsieh467ea212019-10-31 17:36:47 -0700262 match self.entry() {
263 Entry::Punct(op) if op.as_char() != '\'' => Some((op.clone(), unsafe { self.bump() })),
David Tolnay51382052017-12-27 13:46:21 -0500264 _ => None,
Michael Layzell2a60e252017-05-31 21:36:47 -0400265 }
266 }
267
David Tolnay7c3e77d2018-01-06 17:42:53 -0800268 /// If the cursor is pointing at a `Literal`, return it along with a cursor
269 /// pointing at the next `TokenTree`.
Alex Crichton9a4dca22018-03-28 06:32:19 -0700270 pub fn literal(mut self) -> Option<(Literal, Cursor<'a>)> {
Michael Layzell2a60e252017-05-31 21:36:47 -0400271 self.ignore_none();
Chih-Hung Hsieh467ea212019-10-31 17:36:47 -0700272 match self.entry() {
273 Entry::Literal(lit) => Some((lit.clone(), unsafe { self.bump() })),
David Tolnay51382052017-12-27 13:46:21 -0500274 _ => None,
Michael Layzell2a60e252017-05-31 21:36:47 -0400275 }
276 }
277
David Tolnay66cb0c42018-08-31 09:01:30 -0700278 /// If the cursor is pointing at a `Lifetime`, returns it along with a
279 /// cursor pointing at the next `TokenTree`.
280 pub fn lifetime(mut self) -> Option<(Lifetime, Cursor<'a>)> {
281 self.ignore_none();
Chih-Hung Hsieh467ea212019-10-31 17:36:47 -0700282 match self.entry() {
283 Entry::Punct(op) if op.as_char() == '\'' && op.spacing() == Spacing::Joint => {
David Tolnay66cb0c42018-08-31 09:01:30 -0700284 let next = unsafe { self.bump() };
285 match next.ident() {
286 Some((ident, rest)) => {
287 let lifetime = Lifetime {
288 apostrophe: op.span(),
Chih-Hung Hsieh467ea212019-10-31 17:36:47 -0700289 ident,
David Tolnay66cb0c42018-08-31 09:01:30 -0700290 };
291 Some((lifetime, rest))
292 }
293 None => None,
294 }
295 }
296 _ => None,
297 }
298 }
299
David Tolnay7c3e77d2018-01-06 17:42:53 -0800300 /// Copies all remaining tokens visible from this cursor into a
301 /// `TokenStream`.
Michael Layzell2a60e252017-05-31 21:36:47 -0400302 pub fn token_stream(self) -> TokenStream {
303 let mut tts = Vec::new();
304 let mut cursor = self;
David Tolnay65729482017-12-31 16:14:50 -0500305 while let Some((tt, rest)) = cursor.token_tree() {
Michael Layzell2a60e252017-05-31 21:36:47 -0400306 tts.push(tt);
David Tolnay65729482017-12-31 16:14:50 -0500307 cursor = rest;
Michael Layzell2a60e252017-05-31 21:36:47 -0400308 }
309 tts.into_iter().collect()
310 }
311
David Tolnay7c3e77d2018-01-06 17:42:53 -0800312 /// If the cursor is pointing at a `TokenTree`, returns it along with a
313 /// cursor pointing at the next `TokenTree`.
Michael Layzell2a60e252017-05-31 21:36:47 -0400314 ///
David Tolnay7c3e77d2018-01-06 17:42:53 -0800315 /// Returns `None` if the cursor has reached the end of its stream.
316 ///
317 /// This method does not treat `None`-delimited groups as transparent, and
Alex Crichtonf9e8f1a2017-07-05 18:20:44 -0700318 /// will return a `Group(None, ..)` if the cursor is looking at one.
David Tolnay65729482017-12-31 16:14:50 -0500319 pub fn token_tree(self) -> Option<(TokenTree, Cursor<'a>)> {
Chih-Hung Hsieh467ea212019-10-31 17:36:47 -0700320 let tree = match self.entry() {
321 Entry::Group(group, _) => group.clone().into(),
322 Entry::Literal(lit) => lit.clone().into(),
323 Entry::Ident(ident) => ident.clone().into(),
324 Entry::Punct(op) => op.clone().into(),
Michael Layzell2a60e252017-05-31 21:36:47 -0400325 Entry::End(..) => {
326 return None;
327 }
328 };
329
David Tolnay65729482017-12-31 16:14:50 -0500330 Some((tree, unsafe { self.bump() }))
Michael Layzell2a60e252017-05-31 21:36:47 -0400331 }
David Tolnay225efa22017-12-31 16:51:29 -0500332
333 /// Returns the `Span` of the current token, or `Span::call_site()` if this
334 /// cursor points to eof.
335 pub fn span(self) -> Span {
Chih-Hung Hsieh467ea212019-10-31 17:36:47 -0700336 match self.entry() {
337 Entry::Group(group, _) => group.span(),
338 Entry::Literal(l) => l.span(),
339 Entry::Ident(t) => t.span(),
340 Entry::Punct(o) => o.span(),
David Tolnay225efa22017-12-31 16:51:29 -0500341 Entry::End(..) => Span::call_site(),
342 }
343 }
Chih-Hung Hsieh218e2692020-03-20 13:02:10 -0700344
345 /// Skip over the next token without cloning it. Returns `None` if this
346 /// cursor points to eof.
347 ///
348 /// This method treats `'lifetimes` as a single token.
349 pub(crate) fn skip(self) -> Option<Cursor<'a>> {
350 match self.entry() {
351 Entry::End(..) => None,
352
353 // Treat lifetimes as a single tt for the purposes of 'skip'.
354 Entry::Punct(op) if op.as_char() == '\'' && op.spacing() == Spacing::Joint => {
355 let next = unsafe { self.bump() };
356 match next.entry() {
357 Entry::Ident(_) => Some(unsafe { next.bump() }),
358 _ => Some(next),
359 }
360 }
361 _ => Some(unsafe { self.bump() }),
362 }
363 }
Michael Layzell2a60e252017-05-31 21:36:47 -0400364}
David Tolnayfe89fcc2018-09-08 17:56:31 -0700365
Chih-Hung Hsieh467ea212019-10-31 17:36:47 -0700366pub(crate) fn same_scope(a: Cursor, b: Cursor) -> bool {
367 a.scope == b.scope
368}
David Tolnay6db0f2a2019-06-23 13:37:39 -0700369
Chih-Hung Hsieh467ea212019-10-31 17:36:47 -0700370pub(crate) fn open_span_of_group(cursor: Cursor) -> Span {
371 match cursor.entry() {
372 Entry::Group(group, _) => group.span_open(),
373 _ => cursor.span(),
David Tolnayfe89fcc2018-09-08 17:56:31 -0700374 }
Chih-Hung Hsieh467ea212019-10-31 17:36:47 -0700375}
David Tolnayfe89fcc2018-09-08 17:56:31 -0700376
Chih-Hung Hsieh467ea212019-10-31 17:36:47 -0700377pub(crate) fn close_span_of_group(cursor: Cursor) -> Span {
378 match cursor.entry() {
379 Entry::Group(group, _) => group.span_close(),
380 _ => cursor.span(),
David Tolnayfe89fcc2018-09-08 17:56:31 -0700381 }
382}