mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Finalize TypeBound grammar
This commit is contained in:
parent
a6527ed92c
commit
b250ae6c55
4 changed files with 35 additions and 54 deletions
|
@ -270,7 +270,7 @@ impl GenericParams {
|
||||||
bound: ast::TypeBound,
|
bound: ast::TypeBound,
|
||||||
type_ref: TypeRef,
|
type_ref: TypeRef,
|
||||||
) {
|
) {
|
||||||
if bound.question_token().is_some() {
|
if bound.question_mark_token().is_some() {
|
||||||
// FIXME: remove this bound
|
// FIXME: remove this bound
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -639,6 +639,17 @@ impl DynTraitType {
|
||||||
pub fn type_bound_list(&self) -> Option<TypeBoundList> { support::child(&self.syntax) }
|
pub fn type_bound_list(&self) -> Option<TypeBoundList> { support::child(&self.syntax) }
|
||||||
}
|
}
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
pub struct TypeBound {
|
||||||
|
pub(crate) syntax: SyntaxNode,
|
||||||
|
}
|
||||||
|
impl TypeBound {
|
||||||
|
pub fn lifetime_token(&self) -> Option<SyntaxToken> {
|
||||||
|
support::token(&self.syntax, T![lifetime])
|
||||||
|
}
|
||||||
|
pub fn question_mark_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![?]) }
|
||||||
|
pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
|
||||||
|
}
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct TupleExpr {
|
pub struct TupleExpr {
|
||||||
pub(crate) syntax: SyntaxNode,
|
pub(crate) syntax: SyntaxNode,
|
||||||
}
|
}
|
||||||
|
@ -1168,17 +1179,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 TypeBound {
|
|
||||||
pub(crate) syntax: SyntaxNode,
|
|
||||||
}
|
|
||||||
impl TypeBound {
|
|
||||||
pub fn lifetime_token(&self) -> Option<SyntaxToken> {
|
|
||||||
support::token(&self.syntax, T![lifetime])
|
|
||||||
}
|
|
||||||
pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
|
|
||||||
pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
|
|
||||||
}
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
||||||
pub struct WherePred {
|
pub struct WherePred {
|
||||||
pub(crate) syntax: SyntaxNode,
|
pub(crate) syntax: SyntaxNode,
|
||||||
}
|
}
|
||||||
|
@ -2045,6 +2045,17 @@ impl AstNode for DynTraitType {
|
||||||
}
|
}
|
||||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||||
}
|
}
|
||||||
|
impl AstNode for TypeBound {
|
||||||
|
fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_BOUND }
|
||||||
|
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 TupleExpr {
|
impl AstNode for TupleExpr {
|
||||||
fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_EXPR }
|
fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_EXPR }
|
||||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||||
|
@ -2661,17 +2672,6 @@ impl AstNode for MacroStmts {
|
||||||
}
|
}
|
||||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||||
}
|
}
|
||||||
impl AstNode for TypeBound {
|
|
||||||
fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_BOUND }
|
|
||||||
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 WherePred {
|
impl AstNode for WherePred {
|
||||||
fn can_cast(kind: SyntaxKind) -> bool { kind == WHERE_PRED }
|
fn can_cast(kind: SyntaxKind) -> bool { kind == WHERE_PRED }
|
||||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||||
|
@ -3746,6 +3746,11 @@ impl std::fmt::Display for DynTraitType {
|
||||||
std::fmt::Display::fmt(self.syntax(), f)
|
std::fmt::Display::fmt(self.syntax(), f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl std::fmt::Display for TypeBound {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
std::fmt::Display::fmt(self.syntax(), f)
|
||||||
|
}
|
||||||
|
}
|
||||||
impl std::fmt::Display for TupleExpr {
|
impl std::fmt::Display for TupleExpr {
|
||||||
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)
|
||||||
|
@ -4026,11 +4031,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 TypeBound {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
std::fmt::Display::fmt(self.syntax(), f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl std::fmt::Display for WherePred {
|
impl std::fmt::Display for WherePred {
|
||||||
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)
|
||||||
|
|
|
@ -362,26 +362,6 @@ impl ast::TypeBound {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn const_question_token(&self) -> Option<SyntaxToken> {
|
|
||||||
self.syntax()
|
|
||||||
.children_with_tokens()
|
|
||||||
.filter_map(|it| it.into_token())
|
|
||||||
.take_while(|it| it.kind() != T![const])
|
|
||||||
.find(|it| it.kind() == T![?])
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn question_token(&self) -> Option<SyntaxToken> {
|
|
||||||
if self.const_token().is_some() {
|
|
||||||
self.syntax()
|
|
||||||
.children_with_tokens()
|
|
||||||
.filter_map(|it| it.into_token())
|
|
||||||
.skip_while(|it| it.kind() != T![const])
|
|
||||||
.find(|it| it.kind() == T![?])
|
|
||||||
} else {
|
|
||||||
support::token(&self.syntax, T![?])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum VisibilityKind {
|
pub enum VisibilityKind {
|
||||||
|
|
|
@ -242,6 +242,13 @@ ImplTraitType =
|
||||||
DynTraitType =
|
DynTraitType =
|
||||||
'dyn' TypeBoundList
|
'dyn' TypeBoundList
|
||||||
|
|
||||||
|
TypeBoundList =
|
||||||
|
bounds:(TypeBound ('+' TypeBound)* '+'?)
|
||||||
|
|
||||||
|
TypeBound =
|
||||||
|
'lifetime'
|
||||||
|
| '?'? Type
|
||||||
|
|
||||||
TupleExpr =
|
TupleExpr =
|
||||||
Attr* '(' Expr* ')'
|
Attr* '(' Expr* ')'
|
||||||
|
|
||||||
|
@ -443,12 +450,6 @@ MacroStmts =
|
||||||
statements:Stmt*
|
statements:Stmt*
|
||||||
Expr?
|
Expr?
|
||||||
|
|
||||||
TypeBound =
|
|
||||||
'lifetime' | 'const'? Type
|
|
||||||
|
|
||||||
TypeBoundList =
|
|
||||||
bounds:TypeBound*
|
|
||||||
|
|
||||||
WherePred =
|
WherePred =
|
||||||
('for' GenericParamList)? ('lifetime' | Type) ':' TypeBoundList
|
('for' GenericParamList)? ('lifetime' | Type) ':' TypeBoundList
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue