mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
Merge commit 'af40101841
' into sync-from-ra
This commit is contained in:
parent
79fa976864
commit
3afeb24198
115 changed files with 3106 additions and 3623 deletions
|
@ -293,13 +293,12 @@ impl ast::GenericParamList {
|
|||
}
|
||||
|
||||
/// Removes the corresponding generic arg
|
||||
pub fn remove_generic_arg(&self, generic_arg: &ast::GenericArg) -> Option<GenericParam> {
|
||||
pub fn remove_generic_arg(&self, generic_arg: &ast::GenericArg) {
|
||||
let param_to_remove = self.find_generic_arg(generic_arg);
|
||||
|
||||
if let Some(param) = ¶m_to_remove {
|
||||
self.remove_generic_param(param.clone());
|
||||
}
|
||||
param_to_remove
|
||||
}
|
||||
|
||||
/// Constructs a matching [`ast::GenericArgList`]
|
||||
|
|
|
@ -13,6 +13,8 @@ use crate::{
|
|||
SyntaxNode, SyntaxToken, T,
|
||||
};
|
||||
|
||||
use super::RangeItem;
|
||||
|
||||
impl ast::HasAttrs for ast::Expr {}
|
||||
|
||||
impl ast::Expr {
|
||||
|
@ -227,16 +229,12 @@ impl ast::RangeExpr {
|
|||
Some((ix, token, bin_op))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn op_kind(&self) -> Option<RangeOp> {
|
||||
self.op_details().map(|t| t.2)
|
||||
}
|
||||
impl RangeItem for ast::RangeExpr {
|
||||
type Bound = ast::Expr;
|
||||
|
||||
pub fn op_token(&self) -> Option<SyntaxToken> {
|
||||
self.op_details().map(|t| t.1)
|
||||
}
|
||||
|
||||
pub fn start(&self) -> Option<ast::Expr> {
|
||||
fn start(&self) -> Option<ast::Expr> {
|
||||
let op_ix = self.op_details()?.0;
|
||||
self.syntax()
|
||||
.children_with_tokens()
|
||||
|
@ -244,13 +242,21 @@ impl ast::RangeExpr {
|
|||
.find_map(|it| ast::Expr::cast(it.into_node()?))
|
||||
}
|
||||
|
||||
pub fn end(&self) -> Option<ast::Expr> {
|
||||
fn end(&self) -> Option<ast::Expr> {
|
||||
let op_ix = self.op_details()?.0;
|
||||
self.syntax()
|
||||
.children_with_tokens()
|
||||
.skip(op_ix + 1)
|
||||
.find_map(|it| ast::Expr::cast(it.into_node()?))
|
||||
}
|
||||
|
||||
fn op_token(&self) -> Option<SyntaxToken> {
|
||||
self.op_details().map(|t| t.1)
|
||||
}
|
||||
|
||||
fn op_kind(&self) -> Option<RangeOp> {
|
||||
self.op_details().map(|t| t.2)
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::IndexExpr {
|
||||
|
|
|
@ -263,9 +263,6 @@ pub fn impl_(
|
|||
ast_from_text(&format!("impl{gen_params} {path_type}{tr_gen_args}{where_clause}{{{}}}", body))
|
||||
}
|
||||
|
||||
// FIXME : We must make *_gen_args' type ast::GenericArgList but in order to do so we must implement in `edit_in_place.rs`
|
||||
// `add_generic_arg()` just like `add_generic_param()`
|
||||
// is implemented for `ast::GenericParamList`
|
||||
pub fn impl_trait(
|
||||
is_unsafe: bool,
|
||||
trait_gen_params: Option<ast::GenericParamList>,
|
||||
|
|
|
@ -14,6 +14,8 @@ use crate::{
|
|||
ted, NodeOrToken, SmolStr, SyntaxElement, SyntaxToken, TokenText, T,
|
||||
};
|
||||
|
||||
use super::{RangeItem, RangeOp};
|
||||
|
||||
impl ast::Lifetime {
|
||||
pub fn text(&self) -> TokenText<'_> {
|
||||
text_of_first_token(self.syntax())
|
||||
|
@ -875,8 +877,10 @@ impl ast::Module {
|
|||
}
|
||||
}
|
||||
|
||||
impl ast::RangePat {
|
||||
pub fn start(&self) -> Option<ast::Pat> {
|
||||
impl RangeItem for ast::RangePat {
|
||||
type Bound = ast::Pat;
|
||||
|
||||
fn start(&self) -> Option<ast::Pat> {
|
||||
self.syntax()
|
||||
.children_with_tokens()
|
||||
.take_while(|it| !(it.kind() == T![..] || it.kind() == T![..=]))
|
||||
|
@ -884,13 +888,37 @@ impl ast::RangePat {
|
|||
.find_map(ast::Pat::cast)
|
||||
}
|
||||
|
||||
pub fn end(&self) -> Option<ast::Pat> {
|
||||
fn end(&self) -> Option<ast::Pat> {
|
||||
self.syntax()
|
||||
.children_with_tokens()
|
||||
.skip_while(|it| !(it.kind() == T![..] || it.kind() == T![..=]))
|
||||
.filter_map(|it| it.into_node())
|
||||
.find_map(ast::Pat::cast)
|
||||
}
|
||||
|
||||
fn op_token(&self) -> Option<SyntaxToken> {
|
||||
self.syntax().children_with_tokens().find_map(|it| {
|
||||
let token = it.into_token()?;
|
||||
|
||||
match token.kind() {
|
||||
T![..] => Some(token),
|
||||
T![..=] => Some(token),
|
||||
_ => None,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn op_kind(&self) -> Option<RangeOp> {
|
||||
self.syntax().children_with_tokens().find_map(|it| {
|
||||
let token = it.into_token()?;
|
||||
|
||||
match token.kind() {
|
||||
T![..] => Some(RangeOp::Exclusive),
|
||||
T![..=] => Some(RangeOp::Inclusive),
|
||||
_ => None,
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::TokenTree {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//! Precedence representation.
|
||||
|
||||
use crate::{
|
||||
ast::{self, BinaryOp, Expr, HasArgList},
|
||||
ast::{self, BinaryOp, Expr, HasArgList, RangeItem},
|
||||
match_ast, AstNode, SyntaxNode,
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue