mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Prepare for pat_field_shorthand
This commit is contained in:
parent
d447a9a381
commit
c8cbd398e4
1 changed files with 13 additions and 5 deletions
|
@ -15,7 +15,7 @@ use itertools::Itertools;
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, AstNode},
|
ast::{self, AstNode},
|
||||||
SyntaxNode, TextRange, T,
|
match_ast, SyntaxNode, TextRange, T,
|
||||||
};
|
};
|
||||||
use text_edit::TextEdit;
|
use text_edit::TextEdit;
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ pub(crate) fn diagnostics(
|
||||||
|
|
||||||
for node in parse.tree().syntax().descendants() {
|
for node in parse.tree().syntax().descendants() {
|
||||||
check_unnecessary_braces_in_use_statement(&mut res, file_id, &node);
|
check_unnecessary_braces_in_use_statement(&mut res, file_id, &node);
|
||||||
check_struct_shorthand_initialization(&mut res, file_id, &node);
|
check_field_shorthand(&mut res, file_id, &node);
|
||||||
}
|
}
|
||||||
let res = RefCell::new(res);
|
let res = RefCell::new(res);
|
||||||
let sink_builder = DiagnosticSinkBuilder::new()
|
let sink_builder = DiagnosticSinkBuilder::new()
|
||||||
|
@ -188,12 +188,20 @@ fn text_edit_for_remove_unnecessary_braces_with_self_in_use_statement(
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_struct_shorthand_initialization(
|
fn check_field_shorthand(acc: &mut Vec<Diagnostic>, file_id: FileId, node: &SyntaxNode) {
|
||||||
|
match_ast! {
|
||||||
|
match node {
|
||||||
|
ast::RecordExpr(it) => check_expr_field_shorthand(acc, file_id, it),
|
||||||
|
_ => None
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn check_expr_field_shorthand(
|
||||||
acc: &mut Vec<Diagnostic>,
|
acc: &mut Vec<Diagnostic>,
|
||||||
file_id: FileId,
|
file_id: FileId,
|
||||||
node: &SyntaxNode,
|
record_lit: ast::RecordExpr,
|
||||||
) -> Option<()> {
|
) -> Option<()> {
|
||||||
let record_lit = ast::RecordExpr::cast(node.clone())?;
|
|
||||||
let record_field_list = record_lit.record_expr_field_list()?;
|
let record_field_list = record_lit.record_expr_field_list()?;
|
||||||
for record_field in record_field_list.fields() {
|
for record_field in record_field_list.fields() {
|
||||||
if let (Some(name_ref), Some(expr)) = (record_field.name_ref(), record_field.expr()) {
|
if let (Some(name_ref), Some(expr)) = (record_field.name_ref(), record_field.expr()) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue