diff options
Diffstat (limited to 'compiler/rustc_ast')
-rw-r--r-- | compiler/rustc_ast/src/ast.rs | 8 | ||||
-rw-r--r-- | compiler/rustc_ast/src/attr/mod.rs | 16 | ||||
-rw-r--r-- | compiler/rustc_ast/src/mut_visit.rs | 5 | ||||
-rw-r--r-- | compiler/rustc_ast/src/token.rs | 2 | ||||
-rw-r--r-- | compiler/rustc_ast/src/tokenstream.rs | 18 | ||||
-rw-r--r-- | compiler/rustc_ast/src/util/classify.rs | 2 | ||||
-rw-r--r-- | compiler/rustc_ast/src/visit.rs | 5 |
7 files changed, 40 insertions, 16 deletions
diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 58725a08c..e8cbd7b69 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -33,7 +33,7 @@ use rustc_macros::HashStable_Generic; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use rustc_span::source_map::{respan, Spanned}; use rustc_span::symbol::{kw, sym, Ident, Symbol}; -use rustc_span::{Span, DUMMY_SP}; +use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP}; use std::fmt; use std::mem; use thin_vec::{thin_vec, ThinVec}; @@ -1426,7 +1426,7 @@ pub enum ExprKind { /// of `if` / `while` expressions. (e.g., `if let 0 = x { .. }`). /// /// `Span` represents the whole `let pat = expr` statement. - Let(P<Pat>, P<Expr>, Span), + Let(P<Pat>, P<Expr>, Span, Option<ErrorGuaranteed>), /// An `if` block, with an optional `else` block. /// /// `if expr { block } else { expr }` @@ -2092,6 +2092,10 @@ pub enum TyKind { Never, /// A tuple (`(A, B, C, D,...)`). Tup(ThinVec<P<Ty>>), + /// An anonymous struct type i.e. `struct { foo: Type }` + AnonStruct(ThinVec<FieldDef>), + /// An anonymous union type i.e. `union { bar: Type }` + AnonUnion(ThinVec<FieldDef>), /// A path (`module::module::...::Type`), optionally /// "qualified", e.g., `<Vec<T> as SomeTrait>::SomeType`. /// diff --git a/compiler/rustc_ast/src/attr/mod.rs b/compiler/rustc_ast/src/attr/mod.rs index 19a2b3017..db008ea13 100644 --- a/compiler/rustc_ast/src/attr/mod.rs +++ b/compiler/rustc_ast/src/attr/mod.rs @@ -99,6 +99,22 @@ impl Attribute { } } + pub fn path_matches(&self, name: &[Symbol]) -> bool { + match &self.kind { + AttrKind::Normal(normal) => { + normal.item.path.segments.len() == name.len() + && normal + .item + .path + .segments + .iter() + .zip(name) + .all(|(s, n)| s.args.is_none() && s.ident.name == *n) + } + AttrKind::DocComment(..) => false, + } + } + pub fn is_word(&self) -> bool { if let AttrKind::Normal(normal) = &self.kind { matches!(normal.item.args, AttrArgs::Empty) diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index 48e9b180b..ba2887146 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -510,6 +510,9 @@ pub fn noop_visit_ty<T: MutVisitor>(ty: &mut P<Ty>, vis: &mut T) { visit_vec(bounds, |bound| vis.visit_param_bound(bound)); } TyKind::MacCall(mac) => vis.visit_mac_call(mac), + TyKind::AnonStruct(fields) | TyKind::AnonUnion(fields) => { + fields.flat_map_in_place(|field| vis.flat_map_field_def(field)); + } } vis.visit_span(span); visit_lazy_tts(tokens, vis); @@ -1363,7 +1366,7 @@ pub fn noop_visit_expr<T: MutVisitor>( vis.visit_ty(ty); } ExprKind::AddrOf(_, _, ohs) => vis.visit_expr(ohs), - ExprKind::Let(pat, scrutinee, _) => { + ExprKind::Let(pat, scrutinee, _, _) => { vis.visit_pat(pat); vis.visit_expr(scrutinee); } diff --git a/compiler/rustc_ast/src/token.rs b/compiler/rustc_ast/src/token.rs index f4ad0efa4..300b1486f 100644 --- a/compiler/rustc_ast/src/token.rs +++ b/compiler/rustc_ast/src/token.rs @@ -486,6 +486,8 @@ impl Token { Lt | BinOp(Shl) | // associated path ModSep => true, // global path Interpolated(ref nt) => matches!(**nt, NtTy(..) | NtPath(..)), + // For anonymous structs or unions, which only appear in specific positions + // (type of struct fields or union fields), we don't consider them as regular types _ => false, } } diff --git a/compiler/rustc_ast/src/tokenstream.rs b/compiler/rustc_ast/src/tokenstream.rs index e9591c7c8..1e18b1232 100644 --- a/compiler/rustc_ast/src/tokenstream.rs +++ b/compiler/rustc_ast/src/tokenstream.rs @@ -213,14 +213,10 @@ impl AttrTokenStream { .into_iter() } AttrTokenTree::Attributes(data) => { - let mut outer_attrs = Vec::new(); - let mut inner_attrs = Vec::new(); - for attr in &data.attrs { - match attr.style { - crate::AttrStyle::Outer => outer_attrs.push(attr), - crate::AttrStyle::Inner => inner_attrs.push(attr), - } - } + let idx = data + .attrs + .partition_point(|attr| matches!(attr.style, crate::AttrStyle::Outer)); + let (outer_attrs, inner_attrs) = data.attrs.split_at(idx); let mut target_tokens: Vec<_> = data .tokens @@ -265,10 +261,10 @@ impl AttrTokenStream { "Failed to find trailing delimited group in: {target_tokens:?}" ); } - let mut flat: SmallVec<[_; 1]> = SmallVec::new(); + let mut flat: SmallVec<[_; 1]> = + SmallVec::with_capacity(target_tokens.len() + outer_attrs.len()); for attr in outer_attrs { - // FIXME: Make this more efficient - flat.extend(attr.tokens().0.clone().iter().cloned()); + flat.extend(attr.tokens().0.iter().cloned()); } flat.extend(target_tokens); flat.into_iter() diff --git a/compiler/rustc_ast/src/util/classify.rs b/compiler/rustc_ast/src/util/classify.rs index 607b77705..f9f1c0cf9 100644 --- a/compiler/rustc_ast/src/util/classify.rs +++ b/compiler/rustc_ast/src/util/classify.rs @@ -36,7 +36,7 @@ pub fn expr_trailing_brace(mut expr: &ast::Expr) -> Option<&ast::Expr> { | AssignOp(_, _, e) | Binary(_, _, e) | Break(_, Some(e)) - | Let(_, e, _) + | Let(_, e, _, _) | Range(_, Some(e), _) | Ret(Some(e)) | Unary(_, e) diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index 6d474de2d..e66c4a9ee 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -438,6 +438,9 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) { TyKind::Infer | TyKind::ImplicitSelf | TyKind::Err => {} TyKind::MacCall(mac) => visitor.visit_mac_call(mac), TyKind::Never | TyKind::CVarArgs => {} + TyKind::AnonStruct(ref fields, ..) | TyKind::AnonUnion(ref fields, ..) => { + walk_list!(visitor, visit_field_def, fields) + } } } @@ -824,7 +827,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) { visitor.visit_expr(subexpression); visitor.visit_ty(typ) } - ExprKind::Let(pat, expr, _) => { + ExprKind::Let(pat, expr, _, _) => { visitor.visit_pat(pat); visitor.visit_expr(expr); } |