Skip to content

Commit 065f804

Browse files
committed
Get it compiling
1 parent d76dba2 commit 065f804

File tree

6 files changed

+26
-30
lines changed

6 files changed

+26
-30
lines changed

compiler/rustc_ast/src/ast_like.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use super::ptr::P;
2-
use super::tokenstream::{LazyTokenStream, Spacing, AttributesData, PreexpTokenTree, PreexpTokenStream};
2+
use super::tokenstream::{
3+
AttributesData, LazyTokenStream, PreexpTokenStream, PreexpTokenTree, Spacing,
4+
};
35
use super::{Arm, Field, FieldPat, GenericParam, Param, StructField, Variant};
46
use super::{AssocItem, Expr, ForeignItem, Item, Local, MacCallStmt};
57
use super::{AttrItem, AttrKind, Block, Pat, Path, Ty, Visibility};
@@ -143,7 +145,6 @@ impl AstLike for Attribute {
143145
panic!("Called visit_tokens on doc comment attr {:?}", self)
144146
}
145147
}
146-
147148
}
148149
}
149150

@@ -177,7 +178,6 @@ pub fn has_cfg_or_cfg_any(attrs: &[Attribute]) -> bool {
177178
})
178179
}
179180

180-
181181
/// Helper trait for the macros below. Abstracts over
182182
/// the two types of attribute fields that AST nodes
183183
/// may have (`Vec<Attribute>` or `AttrVec`)

compiler/rustc_expand/src/base.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::module::DirectoryOwnership;
33

44
use rustc_ast::ptr::P;
55
use rustc_ast::token::{self, Nonterminal};
6-
use rustc_ast::tokenstream::{CanSynthesizeMissingTokens, LazyTokenStream, TokenStream};
6+
use rustc_ast::tokenstream::{AttributesData, CanSynthesizeMissingTokens, LazyTokenStream, TokenStream};
77
use rustc_ast::visit::{AssocCtxt, Visitor};
88
use rustc_ast::{self as ast, AstLike, Attribute, NodeId, PatKind};
99
use rustc_attr::{self as attr, Deprecation, Stability};
@@ -45,6 +45,7 @@ pub enum Annotatable {
4545
}
4646

4747
impl AstLike for Annotatable {
48+
const SUPPORTS_INNER_ATTRS: bool = true;
4849
fn attrs(&self) -> &[Attribute] {
4950
match *self {
5051
Annotatable::Item(ref item) => &item.attrs,
@@ -81,7 +82,7 @@ impl AstLike for Annotatable {
8182
}
8283
}
8384

84-
fn finalize_tokens(&mut self, tokens: LazyTokenStream) {
85+
fn finalize_tokens(&mut self, tokens: LazyTokenStream) -> Option<AttributesData> {
8586
panic!("Called finalize_tokens on an Annotatable: {:?}", tokens);
8687
}
8788

compiler/rustc_expand/src/config.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ use crate::base::Annotatable;
55
use rustc_ast::mut_visit::*;
66
use rustc_ast::ptr::P;
77
use rustc_ast::token::{DelimToken, Token, TokenKind};
8-
use rustc_ast::tokenstream::{DelimSpan, LazyTokenStream, Spacing, TokenStream, TokenTree};
9-
use rustc_ast::{self as ast, AstLike, AttrItem, Attribute, MetaItem};
8+
use rustc_ast::tokenstream::{
9+
DelimSpan, LazyTokenStream, PreexpTokenStream, PreexpTokenTree, Spacing, TokenStream, TokenTree,
10+
};
11+
use rustc_ast::{self as ast, AstLike, AttrItem, Attribute, AttrStyle, MetaItem};
1012
use rustc_attr as attr;
1113
use rustc_data_structures::fx::FxHashMap;
1214
use rustc_data_structures::map_in_place::MapInPlace;
@@ -268,12 +270,7 @@ impl<'a> StripUnconfigured<'a> {
268270
mut attrs: Vec<ast::Attribute>,
269271
) -> Option<Vec<ast::Attribute>> {
270272
attrs.flat_map_in_place(|attr| self.process_cfg_attr(attr));
271-
if self.in_cfg(&attrs) {
272-
Some(attrs)
273-
} else {
274-
self.modified = true;
275-
None
276-
}
273+
if self.in_cfg(&attrs) { Some(attrs) } else { None }
277274
}
278275

279276
fn configure_tokens(&mut self, stream: &PreexpTokenStream) -> PreexpTokenStream {

compiler/rustc_lint/src/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ impl EarlyLintPass for UnusedDocComment {
10481048
| ast::StmtKind::MacCall(_) => return,
10491049
};
10501050

1051-
warn_if_doc(cx, stmt.span, kind, HasAttrs::attrs(&stmt.kind));
1051+
warn_if_doc(cx, stmt.span, kind, stmt.kind.attrs());
10521052
}
10531053

10541054
fn check_arm(&mut self, cx: &EarlyContext<'_>, arm: &ast::Arm) {

compiler/rustc_parse/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010
use rustc_ast as ast;
1111
use rustc_ast::token::{self, Nonterminal, Token, TokenKind};
12-
use rustc_ast::AstLike;
1312
use rustc_ast::tokenstream::{
1413
self, AttributesData, CanSynthesizeMissingTokens, LazyTokenStream, PreexpTokenStream,
1514
PreexpTokenTree, Spacing, TokenStream,
1615
};
16+
use rustc_ast::AstLike;
1717
use rustc_ast::Attribute;
1818
use rustc_ast_pretty::pprust;
1919
use rustc_data_structures::sync::Lrc;

compiler/rustc_parse/src/parser/attr_wrapper.rs

+13-15
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ impl<'a> Parser<'a> {
230230
&& !attrs.maybe_needs_tokens()
231231
&& !R::SUPPORTS_INNER_ATTRS
232232
&& !(matches!(self.capture_state.capturing, Capturing::Yes { tokens_for_attrs: true })
233-
&& ast::attr::has_cfg_or_cfg_any(&attrs.attrs))
233+
&& ast::ast_like::has_cfg_or_cfg_any(&attrs.attrs))
234234
{
235235
return Ok(f(self, attrs.attrs.into())?.0);
236236
}
@@ -268,7 +268,7 @@ impl<'a> Parser<'a> {
268268
// but we only bail out if there's no possibility of inner attributes
269269
// (!R::SUPPORTS_INNER_ATTRS)
270270
&& !(matches!(self.capture_state.capturing, Capturing:: Yes { tokens_for_attrs: true })
271-
&& ast::attr::has_cfg_or_cfg_any(ret.attrs()))
271+
&& ast::ast_like::has_cfg_or_cfg_any(ret.attrs()))
272272
{
273273
return Ok(ret);
274274
}
@@ -298,19 +298,17 @@ impl<'a> Parser<'a> {
298298

299299
let num_calls = end_pos - cursor_snapshot_next_calls;
300300

301-
let make_lazy = || {
302-
LazyTokenStream::new(LazyTokenStreamImpl {
303-
start_token,
304-
num_calls: num_calls.try_into().unwrap(),
305-
cursor_snapshot,
306-
desugar_doc_comments: self.desugar_doc_comments,
307-
append_unglued_token: self.token_cursor.append_unglued_token.clone(),
308-
replace_ranges: replace_ranges.into(),
309-
start_calls: cursor_snapshot_next_calls.try_into().unwrap(),
310-
})
311-
};
312-
313-
let final_attrs: Option<AttributesData> = ret.finalize_tokens(make_lazy);
301+
let tokens = LazyTokenStream::new(LazyTokenStreamImpl {
302+
start_token,
303+
num_calls: num_calls.try_into().unwrap(),
304+
cursor_snapshot,
305+
desugar_doc_comments: self.desugar_doc_comments,
306+
append_unglued_token: self.token_cursor.append_unglued_token.clone(),
307+
replace_ranges: replace_ranges.into(),
308+
start_calls: cursor_snapshot_next_calls.try_into().unwrap(),
309+
});
310+
311+
let final_attrs: Option<AttributesData> = ret.finalize_tokens(tokens);
314312
if let Some(final_attrs) = final_attrs {
315313
if matches!(self.capture_state.capturing, Capturing::Yes { tokens_for_attrs: true }) {
316314
let start_pos =

0 commit comments

Comments
 (0)