mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-21 11:00:26 +00:00
Merge #6456
6456: Support record variants in extract_struct_from_enum_variant r=matklad a=Veykril As requested :) This also prevents the assist from being disabled if a definition in the value namespace exists with the same name as our new struct since that won't cause a collision #4468 Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
bd6eeffb2f
3 changed files with 137 additions and 41 deletions
|
@ -110,8 +110,16 @@ pub fn record_expr_field(name: ast::NameRef, expr: Option<ast::Expr>) -> ast::Re
|
|||
}
|
||||
}
|
||||
|
||||
pub fn record_field(name: ast::NameRef, ty: ast::Type) -> ast::RecordField {
|
||||
ast_from_text(&format!("struct S {{ {}: {}, }}", name, ty))
|
||||
pub fn record_field(
|
||||
visibility: Option<ast::Visibility>,
|
||||
name: ast::Name,
|
||||
ty: ast::Type,
|
||||
) -> ast::RecordField {
|
||||
let visibility = match visibility {
|
||||
None => String::new(),
|
||||
Some(it) => format!("{} ", it),
|
||||
};
|
||||
ast_from_text(&format!("struct S {{ {}{}: {}, }}", visibility, name, ty))
|
||||
}
|
||||
|
||||
pub fn block_expr(
|
||||
|
@ -360,6 +368,13 @@ pub fn tuple_field_list(fields: impl IntoIterator<Item = ast::TupleField>) -> as
|
|||
ast_from_text(&format!("struct f({});", fields))
|
||||
}
|
||||
|
||||
pub fn record_field_list(
|
||||
fields: impl IntoIterator<Item = ast::RecordField>,
|
||||
) -> ast::RecordFieldList {
|
||||
let fields = fields.into_iter().join(", ");
|
||||
ast_from_text(&format!("struct f {{ {} }}", fields))
|
||||
}
|
||||
|
||||
pub fn tuple_field(visibility: Option<ast::Visibility>, ty: ast::Type) -> ast::TupleField {
|
||||
let visibility = match visibility {
|
||||
None => String::new(),
|
||||
|
@ -368,6 +383,14 @@ pub fn tuple_field(visibility: Option<ast::Visibility>, ty: ast::Type) -> ast::T
|
|||
ast_from_text(&format!("struct f({}{});", visibility, ty))
|
||||
}
|
||||
|
||||
pub fn variant(name: ast::Name, field_list: Option<ast::FieldList>) -> ast::Variant {
|
||||
let field_list = match field_list {
|
||||
None => String::new(),
|
||||
Some(it) => format!("{}", it),
|
||||
};
|
||||
ast_from_text(&format!("enum f {{ {}{} }}", name, field_list))
|
||||
}
|
||||
|
||||
pub fn fn_(
|
||||
visibility: Option<ast::Visibility>,
|
||||
fn_name: ast::Name,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue