Skip to content

Commit 5785a84

Browse files
committed
Make proc_macro::Group take up less space remove redundant field.
The field `entire` is redundant. This saves 4 bytes and makes the DelimSpan match up with what the compiler uses.
1 parent b64df9d commit 5785a84

File tree

3 files changed

+5
-9
lines changed

3 files changed

+5
-9
lines changed

compiler/rustc_expand/src/proc_macro_server.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,7 @@ impl FromInternal<(TokenStream, &mut Rustc<'_, '_>)> for Vec<TokenTree<TokenStre
151151
trees.push(TokenTree::Group(Group {
152152
delimiter: rustc_proc_macro::Delimiter::from_internal(delim),
153153
stream: Some(stream),
154-
span: DelimSpan {
155-
open: span.open,
156-
close: span.close,
157-
entire: span.entire(),
158-
},
154+
span: DelimSpan { open: span.open, close: span.close },
159155
}));
160156
continue;
161157
}

library/proc_macro/src/bridge/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,16 +420,15 @@ compound_traits!(
420420
pub struct DelimSpan<Span> {
421421
pub open: Span,
422422
pub close: Span,
423-
pub entire: Span,
424423
}
425424

426425
impl<Span: Copy> DelimSpan<Span> {
427426
pub fn from_single(span: Span) -> Self {
428-
DelimSpan { open: span, close: span, entire: span }
427+
DelimSpan { open: span, close: span }
429428
}
430429
}
431430

432-
compound_traits!(struct DelimSpan<Span> { open, close, entire });
431+
compound_traits!(struct DelimSpan<Span> { open, close });
433432

434433
#[derive(Clone)]
435434
pub struct Group<TokenStream, Span> {

library/proc_macro/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,8 @@ impl Group {
847847
/// ```
848848
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
849849
pub fn span(&self) -> Span {
850-
Span(self.0.span.entire)
850+
let sp = self.0.span;
851+
Span(sp.open.join(sp.close).unwrap_or(sp.open))
851852
}
852853

853854
/// Returns the span pointing to the opening delimiter of this group.

0 commit comments

Comments
 (0)