mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
Merge commit '3b7c7f97e4
' into sync-from-ra
This commit is contained in:
parent
6eaf3f8bb2
commit
d1d111d09e
177 changed files with 14930 additions and 2099 deletions
|
@ -224,7 +224,7 @@ pub trait AttrsOwnerEdit: ast::HasAttrs {
|
|||
let after_attrs_and_comments = node
|
||||
.children_with_tokens()
|
||||
.find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR))
|
||||
.map_or(Position::first_child_of(node), |it| Position::before(it));
|
||||
.map_or(Position::first_child_of(node), Position::before);
|
||||
|
||||
ted::insert_all(
|
||||
after_attrs_and_comments,
|
||||
|
@ -433,7 +433,9 @@ impl ast::UseTree {
|
|||
if &path == prefix && self.use_tree_list().is_none() {
|
||||
if self.star_token().is_some() {
|
||||
// path$0::* -> *
|
||||
self.coloncolon_token().map(ted::remove);
|
||||
if let Some(a) = self.coloncolon_token() {
|
||||
ted::remove(a)
|
||||
}
|
||||
ted::remove(prefix.syntax());
|
||||
} else {
|
||||
// path$0 -> self
|
||||
|
@ -460,7 +462,9 @@ impl ast::UseTree {
|
|||
for p in successors(parent.parent_path(), |it| it.parent_path()) {
|
||||
p.segment()?;
|
||||
}
|
||||
prefix.parent_path().and_then(|p| p.coloncolon_token()).map(ted::remove);
|
||||
if let Some(a) = prefix.parent_path().and_then(|p| p.coloncolon_token()) {
|
||||
ted::remove(a)
|
||||
}
|
||||
ted::remove(prefix.syntax());
|
||||
Some(())
|
||||
}
|
||||
|
@ -976,7 +980,9 @@ enum Foo {
|
|||
|
||||
fn check_add_variant(before: &str, expected: &str, variant: ast::Variant) {
|
||||
let enum_ = ast_mut_from_text::<ast::Enum>(before);
|
||||
enum_.variant_list().map(|it| it.add_variant(variant));
|
||||
if let Some(it) = enum_.variant_list() {
|
||||
it.add_variant(variant)
|
||||
}
|
||||
let after = enum_.to_string();
|
||||
assert_eq_text!(&trim_indent(expected.trim()), &trim_indent(after.trim()));
|
||||
}
|
||||
|
|
|
@ -433,7 +433,6 @@ pub fn record_field(
|
|||
ast_from_text(&format!("struct S {{ {visibility}{name}: {ty}, }}"))
|
||||
}
|
||||
|
||||
// TODO
|
||||
pub fn block_expr(
|
||||
stmts: impl IntoIterator<Item = ast::Stmt>,
|
||||
tail_expr: Option<ast::Expr>,
|
||||
|
@ -853,6 +852,10 @@ pub fn self_param() -> ast::SelfParam {
|
|||
ast_from_text("fn f(&self) { }")
|
||||
}
|
||||
|
||||
pub fn mut_self_param() -> ast::SelfParam {
|
||||
ast_from_text("fn f(&mut self) { }")
|
||||
}
|
||||
|
||||
pub fn ret_type(ty: ast::Type) -> ast::RetType {
|
||||
ast_from_text(&format!("fn f() -> {ty} {{ }}"))
|
||||
}
|
||||
|
@ -973,6 +976,11 @@ pub fn tuple_field(visibility: Option<ast::Visibility>, ty: ast::Type) -> ast::T
|
|||
ast_from_text(&format!("struct f({visibility}{ty});"))
|
||||
}
|
||||
|
||||
pub fn variant_list(variants: impl IntoIterator<Item = ast::Variant>) -> ast::VariantList {
|
||||
let variants = variants.into_iter().join(", ");
|
||||
ast_from_text(&format!("enum f {{ {variants} }}"))
|
||||
}
|
||||
|
||||
pub fn variant(name: ast::Name, field_list: Option<ast::FieldList>) -> ast::Variant {
|
||||
let field_list = match field_list {
|
||||
None => String::new(),
|
||||
|
@ -1037,6 +1045,19 @@ pub fn struct_(
|
|||
ast_from_text(&format!("{visibility}struct {strukt_name}{type_params}{field_list}{semicolon}",))
|
||||
}
|
||||
|
||||
pub fn enum_(
|
||||
visibility: Option<ast::Visibility>,
|
||||
enum_name: ast::Name,
|
||||
variant_list: ast::VariantList,
|
||||
) -> ast::Enum {
|
||||
let visibility = match visibility {
|
||||
None => String::new(),
|
||||
Some(it) => format!("{it} "),
|
||||
};
|
||||
|
||||
ast_from_text(&format!("{visibility}enum {enum_name} {variant_list}"))
|
||||
}
|
||||
|
||||
pub fn attr_outer(meta: ast::Meta) -> ast::Attr {
|
||||
ast_from_text(&format!("#[{meta}]"))
|
||||
}
|
||||
|
@ -1149,6 +1170,16 @@ pub mod tokens {
|
|||
lit.syntax().first_child_or_token().unwrap().into_token().unwrap()
|
||||
}
|
||||
|
||||
pub fn ident(text: &str) -> SyntaxToken {
|
||||
assert_eq!(text.trim(), text);
|
||||
let path: ast::Path = super::ext::ident_path(text);
|
||||
path.syntax()
|
||||
.descendants_with_tokens()
|
||||
.filter_map(|it| it.into_token())
|
||||
.find(|it| it.kind() == IDENT)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn single_newline() -> SyntaxToken {
|
||||
let res = SOURCE_FILE
|
||||
.tree()
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
use std::borrow::Cow;
|
||||
|
||||
use rustc_dependencies::lexer as rustc_lexer;
|
||||
|
||||
use rustc_lexer::unescape::{
|
||||
unescape_byte, unescape_c_string, unescape_char, unescape_literal, CStrUnit, Mode,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue