prefer default over new

This commit is contained in:
BenjaminBrienen 2025-04-04 15:49:50 +02:00
parent 6ca780700d
commit 2462624a7d
46 changed files with 100 additions and 127 deletions

View file

@ -33,7 +33,7 @@ pub struct SyntaxEditor {
impl SyntaxEditor {
/// Creates a syntax editor to start editing from `root`
pub fn new(root: SyntaxNode) -> Self {
Self { root, changes: vec![], mappings: SyntaxMapping::new(), annotations: vec![] }
Self { root, changes: vec![], mappings: SyntaxMapping::default(), annotations: vec![] }
}
pub fn add_annotation(&mut self, element: impl Element, annotation: SyntaxAnnotation) {
@ -151,9 +151,8 @@ impl SyntaxEdit {
#[repr(transparent)]
pub struct SyntaxAnnotation(NonZeroU32);
impl SyntaxAnnotation {
/// Creates a unique syntax annotation to attach data to.
pub fn new() -> Self {
impl Default for SyntaxAnnotation {
fn default() -> Self {
static COUNTER: AtomicU32 = AtomicU32::new(1);
// Only consistency within a thread matters, as SyntaxElements are !Send
@ -163,12 +162,6 @@ impl SyntaxAnnotation {
}
}
impl Default for SyntaxAnnotation {
fn default() -> Self {
Self::new()
}
}
/// Position describing where to insert elements
#[derive(Debug)]
pub struct Position {
@ -411,12 +404,12 @@ mod tests {
let to_replace = root.syntax().descendants().find_map(ast::BinExpr::cast).unwrap();
let mut editor = SyntaxEditor::new(root.syntax().clone());
let make = SyntaxFactory::new();
let make = SyntaxFactory::with_mappings();
let name = make::name("var_name");
let name_ref = make::name_ref("var_name").clone_for_update();
let placeholder_snippet = SyntaxAnnotation::new();
let placeholder_snippet = SyntaxAnnotation::default();
editor.add_annotation(name.syntax(), placeholder_snippet);
editor.add_annotation(name_ref.syntax(), placeholder_snippet);
@ -522,7 +515,7 @@ mod tests {
let second_let = root.syntax().descendants().find_map(ast::LetStmt::cast).unwrap();
let mut editor = SyntaxEditor::new(root.syntax().clone());
let make = SyntaxFactory::new();
let make = SyntaxFactory::with_mappings();
let new_block_expr = make.block_expr([], Some(ast::Expr::BlockExpr(inner_block.clone())));
@ -574,7 +567,7 @@ mod tests {
let inner_block = root.clone();
let mut editor = SyntaxEditor::new(root.syntax().clone());
let make = SyntaxFactory::new();
let make = SyntaxFactory::with_mappings();
let new_block_expr = make.block_expr([], Some(ast::Expr::BlockExpr(inner_block.clone())));