mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 01:17:27 +00:00
Remove un needed extra handling for remove self with braces
This commit is contained in:
parent
ce0239bd6a
commit
3fb6a3be82
1 changed files with 5 additions and 17 deletions
|
@ -27,13 +27,11 @@ pub(crate) fn useless_braces(
|
|||
}
|
||||
|
||||
let use_range = use_tree_list.syntax().text_range();
|
||||
let edit = remove_braces(&single_use_tree).unwrap_or_else(|| {
|
||||
let to_replace = single_use_tree.syntax().text().to_string();
|
||||
let mut edit_builder = TextEdit::builder();
|
||||
edit_builder.delete(use_range);
|
||||
edit_builder.insert(use_range.start(), to_replace);
|
||||
edit_builder.finish()
|
||||
});
|
||||
let to_replace = single_use_tree.syntax().text().to_string();
|
||||
let mut edit_builder = TextEdit::builder();
|
||||
edit_builder.delete(use_range);
|
||||
edit_builder.insert(use_range.start(), to_replace);
|
||||
let edit = edit_builder.finish();
|
||||
|
||||
acc.push(
|
||||
Diagnostic::new(
|
||||
|
@ -53,16 +51,6 @@ pub(crate) fn useless_braces(
|
|||
Some(())
|
||||
}
|
||||
|
||||
fn remove_braces(single_use_tree: &ast::UseTree) -> Option<TextEdit> {
|
||||
let use_tree_list_node = single_use_tree.syntax().parent()?;
|
||||
if single_use_tree.path()?.segment()?.self_token().is_some() {
|
||||
let start = use_tree_list_node.prev_sibling_or_token()?.text_range().start();
|
||||
let end = use_tree_list_node.text_range().end();
|
||||
return Some(TextEdit::delete(TextRange::new(start, end)));
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::tests::{check_diagnostics, check_fix};
|
||||
|
|
Loading…
Reference in a new issue