diff options
| author | bors <bors@rust-lang.org> | 2021-01-15 05:36:48 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-01-15 05:36:48 +0000 |
| commit | dcf622eb70aebe16d40c5f88fa2a41fa7019541c (patch) | |
| tree | 0dc48e3ed0ac3cb88d7b86224b2248ae40b9add4 /compiler/rustc_parse/src/parser/attr.rs | |
| parent | 3419da89aaaa678f680032fef9764e875aa06026 (diff) | |
| parent | a961e6785c7ed33a532bb6172ae0c95f44db5726 (diff) | |
| download | rust-dcf622eb70aebe16d40c5f88fa2a41fa7019541c.tar.gz rust-dcf622eb70aebe16d40c5f88fa2a41fa7019541c.zip | |
Auto merge of #80993 - Aaron1011:collect-set-tokens, r=petrochenkov
Set tokens on AST node in `collect_tokens` A new `HasTokens` trait is introduced, which is used to move logic from the callers of `collect_tokens` into the body of `collect_tokens`. In addition to reducing duplication, this paves the way for PR #80689, which needs to perform additional logic during token collection.
Diffstat (limited to 'compiler/rustc_parse/src/parser/attr.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/attr.rs | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/compiler/rustc_parse/src/parser/attr.rs b/compiler/rustc_parse/src/parser/attr.rs index fae09fa6fec..1b26fb33370 100644 --- a/compiler/rustc_parse/src/parser/attr.rs +++ b/compiler/rustc_parse/src/parser/attr.rs @@ -89,7 +89,7 @@ impl<'a> Parser<'a> { inner_parse_policy, self.token ); let lo = self.token.span; - let ((item, style, span), tokens) = self.collect_tokens(|this| { + self.collect_tokens(|this| { if this.eat(&token::Pound) { let style = if this.eat(&token::Not) { ast::AttrStyle::Inner @@ -107,15 +107,13 @@ impl<'a> Parser<'a> { this.error_on_forbidden_inner_attr(attr_sp, inner_parse_policy); } - Ok((item, style, attr_sp)) + Ok(attr::mk_attr_from_item(item, None, style, attr_sp)) } else { let token_str = pprust::token_to_string(&this.token); let msg = &format!("expected `#`, found `{}`", token_str); Err(this.struct_span_err(this.token.span, msg)) } - })?; - - Ok(attr::mk_attr_from_item(item, tokens, style, span)) + }) } pub(super) fn error_on_forbidden_inner_attr(&self, attr_sp: Span, policy: InnerAttrPolicy<'_>) { @@ -165,13 +163,7 @@ impl<'a> Parser<'a> { let args = this.parse_attr_args()?; Ok(ast::AttrItem { path, args, tokens: None }) }; - if capture_tokens { - let (mut item, tokens) = self.collect_tokens(do_parse)?; - item.tokens = tokens; - item - } else { - do_parse(self)? - } + if capture_tokens { self.collect_tokens(do_parse) } else { do_parse(self) }? }) } |
