mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Merge commit 'ac998a74b3
' into sync-from-ra
This commit is contained in:
parent
d33d8675d0
commit
6b17dba68c
178 changed files with 7101 additions and 1965 deletions
|
@ -367,6 +367,7 @@ Expr =
|
|||
| RecordExpr
|
||||
| RefExpr
|
||||
| ReturnExpr
|
||||
| BecomeExpr
|
||||
| TryExpr
|
||||
| TupleExpr
|
||||
| WhileExpr
|
||||
|
@ -528,6 +529,9 @@ MatchGuard =
|
|||
ReturnExpr =
|
||||
Attr* 'return' Expr?
|
||||
|
||||
BecomeExpr =
|
||||
Attr* 'become' Expr
|
||||
|
||||
YieldExpr =
|
||||
Attr* 'yield' Expr?
|
||||
|
||||
|
@ -610,7 +614,7 @@ TypeBoundList =
|
|||
|
||||
TypeBound =
|
||||
Lifetime
|
||||
| ('?' | '~' 'const')? Type
|
||||
| ('~' 'const' | 'const')? 'async'? '?'? Type
|
||||
|
||||
//************************//
|
||||
// Patterns //
|
||||
|
|
|
@ -1007,20 +1007,24 @@ impl ast::IdentPat {
|
|||
}
|
||||
|
||||
pub trait HasVisibilityEdit: ast::HasVisibility {
|
||||
fn set_visibility(&self, visibility: ast::Visibility) {
|
||||
match self.visibility() {
|
||||
Some(current_visibility) => {
|
||||
ted::replace(current_visibility.syntax(), visibility.syntax())
|
||||
}
|
||||
None => {
|
||||
let vis_before = self
|
||||
.syntax()
|
||||
.children_with_tokens()
|
||||
.find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR))
|
||||
.unwrap_or_else(|| self.syntax().first_child_or_token().unwrap());
|
||||
fn set_visibility(&self, visibility: Option<ast::Visibility>) {
|
||||
if let Some(visibility) = visibility {
|
||||
match self.visibility() {
|
||||
Some(current_visibility) => {
|
||||
ted::replace(current_visibility.syntax(), visibility.syntax())
|
||||
}
|
||||
None => {
|
||||
let vis_before = self
|
||||
.syntax()
|
||||
.children_with_tokens()
|
||||
.find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR))
|
||||
.unwrap_or_else(|| self.syntax().first_child_or_token().unwrap());
|
||||
|
||||
ted::insert(ted::Position::before(vis_before), visibility.syntax());
|
||||
ted::insert(ted::Position::before(vis_before), visibility.syntax());
|
||||
}
|
||||
}
|
||||
} else if let Some(visibility) = self.visibility() {
|
||||
ted::remove(visibility.syntax());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1095,6 +1095,16 @@ impl ReturnExpr {
|
|||
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct BecomeExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
impl ast::HasAttrs for BecomeExpr {}
|
||||
impl BecomeExpr {
|
||||
pub fn become_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![become]) }
|
||||
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct TryExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
|
@ -1400,9 +1410,10 @@ pub struct TypeBound {
|
|||
}
|
||||
impl TypeBound {
|
||||
pub fn lifetime(&self) -> Option<Lifetime> { support::child(&self.syntax) }
|
||||
pub fn question_mark_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![?]) }
|
||||
pub fn tilde_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![~]) }
|
||||
pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
|
||||
pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) }
|
||||
pub fn question_mark_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![?]) }
|
||||
pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
|
||||
}
|
||||
|
||||
|
@ -1633,6 +1644,7 @@ pub enum Expr {
|
|||
RecordExpr(RecordExpr),
|
||||
RefExpr(RefExpr),
|
||||
ReturnExpr(ReturnExpr),
|
||||
BecomeExpr(BecomeExpr),
|
||||
TryExpr(TryExpr),
|
||||
TupleExpr(TupleExpr),
|
||||
WhileExpr(WhileExpr),
|
||||
|
@ -2792,6 +2804,17 @@ impl AstNode for ReturnExpr {
|
|||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
impl AstNode for BecomeExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == BECOME_EXPR }
|
||||
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 TryExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == TRY_EXPR }
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
|
@ -3540,6 +3563,9 @@ impl From<RefExpr> for Expr {
|
|||
impl From<ReturnExpr> for Expr {
|
||||
fn from(node: ReturnExpr) -> Expr { Expr::ReturnExpr(node) }
|
||||
}
|
||||
impl From<BecomeExpr> for Expr {
|
||||
fn from(node: BecomeExpr) -> Expr { Expr::BecomeExpr(node) }
|
||||
}
|
||||
impl From<TryExpr> for Expr {
|
||||
fn from(node: TryExpr) -> Expr { Expr::TryExpr(node) }
|
||||
}
|
||||
|
@ -3593,6 +3619,7 @@ impl AstNode for Expr {
|
|||
| RECORD_EXPR
|
||||
| REF_EXPR
|
||||
| RETURN_EXPR
|
||||
| BECOME_EXPR
|
||||
| TRY_EXPR
|
||||
| TUPLE_EXPR
|
||||
| WHILE_EXPR
|
||||
|
@ -3632,6 +3659,7 @@ impl AstNode for Expr {
|
|||
RECORD_EXPR => Expr::RecordExpr(RecordExpr { syntax }),
|
||||
REF_EXPR => Expr::RefExpr(RefExpr { syntax }),
|
||||
RETURN_EXPR => Expr::ReturnExpr(ReturnExpr { syntax }),
|
||||
BECOME_EXPR => Expr::BecomeExpr(BecomeExpr { syntax }),
|
||||
TRY_EXPR => Expr::TryExpr(TryExpr { syntax }),
|
||||
TUPLE_EXPR => Expr::TupleExpr(TupleExpr { syntax }),
|
||||
WHILE_EXPR => Expr::WhileExpr(WhileExpr { syntax }),
|
||||
|
@ -3673,6 +3701,7 @@ impl AstNode for Expr {
|
|||
Expr::RecordExpr(it) => &it.syntax,
|
||||
Expr::RefExpr(it) => &it.syntax,
|
||||
Expr::ReturnExpr(it) => &it.syntax,
|
||||
Expr::BecomeExpr(it) => &it.syntax,
|
||||
Expr::TryExpr(it) => &it.syntax,
|
||||
Expr::TupleExpr(it) => &it.syntax,
|
||||
Expr::WhileExpr(it) => &it.syntax,
|
||||
|
@ -4150,6 +4179,7 @@ impl AstNode for AnyHasAttrs {
|
|||
| RANGE_EXPR
|
||||
| REF_EXPR
|
||||
| RETURN_EXPR
|
||||
| BECOME_EXPR
|
||||
| TRY_EXPR
|
||||
| TUPLE_EXPR
|
||||
| WHILE_EXPR
|
||||
|
@ -4851,6 +4881,11 @@ impl std::fmt::Display for ReturnExpr {
|
|||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for BecomeExpr {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for TryExpr {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
|
|
|
@ -1147,7 +1147,7 @@ pub mod tokens {
|
|||
|
||||
pub(super) static SOURCE_FILE: Lazy<Parse<SourceFile>> = Lazy::new(|| {
|
||||
SourceFile::parse(
|
||||
"const C: <()>::Item = ( true && true , true || true , 1 != 1, 2 == 2, 3 < 3, 4 <= 4, 5 > 5, 6 >= 6, !true, *p, &p , &mut p, { let a @ [] })\n;\n\n",
|
||||
"const C: <()>::Item = ( true && true , true || true , 1 != 1, 2 == 2, 3 < 3, 4 <= 4, 5 > 5, 6 >= 6, !true, *p, &p , &mut p, { let a @ [] })\n;\n\nimpl A for B where: {}",
|
||||
)
|
||||
});
|
||||
|
||||
|
|
|
@ -569,6 +569,26 @@ impl fmt::Display for NameOrNameRef {
|
|||
}
|
||||
}
|
||||
|
||||
impl ast::AstNode for NameOrNameRef {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
matches!(kind, SyntaxKind::NAME | SyntaxKind::NAME_REF)
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
let res = match syntax.kind() {
|
||||
SyntaxKind::NAME => NameOrNameRef::Name(ast::Name { syntax }),
|
||||
SyntaxKind::NAME_REF => NameOrNameRef::NameRef(ast::NameRef { syntax }),
|
||||
_ => return None,
|
||||
};
|
||||
Some(res)
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
match self {
|
||||
NameOrNameRef::NameRef(it) => it.syntax(),
|
||||
NameOrNameRef::Name(it) => it.syntax(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl NameOrNameRef {
|
||||
pub fn text(&self) -> TokenText<'_> {
|
||||
match self {
|
||||
|
|
|
@ -130,8 +130,8 @@ impl Expr {
|
|||
//
|
||||
ContinueExpr(_) => (0, 0),
|
||||
|
||||
ClosureExpr(_) | ReturnExpr(_) | YieldExpr(_) | YeetExpr(_) | BreakExpr(_)
|
||||
| OffsetOfExpr(_) | FormatArgsExpr(_) | AsmExpr(_) => (0, 1),
|
||||
ClosureExpr(_) | ReturnExpr(_) | BecomeExpr(_) | YieldExpr(_) | YeetExpr(_)
|
||||
| BreakExpr(_) | OffsetOfExpr(_) | FormatArgsExpr(_) | AsmExpr(_) => (0, 1),
|
||||
|
||||
RangeExpr(_) => (5, 5),
|
||||
|
||||
|
@ -288,6 +288,7 @@ impl Expr {
|
|||
PrefixExpr(e) => e.op_token(),
|
||||
RefExpr(e) => e.amp_token(),
|
||||
ReturnExpr(e) => e.return_token(),
|
||||
BecomeExpr(e) => e.become_token(),
|
||||
TryExpr(e) => e.question_mark_token(),
|
||||
YieldExpr(e) => e.yield_token(),
|
||||
YeetExpr(e) => e.do_token(),
|
||||
|
@ -316,7 +317,8 @@ impl Expr {
|
|||
|
||||
// For BinExpr and RangeExpr this is technically wrong -- the child can be on the left...
|
||||
BinExpr(_) | RangeExpr(_) | BreakExpr(_) | ContinueExpr(_) | PrefixExpr(_)
|
||||
| RefExpr(_) | ReturnExpr(_) | YieldExpr(_) | YeetExpr(_) | LetExpr(_) => self
|
||||
| RefExpr(_) | ReturnExpr(_) | BecomeExpr(_) | YieldExpr(_) | YeetExpr(_)
|
||||
| LetExpr(_) => self
|
||||
.syntax()
|
||||
.parent()
|
||||
.and_then(Expr::cast)
|
||||
|
|
|
@ -27,11 +27,6 @@ extern crate ra_ap_rustc_lexer as rustc_lexer;
|
|||
#[cfg(feature = "in-rust-tree")]
|
||||
extern crate rustc_lexer;
|
||||
|
||||
#[allow(unused)]
|
||||
macro_rules! eprintln {
|
||||
($($tt:tt)*) => { stdx::eprintln!($($tt)*) };
|
||||
}
|
||||
|
||||
mod parsing;
|
||||
mod ptr;
|
||||
mod syntax_error;
|
||||
|
|
|
@ -67,8 +67,9 @@ pub(crate) const KINDS_SRC: KindsSrc<'_> = KindsSrc {
|
|||
keywords: &[
|
||||
"as", "async", "await", "box", "break", "const", "continue", "crate", "do", "dyn", "else",
|
||||
"enum", "extern", "false", "fn", "for", "if", "impl", "in", "let", "loop", "macro",
|
||||
"match", "mod", "move", "mut", "pub", "ref", "return", "self", "Self", "static", "struct",
|
||||
"super", "trait", "true", "try", "type", "unsafe", "use", "where", "while", "yield",
|
||||
"match", "mod", "move", "mut", "pub", "ref", "return", "become", "self", "Self", "static",
|
||||
"struct", "super", "trait", "true", "try", "type", "unsafe", "use", "where", "while",
|
||||
"yield",
|
||||
],
|
||||
contextual_keywords: &[
|
||||
"auto",
|
||||
|
@ -154,6 +155,7 @@ pub(crate) const KINDS_SRC: KindsSrc<'_> = KindsSrc {
|
|||
"BLOCK_EXPR",
|
||||
"STMT_LIST",
|
||||
"RETURN_EXPR",
|
||||
"BECOME_EXPR",
|
||||
"YIELD_EXPR",
|
||||
"YEET_EXPR",
|
||||
"LET_EXPR",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue