From 08ea2271e8050165d0aaf4c994ed3dd746aff3ba Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 12:06:38 +0200 Subject: Rename TypeRef -> Type The TypeRef name comes from IntelliJ days, where you often have both type *syntax* as well as *semantical* representation of types in scope. And naming both Type is confusing. In rust-analyzer however, we use ast types as `ast::Type`, and have many more semantic counterparts to ast types, so avoiding name clash here is just confusing. --- xtask/src/codegen/gen_syntax.rs | 8 +++++- xtask/src/codegen/rust.ungram | 54 ++++++++++++++++++++--------------------- 2 files changed, 34 insertions(+), 28 deletions(-) (limited to 'xtask') diff --git a/xtask/src/codegen/gen_syntax.rs b/xtask/src/codegen/gen_syntax.rs index 45b788bdb..d6a72ccc0 100644 --- a/xtask/src/codegen/gen_syntax.rs +++ b/xtask/src/codegen/gen_syntax.rs @@ -476,7 +476,13 @@ impl Field { }; format_ident!("{}_token", name) } - Field::Node { name, .. } => format_ident!("{}", name), + Field::Node { name, .. } => { + if name == "type" { + format_ident!("ty") + } else { + format_ident!("{}", name) + } + } } } fn ty(&self) -> proc_macro2::Ident { diff --git a/xtask/src/codegen/rust.ungram b/xtask/src/codegen/rust.ungram index 1c1dec80a..8f0e66278 100644 --- a/xtask/src/codegen/rust.ungram +++ b/xtask/src/codegen/rust.ungram @@ -61,22 +61,22 @@ ParamList = SelfParam = Attr* ( ('&' 'lifetime'?)? 'mut'? 'self' - | 'mut'? 'self' ':' ty:TypeRef + | 'mut'? 'self' ':' Type ) Param = Attr* ( - Pat (':' ty:TypeRef) - | ty:TypeRef + Pat (':' Type) + | Type | '...' ) RetType = - '->' ty:TypeRef + '->' Type TypeAlias = Attr* Visibility? 'default'? 'type' Name GenericParamList? (':' TypeBoundList?)? WhereClause? - '=' ty:TypeRef ';' + '=' Type ';' Struct = Attr* Visibility? 'struct' Name GenericParamList? ( @@ -88,13 +88,13 @@ RecordFieldList = '{' fields:(RecordField (',' RecordField)* ','?)? '}' RecordField = - Attr* Visibility? Name ':' ty:TypeRef + Attr* Visibility? Name ':' Type TupleFieldList = '(' fields:(TupleField (',' TupleField)* ','?)? ')' TupleField = - Attr* Visibility? ty:TypeRef + Attr* Visibility? Type FieldList = RecordFieldList @@ -120,11 +120,11 @@ AdtDef = | Union Const = - Attr* Visibility? 'default'? 'const' (Name | '_') ':' ty:TypeRef + Attr* Visibility? 'default'? 'const' (Name | '_') ':' Type '=' body:Expr ';' Static = - Attr* Visibility? 'static'? 'mut'? Name ':' ty:TypeRef + Attr* Visibility? 'static'? 'mut'? Name ':' Type '=' body:Expr ';' Trait = @@ -144,8 +144,8 @@ AssocItem = Impl = Attr* Visibility? 'default'? 'unsafe'? 'impl' 'const'? GenericParamList? ( - TypeRef - | '!'? TypeRef 'for' TypeRef + Type + | '!'? Type 'for' Type ) WhereClause? AssocItemList @@ -168,10 +168,10 @@ GenericParam = TypeParam = Attr* Name (':' TypeBoundList?)? - ('=' default_type:TypeRef)? + ('=' default_type:Type)? ConstParam = - Attr* 'const' Name ':' ty:TypeRef + Attr* 'const' Name ':' Type ('=' default_val:Expr)? LifetimeParam = @@ -188,7 +188,7 @@ Visibility = Attr = '#' '!'? '[' Path ('=' Literal | TokenTree)? ']' -TypeRef = +Type = ParenType | TupleType | NeverType @@ -204,10 +204,10 @@ TypeRef = | DynTraitType ParenType = - '(' ty:TypeRef ')' + '(' Type ')' TupleType = - '(' fields:TypeRef* ')' + '(' fields:Type* ')' NeverType = '!' @@ -216,16 +216,16 @@ PathType = Path PointerType = - '*' ('const' | 'mut') ty:TypeRef + '*' ('const' | 'mut') Type ArrayType = - '[' ty:TypeRef ';' Expr ']' + '[' Type ';' Expr ']' SliceType = - '[' ty:TypeRef ']' + '[' Type ']' ReferenceType = - '&' 'lifetime'? 'mut'? ty:TypeRef + '&' 'lifetime'? 'mut'? Type PlaceholderType = '_' @@ -234,7 +234,7 @@ FnPointerType = Abi 'unsafe'? 'fn' ParamList RetType? ForType = - 'for' GenericParamList ty:TypeRef + 'for' GenericParamList Type ImplTraitType = 'impl' TypeBoundList @@ -322,7 +322,7 @@ TryExpr = Attr* Expr '?' CastExpr = - Attr* Expr 'as' ty:TypeRef + Attr* Expr 'as' Type RefExpr = Attr* '&' ('raw' | 'mut' | 'const') Expr @@ -444,13 +444,13 @@ MacroStmts = Expr? TypeBound = - 'lifetime' | 'const'? TypeRef + 'lifetime' | 'const'? Type TypeBoundList = bounds:TypeBound* WherePred = - ('for' GenericParamList)? ('lifetime' | TypeRef) ':' TypeBoundList + ('for' GenericParamList)? ('lifetime' | Type) ':' TypeBoundList WhereClause = 'where' predicates:WherePred* @@ -459,7 +459,7 @@ ExprStmt = Attr* Expr ';' LetStmt = - Attr* 'let' Pat (':' ty:TypeRef) + Attr* 'let' Pat (':' Type) '=' initializer:Expr ';' Path = @@ -478,10 +478,10 @@ TypeArgList = '>' TypeArg = - TypeRef + Type AssocTypeArg = - NameRef (':' TypeBoundList | '=' TypeRef) + NameRef (':' TypeBoundList | '=' Type) LifetimeArg = 'lifetime' -- cgit v1.2.3