mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
Merge remote-tracking branch 'upstream/master' into sync-from-rust
This commit is contained in:
commit
4f09335063
185 changed files with 2615 additions and 1781 deletions
|
@ -538,9 +538,13 @@ impl ast::UseTree {
|
|||
/// `foo::bar` -> `{foo::bar}`
|
||||
///
|
||||
/// `{foo::bar}` -> `{foo::bar}`
|
||||
pub fn wrap_in_tree_list(&self) {
|
||||
if self.path().is_none() {
|
||||
return;
|
||||
pub fn wrap_in_tree_list(&self) -> Option<()> {
|
||||
if self.use_tree_list().is_some()
|
||||
&& self.path().is_none()
|
||||
&& self.star_token().is_none()
|
||||
&& self.rename().is_none()
|
||||
{
|
||||
return None;
|
||||
}
|
||||
let subtree = self.clone_subtree().clone_for_update();
|
||||
ted::remove_all_iter(self.syntax().children_with_tokens());
|
||||
|
@ -548,6 +552,7 @@ impl ast::UseTree {
|
|||
self.syntax(),
|
||||
make::use_tree_list(once(subtree)).clone_for_update().syntax(),
|
||||
);
|
||||
Some(())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -960,10 +965,10 @@ impl ast::IdentPat {
|
|||
}
|
||||
|
||||
pub trait HasVisibilityEdit: ast::HasVisibility {
|
||||
fn set_visibility(&self, visbility: ast::Visibility) {
|
||||
fn set_visibility(&self, visibility: ast::Visibility) {
|
||||
match self.visibility() {
|
||||
Some(current_visibility) => {
|
||||
ted::replace(current_visibility.syntax(), visbility.syntax())
|
||||
ted::replace(current_visibility.syntax(), visibility.syntax())
|
||||
}
|
||||
None => {
|
||||
let vis_before = self
|
||||
|
@ -972,7 +977,7 @@ pub trait HasVisibilityEdit: ast::HasVisibility {
|
|||
.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), visbility.syntax());
|
||||
ted::insert(ted::Position::before(vis_before), visibility.syntax());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,10 +9,11 @@
|
|||
//! API should require to assemble every node piecewise. The trick of
|
||||
//! `parse(format!())` we use internally is an implementation detail -- long
|
||||
//! term, it will be replaced with direct tree manipulation.
|
||||
|
||||
use itertools::Itertools;
|
||||
use parser::T;
|
||||
use rowan::NodeOrToken;
|
||||
use stdx::{format_to, never};
|
||||
use stdx::{format_to, format_to_acc, never};
|
||||
|
||||
use crate::{ast, utils::is_raw_identifier, AstNode, SourceFile, SyntaxKind, SyntaxToken};
|
||||
|
||||
|
@ -759,15 +760,12 @@ pub fn match_arm_with_guard(
|
|||
}
|
||||
|
||||
pub fn match_arm_list(arms: impl IntoIterator<Item = ast::MatchArm>) -> ast::MatchArmList {
|
||||
let arms_str = arms
|
||||
.into_iter()
|
||||
.map(|arm| {
|
||||
let needs_comma = arm.expr().map_or(true, |it| !it.is_block_like());
|
||||
let comma = if needs_comma { "," } else { "" };
|
||||
let arm = arm.syntax();
|
||||
format!(" {arm}{comma}\n")
|
||||
})
|
||||
.collect::<String>();
|
||||
let arms_str = arms.into_iter().fold(String::new(), |mut acc, arm| {
|
||||
let needs_comma = arm.expr().map_or(true, |it| !it.is_block_like());
|
||||
let comma = if needs_comma { "," } else { "" };
|
||||
let arm = arm.syntax();
|
||||
format_to_acc!(acc, " {arm}{comma}\n")
|
||||
});
|
||||
return from_text(&arms_str);
|
||||
|
||||
fn from_text(text: &str) -> ast::MatchArmList {
|
||||
|
|
|
@ -384,7 +384,7 @@ impl ast::UseTreeList {
|
|||
// the below remove the innermost {}, got `use crate::{{{A}}}`
|
||||
remove_brace_in_use_tree_list(&self);
|
||||
|
||||
// the below remove othe unnecessary {}, got `use crate::A`
|
||||
// the below remove other unnecessary {}, got `use crate::A`
|
||||
while let Some(parent_use_tree_list) = self.parent_use_tree().parent_use_tree_list() {
|
||||
remove_brace_in_use_tree_list(&parent_use_tree_list);
|
||||
self = parent_use_tree_list;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue