Skip to content

Commit 6d28ed1

Browse files
authored
Rollup merge of rust-lang#65261 - nnethercote:rm-Option-from-TokenStream, r=petrochenkov
Remove `Option` from `TokenStream` A code simplification. r? @petrochenkov
2 parents a9a4d40 + 18b48bf commit 6d28ed1

File tree

10 files changed

+110
-154
lines changed

10 files changed

+110
-154
lines changed

src/libsyntax/attr/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ impl MetaItem {
551551
impl MetaItemKind {
552552
pub fn tokens(&self, span: Span) -> TokenStream {
553553
match *self {
554-
MetaItemKind::Word => TokenStream::empty(),
554+
MetaItemKind::Word => TokenStream::default(),
555555
MetaItemKind::NameValue(ref lit) => {
556556
let mut vec = vec![TokenTree::token(token::Eq, span).into()];
557557
lit.tokens().append_to_tree_and_joint_vec(&mut vec);

src/libsyntax/ext/expand.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -676,12 +676,12 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
676676
}
677677
}
678678
Some(TokenTree::Token(..)) => {}
679-
None => return TokenStream::empty(),
679+
None => return TokenStream::default(),
680680
}
681681
self.cx.span_err(span, "custom attribute invocations must be \
682682
of the form `#[foo]` or `#[foo(..)]`, the macro name must only be \
683683
followed by a delimiter token");
684-
TokenStream::empty()
684+
TokenStream::default()
685685
}
686686

687687
fn gate_proc_macro_attr_item(&self, span: Span, item: &Annotatable) {

src/libsyntax/ext/mbe/transcribe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub(super) fn transcribe(
9595
) -> TokenStream {
9696
// Nothing for us to transcribe...
9797
if src.is_empty() {
98-
return TokenStream::empty();
98+
return TokenStream::default();
9999
}
100100

101101
// We descend into the RHS (`src`), expanding things as we go. This stack contains the things

src/libsyntax/ext/placeholders.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub fn placeholder(kind: AstFragmentKind, id: ast::NodeId) -> AstFragment {
1515
fn mac_placeholder() -> ast::Mac {
1616
ast::Mac {
1717
path: ast::Path { span: DUMMY_SP, segments: Vec::new() },
18-
tts: TokenStream::empty().into(),
18+
tts: TokenStream::default().into(),
1919
delim: ast::MacDelimiter::Brace,
2020
span: DUMMY_SP,
2121
prior_type_ascription: None,
@@ -32,12 +32,12 @@ pub fn placeholder(kind: AstFragmentKind, id: ast::NodeId) -> AstFragment {
3232
attrs: ThinVec::new(),
3333
kind: ast::ExprKind::Mac(mac_placeholder()),
3434
});
35-
let ty = P(ast::Ty {
35+
let ty = || P(ast::Ty {
3636
id,
3737
kind: ast::TyKind::Mac(mac_placeholder()),
3838
span,
3939
});
40-
let pat = P(ast::Pat {
40+
let pat = || P(ast::Pat {
4141
id,
4242
kind: ast::PatKind::Mac(mac_placeholder()),
4343
span,
@@ -83,7 +83,7 @@ pub fn placeholder(kind: AstFragmentKind, id: ast::NodeId) -> AstFragment {
8383
body: expr_placeholder(),
8484
guard: None,
8585
id,
86-
pat,
86+
pat: pat(),
8787
span,
8888
is_placeholder: true,
8989
}
@@ -105,7 +105,7 @@ pub fn placeholder(kind: AstFragmentKind, id: ast::NodeId) -> AstFragment {
105105
id,
106106
ident,
107107
is_shorthand: false,
108-
pat,
108+
pat: pat(),
109109
span,
110110
is_placeholder: true,
111111
}
@@ -124,9 +124,9 @@ pub fn placeholder(kind: AstFragmentKind, id: ast::NodeId) -> AstFragment {
124124
ast::Param {
125125
attrs: Default::default(),
126126
id,
127-
pat,
127+
pat: pat(),
128128
span,
129-
ty,
129+
ty: ty(),
130130
is_placeholder: true,
131131
}
132132
]),
@@ -136,7 +136,7 @@ pub fn placeholder(kind: AstFragmentKind, id: ast::NodeId) -> AstFragment {
136136
id,
137137
ident: None,
138138
span,
139-
ty,
139+
ty: ty(),
140140
vis,
141141
is_placeholder: true,
142142
}

src/libsyntax/ext/proc_macro_server.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ impl server::Types for Rustc<'_> {
394394

395395
impl server::TokenStream for Rustc<'_> {
396396
fn new(&mut self) -> Self::TokenStream {
397-
TokenStream::empty()
397+
TokenStream::default()
398398
}
399399
fn is_empty(&mut self, stream: &Self::TokenStream) -> bool {
400400
stream.is_empty()

src/libsyntax/mut_visit.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -610,10 +610,8 @@ pub fn noop_visit_tt<T: MutVisitor>(tt: &mut TokenTree, vis: &mut T) {
610610
}
611611

612612
pub fn noop_visit_tts<T: MutVisitor>(TokenStream(tts): &mut TokenStream, vis: &mut T) {
613-
visit_opt(tts, |tts| {
614-
let tts = Lrc::make_mut(tts);
615-
visit_vec(tts, |(tree, _is_joint)| vis.visit_tt(tree));
616-
})
613+
let tts = Lrc::make_mut(tts);
614+
visit_vec(tts, |(tree, _is_joint)| vis.visit_tt(tree));
617615
}
618616

619617
// Applies ident visitor if it's an ident; applies other visits to interpolated nodes.

src/libsyntax/parse/attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl<'a> Parser<'a> {
203203
};
204204
TokenStream::from_streams(smallvec![eq.into(), tokens])
205205
} else {
206-
TokenStream::empty()
206+
TokenStream::default()
207207
};
208208
ast::AttrItem { path, tokens }
209209
})

src/libsyntax/parse/parser.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ impl<'a> Parser<'a> {
12731273
// This can happen due to a bad interaction of two unrelated recovery mechanisms with
12741274
// mismatched delimiters *and* recovery lookahead on the likely typo `pub ident(`
12751275
// (#62881).
1276-
return Ok((ret?, TokenStream::new(vec![])));
1276+
return Ok((ret?, TokenStream::default()));
12771277
} else {
12781278
&mut self.token_cursor.stack[prev].last_token
12791279
};
@@ -1288,7 +1288,7 @@ impl<'a> Parser<'a> {
12881288
// This can happen due to a bad interaction of two unrelated recovery mechanisms
12891289
// with mismatched delimiters *and* recovery lookahead on the likely typo
12901290
// `pub ident(` (#62895, different but similar to the case above).
1291-
return Ok((ret?, TokenStream::new(vec![])));
1291+
return Ok((ret?, TokenStream::default()));
12921292
}
12931293
};
12941294

0 commit comments

Comments
 (0)