mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-14 00:47:18 +00:00
Merge #5621
5621: Finalize TypeBound grammar r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
84bf024094
4 changed files with 35 additions and 54 deletions
|
@ -270,7 +270,7 @@ impl GenericParams {
|
|||
bound: ast::TypeBound,
|
||||
type_ref: TypeRef,
|
||||
) {
|
||||
if bound.question_token().is_some() {
|
||||
if bound.question_mark_token().is_some() {
|
||||
// FIXME: remove this bound
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -639,6 +639,17 @@ impl DynTraitType {
|
|||
pub fn type_bound_list(&self) -> Option<TypeBoundList> { support::child(&self.syntax) }
|
||||
}
|
||||
#[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(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
@ -1168,17 +1179,6 @@ impl MacroStmts {
|
|||
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
|
||||
}
|
||||
#[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(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
@ -2045,6 +2045,17 @@ impl AstNode for DynTraitType {
|
|||
}
|
||||
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 {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_EXPR }
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
|
@ -2661,17 +2672,6 @@ impl AstNode for MacroStmts {
|
|||
}
|
||||
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 {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == WHERE_PRED }
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
|
@ -3746,6 +3746,11 @@ impl std::fmt::Display for DynTraitType {
|
|||
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 {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
|
@ -4026,11 +4031,6 @@ impl std::fmt::Display for MacroStmts {
|
|||
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 {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
|
|
|
@ -362,26 +362,6 @@ impl ast::TypeBound {
|
|||
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 {
|
||||
|
|
|
@ -242,6 +242,13 @@ ImplTraitType =
|
|||
DynTraitType =
|
||||
'dyn' TypeBoundList
|
||||
|
||||
TypeBoundList =
|
||||
bounds:(TypeBound ('+' TypeBound)* '+'?)
|
||||
|
||||
TypeBound =
|
||||
'lifetime'
|
||||
| '?'? Type
|
||||
|
||||
TupleExpr =
|
||||
Attr* '(' Expr* ')'
|
||||
|
||||
|
@ -443,12 +450,6 @@ MacroStmts =
|
|||
statements:Stmt*
|
||||
Expr?
|
||||
|
||||
TypeBound =
|
||||
'lifetime' | 'const'? Type
|
||||
|
||||
TypeBoundList =
|
||||
bounds:TypeBound*
|
||||
|
||||
WherePred =
|
||||
('for' GenericParamList)? ('lifetime' | Type) ':' TypeBoundList
|
||||
|
||||
|
|
Loading…
Reference in a new issue