mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
feat(syntax): RTN in bounds
Limited syntactic support for experimental return type notations. https://github.com/rust-lang/rust/issues/109417
This commit is contained in:
parent
ffb04ae32d
commit
0b9c0c5088
8 changed files with 103 additions and 2 deletions
|
@ -142,6 +142,18 @@ impl ConstArg {
|
|||
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ReturnTypeArg {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
impl ast::HasTypeBounds for ReturnTypeArg {}
|
||||
impl ReturnTypeArg {
|
||||
pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
|
||||
pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
|
||||
pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) }
|
||||
pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct TypeBoundList {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
|
@ -1516,6 +1528,7 @@ pub enum GenericArg {
|
|||
AssocTypeArg(AssocTypeArg),
|
||||
LifetimeArg(LifetimeArg),
|
||||
ConstArg(ConstArg),
|
||||
ReturnTypeArg(ReturnTypeArg),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
|
@ -1865,6 +1878,17 @@ impl AstNode for ConstArg {
|
|||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
impl AstNode for ReturnTypeArg {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == RETURN_TYPE_ARG }
|
||||
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 TypeBoundList {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_BOUND_LIST }
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
|
@ -3219,9 +3243,12 @@ impl From<LifetimeArg> for GenericArg {
|
|||
impl From<ConstArg> for GenericArg {
|
||||
fn from(node: ConstArg) -> GenericArg { GenericArg::ConstArg(node) }
|
||||
}
|
||||
impl From<ReturnTypeArg> for GenericArg {
|
||||
fn from(node: ReturnTypeArg) -> GenericArg { GenericArg::ReturnTypeArg(node) }
|
||||
}
|
||||
impl AstNode for GenericArg {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
matches!(kind, TYPE_ARG | ASSOC_TYPE_ARG | LIFETIME_ARG | CONST_ARG)
|
||||
matches!(kind, TYPE_ARG | ASSOC_TYPE_ARG | LIFETIME_ARG | CONST_ARG | RETURN_TYPE_ARG)
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
let res = match syntax.kind() {
|
||||
|
@ -3229,6 +3256,7 @@ impl AstNode for GenericArg {
|
|||
ASSOC_TYPE_ARG => GenericArg::AssocTypeArg(AssocTypeArg { syntax }),
|
||||
LIFETIME_ARG => GenericArg::LifetimeArg(LifetimeArg { syntax }),
|
||||
CONST_ARG => GenericArg::ConstArg(ConstArg { syntax }),
|
||||
RETURN_TYPE_ARG => GenericArg::ReturnTypeArg(ReturnTypeArg { syntax }),
|
||||
_ => return None,
|
||||
};
|
||||
Some(res)
|
||||
|
@ -3239,6 +3267,7 @@ impl AstNode for GenericArg {
|
|||
GenericArg::AssocTypeArg(it) => &it.syntax,
|
||||
GenericArg::LifetimeArg(it) => &it.syntax,
|
||||
GenericArg::ConstArg(it) => &it.syntax,
|
||||
GenericArg::ReturnTypeArg(it) => &it.syntax,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4170,7 +4199,13 @@ impl AstNode for AnyHasTypeBounds {
|
|||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
matches!(
|
||||
kind,
|
||||
ASSOC_TYPE_ARG | TRAIT | TYPE_ALIAS | LIFETIME_PARAM | TYPE_PARAM | WHERE_PRED
|
||||
ASSOC_TYPE_ARG
|
||||
| RETURN_TYPE_ARG
|
||||
| TRAIT
|
||||
| TYPE_ALIAS
|
||||
| LIFETIME_PARAM
|
||||
| TYPE_PARAM
|
||||
| WHERE_PRED
|
||||
)
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
|
@ -4333,6 +4368,11 @@ impl std::fmt::Display for ConstArg {
|
|||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for ReturnTypeArg {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for TypeBoundList {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue