]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_ast/src/tokenstream.rs
Merge commit '7c7683c8efe447b251d6c5ca6cce51233060f6e8' into clippyup
[rust.git] / compiler / rustc_ast / src / tokenstream.rs
1 //! # Token Streams
2 //!
3 //! `TokenStream`s represent syntactic objects before they are converted into ASTs.
4 //! A `TokenStream` is, roughly speaking, a sequence of [`TokenTree`]s,
5 //! which are themselves a single [`Token`] or a `Delimited` subsequence of tokens.
6 //!
7 //! ## Ownership
8 //!
9 //! `TokenStream`s are persistent data structures constructed as ropes with reference
10 //! counted-children. In general, this means that calling an operation on a `TokenStream`
11 //! (such as `slice`) produces an entirely new `TokenStream` from the borrowed reference to
12 //! the original. This essentially coerces `TokenStream`s into "views" of their subparts,
13 //! and a borrowed `TokenStream` is sufficient to build an owned `TokenStream` without taking
14 //! ownership of the original.
15
16 use crate::token::{self, DelimToken, Token, TokenKind};
17 use crate::AttrVec;
18
19 use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
20 use rustc_data_structures::sync::{self, Lrc};
21 use rustc_macros::HashStable_Generic;
22 use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
23 use rustc_span::{Span, DUMMY_SP};
24 use smallvec::{smallvec, SmallVec};
25
26 use std::{fmt, iter, mem};
27
28 /// When the main Rust parser encounters a syntax-extension invocation, it
29 /// parses the arguments to the invocation as a token tree. This is a very
30 /// loose structure, such that all sorts of different AST fragments can
31 /// be passed to syntax extensions using a uniform type.
32 ///
33 /// If the syntax extension is an MBE macro, it will attempt to match its
34 /// LHS token tree against the provided token tree, and if it finds a
35 /// match, will transcribe the RHS token tree, splicing in any captured
36 /// `macro_parser::matched_nonterminals` into the `SubstNt`s it finds.
37 ///
38 /// The RHS of an MBE macro is the only place `SubstNt`s are substituted.
39 /// Nothing special happens to misnamed or misplaced `SubstNt`s.
40 #[derive(Debug, Clone, PartialEq, Encodable, Decodable, HashStable_Generic)]
41 pub enum TokenTree {
42     /// A single token.
43     Token(Token),
44     /// A delimited sequence of token trees.
45     Delimited(DelimSpan, DelimToken, TokenStream),
46 }
47
48 #[derive(Copy, Clone)]
49 pub enum CanSynthesizeMissingTokens {
50     Yes,
51     No,
52 }
53
54 // Ensure all fields of `TokenTree` is `Send` and `Sync`.
55 #[cfg(parallel_compiler)]
56 fn _dummy()
57 where
58     Token: Send + Sync,
59     DelimSpan: Send + Sync,
60     DelimToken: Send + Sync,
61     TokenStream: Send + Sync,
62 {
63 }
64
65 impl TokenTree {
66     /// Checks if this `TokenTree` is equal to the other, regardless of span information.
67     pub fn eq_unspanned(&self, other: &TokenTree) -> bool {
68         match (self, other) {
69             (TokenTree::Token(token), TokenTree::Token(token2)) => token.kind == token2.kind,
70             (TokenTree::Delimited(_, delim, tts), TokenTree::Delimited(_, delim2, tts2)) => {
71                 delim == delim2 && tts.eq_unspanned(&tts2)
72             }
73             _ => false,
74         }
75     }
76
77     /// Retrieves the `TokenTree`'s span.
78     pub fn span(&self) -> Span {
79         match self {
80             TokenTree::Token(token) => token.span,
81             TokenTree::Delimited(sp, ..) => sp.entire(),
82         }
83     }
84
85     /// Modify the `TokenTree`'s span in-place.
86     pub fn set_span(&mut self, span: Span) {
87         match self {
88             TokenTree::Token(token) => token.span = span,
89             TokenTree::Delimited(dspan, ..) => *dspan = DelimSpan::from_single(span),
90         }
91     }
92
93     pub fn token(kind: TokenKind, span: Span) -> TokenTree {
94         TokenTree::Token(Token::new(kind, span))
95     }
96
97     /// Returns the opening delimiter as a token tree.
98     pub fn open_tt(span: DelimSpan, delim: DelimToken) -> TokenTree {
99         TokenTree::token(token::OpenDelim(delim), span.open)
100     }
101
102     /// Returns the closing delimiter as a token tree.
103     pub fn close_tt(span: DelimSpan, delim: DelimToken) -> TokenTree {
104         TokenTree::token(token::CloseDelim(delim), span.close)
105     }
106
107     pub fn uninterpolate(self) -> TokenTree {
108         match self {
109             TokenTree::Token(token) => TokenTree::Token(token.uninterpolate().into_owned()),
110             tt => tt,
111         }
112     }
113 }
114
115 impl<CTX> HashStable<CTX> for TokenStream
116 where
117     CTX: crate::HashStableContext,
118 {
119     fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
120         for sub_tt in self.trees() {
121             sub_tt.hash_stable(hcx, hasher);
122         }
123     }
124 }
125
126 pub trait CreateTokenStream: sync::Send + sync::Sync {
127     fn create_token_stream(&self) -> AttrAnnotatedTokenStream;
128 }
129
130 impl CreateTokenStream for AttrAnnotatedTokenStream {
131     fn create_token_stream(&self) -> AttrAnnotatedTokenStream {
132         self.clone()
133     }
134 }
135
136 /// A lazy version of [`TokenStream`], which defers creation
137 /// of an actual `TokenStream` until it is needed.
138 /// `Box` is here only to reduce the structure size.
139 #[derive(Clone)]
140 pub struct LazyTokenStream(Lrc<Box<dyn CreateTokenStream>>);
141
142 impl LazyTokenStream {
143     pub fn new(inner: impl CreateTokenStream + 'static) -> LazyTokenStream {
144         LazyTokenStream(Lrc::new(Box::new(inner)))
145     }
146
147     pub fn create_token_stream(&self) -> AttrAnnotatedTokenStream {
148         self.0.create_token_stream()
149     }
150 }
151
152 impl fmt::Debug for LazyTokenStream {
153     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
154         write!(f, "LazyTokenStream({:?})", self.create_token_stream())
155     }
156 }
157
158 impl<S: Encoder> Encodable<S> for LazyTokenStream {
159     fn encode(&self, s: &mut S) -> Result<(), S::Error> {
160         // Used by AST json printing.
161         Encodable::encode(&self.create_token_stream(), s)
162     }
163 }
164
165 impl<D: Decoder> Decodable<D> for LazyTokenStream {
166     fn decode(_d: &mut D) -> Result<Self, D::Error> {
167         panic!("Attempted to decode LazyTokenStream");
168     }
169 }
170
171 impl<CTX> HashStable<CTX> for LazyTokenStream {
172     fn hash_stable(&self, _hcx: &mut CTX, _hasher: &mut StableHasher) {
173         panic!("Attempted to compute stable hash for LazyTokenStream");
174     }
175 }
176
177 /// A `AttrAnnotatedTokenStream` is similar to a `TokenStream`, but with extra
178 /// information about the tokens for attribute targets. This is used
179 /// during expansion to perform early cfg-expansion, and to process attributes
180 /// during proc-macro invocations.
181 #[derive(Clone, Debug, Default, Encodable, Decodable)]
182 pub struct AttrAnnotatedTokenStream(pub Lrc<Vec<(AttrAnnotatedTokenTree, Spacing)>>);
183
184 /// Like `TokenTree`, but for `AttrAnnotatedTokenStream`
185 #[derive(Clone, Debug, Encodable, Decodable)]
186 pub enum AttrAnnotatedTokenTree {
187     Token(Token),
188     Delimited(DelimSpan, DelimToken, AttrAnnotatedTokenStream),
189     /// Stores the attributes for an attribute target,
190     /// along with the tokens for that attribute target.
191     /// See `AttributesData` for more information
192     Attributes(AttributesData),
193 }
194
195 impl AttrAnnotatedTokenStream {
196     pub fn new(tokens: Vec<(AttrAnnotatedTokenTree, Spacing)>) -> AttrAnnotatedTokenStream {
197         AttrAnnotatedTokenStream(Lrc::new(tokens))
198     }
199
200     /// Converts this `AttrAnnotatedTokenStream` to a plain `TokenStream
201     /// During conversion, `AttrAnnotatedTokenTree::Attributes` get 'flattened'
202     /// back to a `TokenStream` of the form `outer_attr attr_target`.
203     /// If there are inner attributes, they are inserted into the proper
204     /// place in the attribute target tokens.
205     pub fn to_tokenstream(&self) -> TokenStream {
206         let trees: Vec<_> = self
207             .0
208             .iter()
209             .flat_map(|tree| match &tree.0 {
210                 AttrAnnotatedTokenTree::Token(inner) => {
211                     smallvec![(TokenTree::Token(inner.clone()), tree.1)].into_iter()
212                 }
213                 AttrAnnotatedTokenTree::Delimited(span, delim, stream) => smallvec![(
214                     TokenTree::Delimited(*span, *delim, stream.to_tokenstream()),
215                     tree.1,
216                 )]
217                 .into_iter(),
218                 AttrAnnotatedTokenTree::Attributes(data) => {
219                     let mut outer_attrs = Vec::new();
220                     let mut inner_attrs = Vec::new();
221                     let attrs: Vec<_> = data.attrs.clone().into();
222                     for attr in attrs {
223                         match attr.style {
224                             crate::AttrStyle::Outer => {
225                                 assert!(
226                                     inner_attrs.len() == 0,
227                                     "Found outer attribute {:?} after inner attrs {:?}",
228                                     attr,
229                                     inner_attrs
230                                 );
231                                 outer_attrs.push(attr);
232                             }
233                             crate::AttrStyle::Inner => {
234                                 inner_attrs.push(attr);
235                             }
236                         }
237                     }
238
239                     let mut target_tokens: Vec<_> = data
240                         .tokens
241                         .create_token_stream()
242                         .to_tokenstream()
243                         .0
244                         .iter()
245                         .cloned()
246                         .collect();
247                     if !inner_attrs.is_empty() {
248                         let mut found = false;
249                         // Check the last two trees (to account for a trailing semi)
250                         for (tree, _) in target_tokens.iter_mut().rev().take(2) {
251                             if let TokenTree::Delimited(span, delim, delim_tokens) = tree {
252                                 // Inner attributes are only supported on extern blocks, functions, impls,
253                                 // and modules. All of these have their inner attributes placed at
254                                 // the beginning of the rightmost outermost braced group:
255                                 // e.g. fn foo() { #![my_attr} }
256                                 //
257                                 // Therefore, we can insert them back into the right location
258                                 // without needing to do any extra position tracking.
259                                 //
260                                 // Note: Outline modules are an exception - they can
261                                 // have attributes like `#![my_attr]` at the start of a file.
262                                 // Support for custom attributes in this position is not
263                                 // properly implemented - we always synthesize fake tokens,
264                                 // so we never reach this code.
265
266                                 let mut builder = TokenStreamBuilder::new();
267                                 for inner_attr in &inner_attrs {
268                                     builder.push(inner_attr.tokens().to_tokenstream());
269                                 }
270                                 builder.push(delim_tokens.clone());
271                                 *tree = TokenTree::Delimited(*span, *delim, builder.build());
272                                 found = true;
273                                 break;
274                             }
275                         }
276
277                         assert!(
278                             found,
279                             "Failed to find trailing delimited group in: {:?}",
280                             target_tokens
281                         );
282                     }
283                     let mut flat: SmallVec<[_; 1]> = SmallVec::new();
284                     for attr in outer_attrs {
285                         // FIXME: Make this more efficient
286                         flat.extend(attr.tokens().to_tokenstream().0.clone().iter().cloned());
287                     }
288                     flat.extend(target_tokens);
289                     flat.into_iter()
290                 }
291             })
292             .collect();
293         TokenStream::new(trees)
294     }
295 }
296
297 /// Stores the tokens for an attribute target, along
298 /// with its attributes.
299 ///
300 /// This is constructed during parsing when we need to capture
301 /// tokens.
302 ///
303 /// For example, `#[cfg(FALSE)] struct Foo {}` would
304 /// have an `attrs` field containing the `#[cfg(FALSE)]` attr,
305 /// and a `tokens` field storing the (unparesd) tokens `struct Foo {}`
306 #[derive(Clone, Debug, Encodable, Decodable)]
307 pub struct AttributesData {
308     /// Attributes, both outer and inner.
309     /// These are stored in the original order that they were parsed in.
310     pub attrs: AttrVec,
311     /// The underlying tokens for the attribute target that `attrs`
312     /// are applied to
313     pub tokens: LazyTokenStream,
314 }
315
316 /// A `TokenStream` is an abstract sequence of tokens, organized into [`TokenTree`]s.
317 ///
318 /// The goal is for procedural macros to work with `TokenStream`s and `TokenTree`s
319 /// instead of a representation of the abstract syntax tree.
320 /// Today's `TokenTree`s can still contain AST via `token::Interpolated` for
321 /// backwards compatibility.
322 #[derive(Clone, Debug, Default, Encodable, Decodable)]
323 pub struct TokenStream(pub(crate) Lrc<Vec<TreeAndSpacing>>);
324
325 pub type TreeAndSpacing = (TokenTree, Spacing);
326
327 // `TokenStream` is used a lot. Make sure it doesn't unintentionally get bigger.
328 #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
329 rustc_data_structures::static_assert_size!(TokenStream, 8);
330
331 #[derive(Clone, Copy, Debug, PartialEq, Encodable, Decodable)]
332 pub enum Spacing {
333     Alone,
334     Joint,
335 }
336
337 impl TokenStream {
338     /// Given a `TokenStream` with a `Stream` of only two arguments, return a new `TokenStream`
339     /// separating the two arguments with a comma for diagnostic suggestions.
340     pub fn add_comma(&self) -> Option<(TokenStream, Span)> {
341         // Used to suggest if a user writes `foo!(a b);`
342         let mut suggestion = None;
343         let mut iter = self.0.iter().enumerate().peekable();
344         while let Some((pos, ts)) = iter.next() {
345             if let Some((_, next)) = iter.peek() {
346                 let sp = match (&ts, &next) {
347                     (_, (TokenTree::Token(Token { kind: token::Comma, .. }), _)) => continue,
348                     (
349                         (TokenTree::Token(token_left), Spacing::Alone),
350                         (TokenTree::Token(token_right), _),
351                     ) if ((token_left.is_ident() && !token_left.is_reserved_ident())
352                         || token_left.is_lit())
353                         && ((token_right.is_ident() && !token_right.is_reserved_ident())
354                             || token_right.is_lit()) =>
355                     {
356                         token_left.span
357                     }
358                     ((TokenTree::Delimited(sp, ..), Spacing::Alone), _) => sp.entire(),
359                     _ => continue,
360                 };
361                 let sp = sp.shrink_to_hi();
362                 let comma = (TokenTree::token(token::Comma, sp), Spacing::Alone);
363                 suggestion = Some((pos, comma, sp));
364             }
365         }
366         if let Some((pos, comma, sp)) = suggestion {
367             let mut new_stream = Vec::with_capacity(self.0.len() + 1);
368             let parts = self.0.split_at(pos + 1);
369             new_stream.extend_from_slice(parts.0);
370             new_stream.push(comma);
371             new_stream.extend_from_slice(parts.1);
372             return Some((TokenStream::new(new_stream), sp));
373         }
374         None
375     }
376 }
377
378 impl From<(AttrAnnotatedTokenTree, Spacing)> for AttrAnnotatedTokenStream {
379     fn from((tree, spacing): (AttrAnnotatedTokenTree, Spacing)) -> AttrAnnotatedTokenStream {
380         AttrAnnotatedTokenStream::new(vec![(tree, spacing)])
381     }
382 }
383
384 impl From<TokenTree> for TokenStream {
385     fn from(tree: TokenTree) -> TokenStream {
386         TokenStream::new(vec![(tree, Spacing::Alone)])
387     }
388 }
389
390 impl From<TokenTree> for TreeAndSpacing {
391     fn from(tree: TokenTree) -> TreeAndSpacing {
392         (tree, Spacing::Alone)
393     }
394 }
395
396 impl iter::FromIterator<TokenTree> for TokenStream {
397     fn from_iter<I: IntoIterator<Item = TokenTree>>(iter: I) -> Self {
398         TokenStream::new(iter.into_iter().map(Into::into).collect::<Vec<TreeAndSpacing>>())
399     }
400 }
401
402 impl Eq for TokenStream {}
403
404 impl PartialEq<TokenStream> for TokenStream {
405     fn eq(&self, other: &TokenStream) -> bool {
406         self.trees().eq(other.trees())
407     }
408 }
409
410 impl TokenStream {
411     pub fn new(streams: Vec<TreeAndSpacing>) -> TokenStream {
412         TokenStream(Lrc::new(streams))
413     }
414
415     pub fn is_empty(&self) -> bool {
416         self.0.is_empty()
417     }
418
419     pub fn len(&self) -> usize {
420         self.0.len()
421     }
422
423     pub fn from_streams(mut streams: SmallVec<[TokenStream; 2]>) -> TokenStream {
424         match streams.len() {
425             0 => TokenStream::default(),
426             1 => streams.pop().unwrap(),
427             _ => {
428                 // We are going to extend the first stream in `streams` with
429                 // the elements from the subsequent streams. This requires
430                 // using `make_mut()` on the first stream, and in practice this
431                 // doesn't cause cloning 99.9% of the time.
432                 //
433                 // One very common use case is when `streams` has two elements,
434                 // where the first stream has any number of elements within
435                 // (often 1, but sometimes many more) and the second stream has
436                 // a single element within.
437
438                 // Determine how much the first stream will be extended.
439                 // Needed to avoid quadratic blow up from on-the-fly
440                 // reallocations (#57735).
441                 let num_appends = streams.iter().skip(1).map(|ts| ts.len()).sum();
442
443                 // Get the first stream. If it's `None`, create an empty
444                 // stream.
445                 let mut iter = streams.drain(..);
446                 let mut first_stream_lrc = iter.next().unwrap().0;
447
448                 // Append the elements to the first stream, after reserving
449                 // space for them.
450                 let first_vec_mut = Lrc::make_mut(&mut first_stream_lrc);
451                 first_vec_mut.reserve(num_appends);
452                 for stream in iter {
453                     first_vec_mut.extend(stream.0.iter().cloned());
454                 }
455
456                 // Create the final `TokenStream`.
457                 TokenStream(first_stream_lrc)
458             }
459         }
460     }
461
462     pub fn trees(&self) -> Cursor {
463         self.clone().into_trees()
464     }
465
466     pub fn into_trees(self) -> Cursor {
467         Cursor::new(self)
468     }
469
470     /// Compares two `TokenStream`s, checking equality without regarding span information.
471     pub fn eq_unspanned(&self, other: &TokenStream) -> bool {
472         let mut t1 = self.trees();
473         let mut t2 = other.trees();
474         for (t1, t2) in iter::zip(&mut t1, &mut t2) {
475             if !t1.eq_unspanned(&t2) {
476                 return false;
477             }
478         }
479         t1.next().is_none() && t2.next().is_none()
480     }
481
482     pub fn map_enumerated<F: FnMut(usize, &TokenTree) -> TokenTree>(self, mut f: F) -> TokenStream {
483         TokenStream(Lrc::new(
484             self.0
485                 .iter()
486                 .enumerate()
487                 .map(|(i, (tree, is_joint))| (f(i, tree), *is_joint))
488                 .collect(),
489         ))
490     }
491 }
492
493 // 99.5%+ of the time we have 1 or 2 elements in this vector.
494 #[derive(Clone)]
495 pub struct TokenStreamBuilder(SmallVec<[TokenStream; 2]>);
496
497 impl TokenStreamBuilder {
498     pub fn new() -> TokenStreamBuilder {
499         TokenStreamBuilder(SmallVec::new())
500     }
501
502     pub fn push<T: Into<TokenStream>>(&mut self, stream: T) {
503         let mut stream = stream.into();
504
505         // If `self` is not empty and the last tree within the last stream is a
506         // token tree marked with `Joint`...
507         if let Some(TokenStream(ref mut last_stream_lrc)) = self.0.last_mut() {
508             if let Some((TokenTree::Token(last_token), Spacing::Joint)) = last_stream_lrc.last() {
509                 // ...and `stream` is not empty and the first tree within it is
510                 // a token tree...
511                 let TokenStream(ref mut stream_lrc) = stream;
512                 if let Some((TokenTree::Token(token), spacing)) = stream_lrc.first() {
513                     // ...and the two tokens can be glued together...
514                     if let Some(glued_tok) = last_token.glue(&token) {
515                         // ...then do so, by overwriting the last token
516                         // tree in `self` and removing the first token tree
517                         // from `stream`. This requires using `make_mut()`
518                         // on the last stream in `self` and on `stream`,
519                         // and in practice this doesn't cause cloning 99.9%
520                         // of the time.
521
522                         // Overwrite the last token tree with the merged
523                         // token.
524                         let last_vec_mut = Lrc::make_mut(last_stream_lrc);
525                         *last_vec_mut.last_mut().unwrap() = (TokenTree::Token(glued_tok), *spacing);
526
527                         // Remove the first token tree from `stream`. (This
528                         // is almost always the only tree in `stream`.)
529                         let stream_vec_mut = Lrc::make_mut(stream_lrc);
530                         stream_vec_mut.remove(0);
531
532                         // Don't push `stream` if it's empty -- that could
533                         // block subsequent token gluing, by getting
534                         // between two token trees that should be glued
535                         // together.
536                         if !stream.is_empty() {
537                             self.0.push(stream);
538                         }
539                         return;
540                     }
541                 }
542             }
543         }
544         self.0.push(stream);
545     }
546
547     pub fn build(self) -> TokenStream {
548         TokenStream::from_streams(self.0)
549     }
550 }
551
552 /// By-reference iterator over a [`TokenStream`].
553 #[derive(Clone)]
554 pub struct CursorRef<'t> {
555     stream: &'t TokenStream,
556     index: usize,
557 }
558
559 impl<'t> CursorRef<'t> {
560     fn next_with_spacing(&mut self) -> Option<&'t TreeAndSpacing> {
561         self.stream.0.get(self.index).map(|tree| {
562             self.index += 1;
563             tree
564         })
565     }
566 }
567
568 impl<'t> Iterator for CursorRef<'t> {
569     type Item = &'t TokenTree;
570
571     fn next(&mut self) -> Option<&'t TokenTree> {
572         self.next_with_spacing().map(|(tree, _)| tree)
573     }
574 }
575
576 /// Owning by-value iterator over a [`TokenStream`].
577 // FIXME: Many uses of this can be replaced with by-reference iterator to avoid clones.
578 #[derive(Clone)]
579 pub struct Cursor {
580     pub stream: TokenStream,
581     index: usize,
582 }
583
584 impl Iterator for Cursor {
585     type Item = TokenTree;
586
587     fn next(&mut self) -> Option<TokenTree> {
588         self.next_with_spacing().map(|(tree, _)| tree)
589     }
590 }
591
592 impl Cursor {
593     fn new(stream: TokenStream) -> Self {
594         Cursor { stream, index: 0 }
595     }
596
597     pub fn next_with_spacing(&mut self) -> Option<TreeAndSpacing> {
598         if self.index < self.stream.len() {
599             self.index += 1;
600             Some(self.stream.0[self.index - 1].clone())
601         } else {
602             None
603         }
604     }
605
606     pub fn index(&self) -> usize {
607         self.index
608     }
609
610     pub fn append(&mut self, new_stream: TokenStream) {
611         if new_stream.is_empty() {
612             return;
613         }
614         let index = self.index;
615         let stream = mem::take(&mut self.stream);
616         *self = TokenStream::from_streams(smallvec![stream, new_stream]).into_trees();
617         self.index = index;
618     }
619
620     pub fn look_ahead(&self, n: usize) -> Option<&TokenTree> {
621         self.stream.0[self.index..].get(n).map(|(tree, _)| tree)
622     }
623 }
624
625 #[derive(Debug, Copy, Clone, PartialEq, Encodable, Decodable, HashStable_Generic)]
626 pub struct DelimSpan {
627     pub open: Span,
628     pub close: Span,
629 }
630
631 impl DelimSpan {
632     pub fn from_single(sp: Span) -> Self {
633         DelimSpan { open: sp, close: sp }
634     }
635
636     pub fn from_pair(open: Span, close: Span) -> Self {
637         DelimSpan { open, close }
638     }
639
640     pub fn dummy() -> Self {
641         Self::from_single(DUMMY_SP)
642     }
643
644     pub fn entire(self) -> Span {
645         self.open.with_hi(self.close.hi())
646     }
647 }