mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 13:18:47 +00:00
Merge #5622
5622: Finalize WhereClause gramamr r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
3407d6f8a4
2 changed files with 103 additions and 102 deletions
|
@ -473,6 +473,7 @@ pub struct LifetimeParam {
|
||||||
pub(crate) syntax: SyntaxNode,
|
pub(crate) syntax: SyntaxNode,
|
||||||
}
|
}
|
||||||
impl ast::AttrsOwner for LifetimeParam {}
|
impl ast::AttrsOwner for LifetimeParam {}
|
||||||
|
impl ast::TypeBoundsOwner for LifetimeParam {}
|
||||||
impl LifetimeParam {
|
impl LifetimeParam {
|
||||||
pub fn lifetime_token(&self) -> Option<SyntaxToken> {
|
pub fn lifetime_token(&self) -> Option<SyntaxToken> {
|
||||||
support::token(&self.syntax, T![lifetime])
|
support::token(&self.syntax, T![lifetime])
|
||||||
|
@ -503,6 +504,19 @@ impl ConstParam {
|
||||||
pub fn default_val(&self) -> Option<Expr> { support::child(&self.syntax) }
|
pub fn default_val(&self) -> Option<Expr> { support::child(&self.syntax) }
|
||||||
}
|
}
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
pub struct WherePred {
|
||||||
|
pub(crate) syntax: SyntaxNode,
|
||||||
|
}
|
||||||
|
impl ast::TypeBoundsOwner for WherePred {}
|
||||||
|
impl WherePred {
|
||||||
|
pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) }
|
||||||
|
pub fn generic_param_list(&self) -> Option<GenericParamList> { support::child(&self.syntax) }
|
||||||
|
pub fn lifetime_token(&self) -> Option<SyntaxToken> {
|
||||||
|
support::token(&self.syntax, T![lifetime])
|
||||||
|
}
|
||||||
|
pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
|
||||||
|
}
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct Literal {
|
pub struct Literal {
|
||||||
pub(crate) syntax: SyntaxNode,
|
pub(crate) syntax: SyntaxNode,
|
||||||
}
|
}
|
||||||
|
@ -520,6 +534,29 @@ impl TokenTree {
|
||||||
pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
|
pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
|
||||||
}
|
}
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
pub struct LetStmt {
|
||||||
|
pub(crate) syntax: SyntaxNode,
|
||||||
|
}
|
||||||
|
impl ast::AttrsOwner for LetStmt {}
|
||||||
|
impl LetStmt {
|
||||||
|
pub fn let_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![let]) }
|
||||||
|
pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
|
||||||
|
pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
|
||||||
|
pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
|
||||||
|
pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
|
||||||
|
pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) }
|
||||||
|
pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
|
||||||
|
}
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
pub struct ExprStmt {
|
||||||
|
pub(crate) syntax: SyntaxNode,
|
||||||
|
}
|
||||||
|
impl ast::AttrsOwner for ExprStmt {}
|
||||||
|
impl ExprStmt {
|
||||||
|
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
|
||||||
|
pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
|
||||||
|
}
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct ParenType {
|
pub struct ParenType {
|
||||||
pub(crate) syntax: SyntaxNode,
|
pub(crate) syntax: SyntaxNode,
|
||||||
}
|
}
|
||||||
|
@ -1179,42 +1216,6 @@ impl MacroStmts {
|
||||||
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
|
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
|
||||||
}
|
}
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct WherePred {
|
|
||||||
pub(crate) syntax: SyntaxNode,
|
|
||||||
}
|
|
||||||
impl ast::TypeBoundsOwner for WherePred {}
|
|
||||||
impl WherePred {
|
|
||||||
pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) }
|
|
||||||
pub fn generic_param_list(&self) -> Option<GenericParamList> { support::child(&self.syntax) }
|
|
||||||
pub fn lifetime_token(&self) -> Option<SyntaxToken> {
|
|
||||||
support::token(&self.syntax, T![lifetime])
|
|
||||||
}
|
|
||||||
pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
|
|
||||||
}
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
||||||
pub struct ExprStmt {
|
|
||||||
pub(crate) syntax: SyntaxNode,
|
|
||||||
}
|
|
||||||
impl ast::AttrsOwner for ExprStmt {}
|
|
||||||
impl ExprStmt {
|
|
||||||
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
|
|
||||||
pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
|
|
||||||
}
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
||||||
pub struct LetStmt {
|
|
||||||
pub(crate) syntax: SyntaxNode,
|
|
||||||
}
|
|
||||||
impl ast::AttrsOwner for LetStmt {}
|
|
||||||
impl LetStmt {
|
|
||||||
pub fn let_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![let]) }
|
|
||||||
pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
|
|
||||||
pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
|
|
||||||
pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
|
|
||||||
pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
|
|
||||||
pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) }
|
|
||||||
pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
|
|
||||||
}
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
||||||
pub struct PathSegment {
|
pub struct PathSegment {
|
||||||
pub(crate) syntax: SyntaxNode,
|
pub(crate) syntax: SyntaxNode,
|
||||||
}
|
}
|
||||||
|
@ -1880,6 +1881,17 @@ impl AstNode for ConstParam {
|
||||||
}
|
}
|
||||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||||
}
|
}
|
||||||
|
impl AstNode for WherePred {
|
||||||
|
fn can_cast(kind: SyntaxKind) -> bool { kind == WHERE_PRED }
|
||||||
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||||
|
if Self::can_cast(syntax.kind()) {
|
||||||
|
Some(Self { syntax })
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||||
|
}
|
||||||
impl AstNode for Literal {
|
impl AstNode for Literal {
|
||||||
fn can_cast(kind: SyntaxKind) -> bool { kind == LITERAL }
|
fn can_cast(kind: SyntaxKind) -> bool { kind == LITERAL }
|
||||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||||
|
@ -1902,6 +1914,28 @@ impl AstNode for TokenTree {
|
||||||
}
|
}
|
||||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||||
}
|
}
|
||||||
|
impl AstNode for LetStmt {
|
||||||
|
fn can_cast(kind: SyntaxKind) -> bool { kind == LET_STMT }
|
||||||
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||||
|
if Self::can_cast(syntax.kind()) {
|
||||||
|
Some(Self { syntax })
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||||
|
}
|
||||||
|
impl AstNode for ExprStmt {
|
||||||
|
fn can_cast(kind: SyntaxKind) -> bool { kind == EXPR_STMT }
|
||||||
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||||
|
if Self::can_cast(syntax.kind()) {
|
||||||
|
Some(Self { syntax })
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||||
|
}
|
||||||
impl AstNode for ParenType {
|
impl AstNode for ParenType {
|
||||||
fn can_cast(kind: SyntaxKind) -> bool { kind == PAREN_TYPE }
|
fn can_cast(kind: SyntaxKind) -> bool { kind == PAREN_TYPE }
|
||||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||||
|
@ -2672,39 +2706,6 @@ impl AstNode for MacroStmts {
|
||||||
}
|
}
|
||||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||||
}
|
}
|
||||||
impl AstNode for WherePred {
|
|
||||||
fn can_cast(kind: SyntaxKind) -> bool { kind == WHERE_PRED }
|
|
||||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
||||||
if Self::can_cast(syntax.kind()) {
|
|
||||||
Some(Self { syntax })
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
|
||||||
}
|
|
||||||
impl AstNode for ExprStmt {
|
|
||||||
fn can_cast(kind: SyntaxKind) -> bool { kind == EXPR_STMT }
|
|
||||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
||||||
if Self::can_cast(syntax.kind()) {
|
|
||||||
Some(Self { syntax })
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
|
||||||
}
|
|
||||||
impl AstNode for LetStmt {
|
|
||||||
fn can_cast(kind: SyntaxKind) -> bool { kind == LET_STMT }
|
|
||||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
||||||
if Self::can_cast(syntax.kind()) {
|
|
||||||
Some(Self { syntax })
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
|
||||||
}
|
|
||||||
impl AstNode for PathSegment {
|
impl AstNode for PathSegment {
|
||||||
fn can_cast(kind: SyntaxKind) -> bool { kind == PATH_SEGMENT }
|
fn can_cast(kind: SyntaxKind) -> bool { kind == PATH_SEGMENT }
|
||||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||||
|
@ -3671,6 +3672,11 @@ impl std::fmt::Display for ConstParam {
|
||||||
std::fmt::Display::fmt(self.syntax(), f)
|
std::fmt::Display::fmt(self.syntax(), f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl std::fmt::Display for WherePred {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
std::fmt::Display::fmt(self.syntax(), f)
|
||||||
|
}
|
||||||
|
}
|
||||||
impl std::fmt::Display for Literal {
|
impl std::fmt::Display for Literal {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
std::fmt::Display::fmt(self.syntax(), f)
|
std::fmt::Display::fmt(self.syntax(), f)
|
||||||
|
@ -3681,6 +3687,16 @@ impl std::fmt::Display for TokenTree {
|
||||||
std::fmt::Display::fmt(self.syntax(), f)
|
std::fmt::Display::fmt(self.syntax(), f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl std::fmt::Display for LetStmt {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
std::fmt::Display::fmt(self.syntax(), f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl std::fmt::Display for ExprStmt {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
std::fmt::Display::fmt(self.syntax(), f)
|
||||||
|
}
|
||||||
|
}
|
||||||
impl std::fmt::Display for ParenType {
|
impl std::fmt::Display for ParenType {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
std::fmt::Display::fmt(self.syntax(), f)
|
std::fmt::Display::fmt(self.syntax(), f)
|
||||||
|
@ -4031,21 +4047,6 @@ impl std::fmt::Display for MacroStmts {
|
||||||
std::fmt::Display::fmt(self.syntax(), f)
|
std::fmt::Display::fmt(self.syntax(), f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl std::fmt::Display for WherePred {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
std::fmt::Display::fmt(self.syntax(), f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl std::fmt::Display for ExprStmt {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
std::fmt::Display::fmt(self.syntax(), f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl std::fmt::Display for LetStmt {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
std::fmt::Display::fmt(self.syntax(), f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl std::fmt::Display for PathSegment {
|
impl std::fmt::Display for PathSegment {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
std::fmt::Display::fmt(self.syntax(), f)
|
std::fmt::Display::fmt(self.syntax(), f)
|
||||||
|
|
|
@ -175,7 +175,13 @@ ConstParam =
|
||||||
('=' default_val:Expr)?
|
('=' default_val:Expr)?
|
||||||
|
|
||||||
LifetimeParam =
|
LifetimeParam =
|
||||||
Attr* 'lifetime'
|
Attr* 'lifetime' (':' TypeBoundList?)?
|
||||||
|
|
||||||
|
WhereClause =
|
||||||
|
'where' predicates:(WherePred (',' WherePred)* ','?)
|
||||||
|
|
||||||
|
WherePred =
|
||||||
|
('for' GenericParamList)? ('lifetime' | Type) ':' TypeBoundList
|
||||||
|
|
||||||
Visibility =
|
Visibility =
|
||||||
'pub' ('('
|
'pub' ('('
|
||||||
|
@ -188,6 +194,17 @@ Visibility =
|
||||||
Attr =
|
Attr =
|
||||||
'#' '!'? '[' Path ('=' Literal | TokenTree)? ']'
|
'#' '!'? '[' Path ('=' Literal | TokenTree)? ']'
|
||||||
|
|
||||||
|
Stmt =
|
||||||
|
LetStmt
|
||||||
|
| ExprStmt
|
||||||
|
|
||||||
|
LetStmt =
|
||||||
|
Attr* 'let' Pat (':' Type)?
|
||||||
|
'=' initializer:Expr ';'
|
||||||
|
|
||||||
|
ExprStmt =
|
||||||
|
Attr* Expr ';'?
|
||||||
|
|
||||||
Type =
|
Type =
|
||||||
ParenType
|
ParenType
|
||||||
| TupleType
|
| TupleType
|
||||||
|
@ -450,19 +467,6 @@ MacroStmts =
|
||||||
statements:Stmt*
|
statements:Stmt*
|
||||||
Expr?
|
Expr?
|
||||||
|
|
||||||
WherePred =
|
|
||||||
('for' GenericParamList)? ('lifetime' | Type) ':' TypeBoundList
|
|
||||||
|
|
||||||
WhereClause =
|
|
||||||
'where' predicates:WherePred*
|
|
||||||
|
|
||||||
ExprStmt =
|
|
||||||
Attr* Expr ';'
|
|
||||||
|
|
||||||
LetStmt =
|
|
||||||
Attr* 'let' Pat (':' Type)
|
|
||||||
'=' initializer:Expr ';'
|
|
||||||
|
|
||||||
Path =
|
Path =
|
||||||
(qualifier:Path '::')? segment:PathSegment
|
(qualifier:Path '::')? segment:PathSegment
|
||||||
|
|
||||||
|
@ -490,10 +494,6 @@ LifetimeArg =
|
||||||
ConstArg =
|
ConstArg =
|
||||||
Literal | BlockExpr BlockExpr
|
Literal | BlockExpr BlockExpr
|
||||||
|
|
||||||
Stmt =
|
|
||||||
LetStmt
|
|
||||||
| ExprStmt
|
|
||||||
|
|
||||||
Pat =
|
Pat =
|
||||||
OrPat
|
OrPat
|
||||||
| ParenPat
|
| ParenPat
|
||||||
|
|
Loading…
Reference in a new issue