Skip to content

Commit afcb45e

Browse files
authored
Merge pull request #19520 from BenjaminBrienen/defaultnew
Align usage of `default` and `new` with style guide
2 parents 6ca7807 + 2462624 commit afcb45e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+98
-125
lines changed

crates/base-db/src/change.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ impl fmt::Debug for FileChange {
3434
}
3535

3636
impl FileChange {
37-
pub fn new() -> Self {
38-
FileChange::default()
39-
}
40-
4137
pub fn set_roots(&mut self, roots: Vec<SourceRoot>) {
4238
self.roots = Some(roots);
4339
}

crates/hir-def/src/dyn_map.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ pub struct Key<K, V, P = (K, V)> {
112112
}
113113

114114
impl<K, V, P> Key<K, V, P> {
115+
#[allow(
116+
clippy::new_without_default,
117+
reason = "this a const fn, so it can't be default yet. See <https://github.com/rust-lang/rust/issues/63065>"
118+
)]
115119
pub(crate) const fn new() -> Key<K, V, P> {
116120
Key { _phantom: PhantomData }
117121
}
@@ -148,16 +152,11 @@ impl<K: Hash + Eq + 'static, V: 'static> Policy for (K, V) {
148152
}
149153
}
150154

155+
#[derive(Default)]
151156
pub struct DynMap {
152157
pub(crate) map: Map,
153158
}
154159

155-
impl Default for DynMap {
156-
fn default() -> Self {
157-
DynMap { map: Map::new() }
158-
}
159-
}
160-
161160
#[repr(transparent)]
162161
pub struct KeyMap<KEY> {
163162
map: DynMap,

crates/hir-def/src/expr_store/lower.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2053,7 +2053,7 @@ impl ExprCollector<'_> {
20532053
f: ast::FormatArgsExpr,
20542054
syntax_ptr: AstPtr<ast::Expr>,
20552055
) -> ExprId {
2056-
let mut args = FormatArgumentsCollector::new();
2056+
let mut args = FormatArgumentsCollector::default();
20572057
f.args().for_each(|arg| {
20582058
args.add(FormatArgument {
20592059
kind: match arg.name() {

crates/hir-def/src/hir/format_args.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,10 +460,6 @@ impl FormatArgumentsCollector {
460460
}
461461
}
462462

463-
pub fn new() -> Self {
464-
Default::default()
465-
}
466-
467463
pub fn add(&mut self, arg: FormatArgument) -> usize {
468464
let index = self.arguments.len();
469465
if let Some(name) = arg.kind.ident() {

crates/hir-expand/src/change.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ pub struct ChangeWithProcMacros {
1414
}
1515

1616
impl ChangeWithProcMacros {
17-
pub fn new() -> Self {
18-
Self::default()
19-
}
20-
2117
pub fn apply(self, db: &mut impl ExpandDatabase) {
2218
let crates_id_map = self.source_change.apply(db);
2319
if let Some(proc_macros) = self.proc_macros {

crates/ide-assists/src/handlers/add_braces.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub(crate) fn add_braces(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<(
3939
},
4040
expr.syntax().text_range(),
4141
|builder| {
42-
let make = SyntaxFactory::new();
42+
let make = SyntaxFactory::with_mappings();
4343
let mut editor = builder.make_editor(expr.syntax());
4444

4545
let block_expr = make.block_expr(None, Some(expr.clone()));

crates/ide-assists/src/handlers/add_missing_match_arms.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
7777

7878
let cfg = ctx.config.import_path_config();
7979

80-
let make = SyntaxFactory::new();
80+
let make = SyntaxFactory::with_mappings();
8181

8282
let module = ctx.sema.scope(expr.syntax())?.module();
8383
let (mut missing_pats, is_non_exhaustive, has_hidden_variants): (
@@ -467,7 +467,7 @@ fn build_pat(
467467
let fields = var.fields(db);
468468
let pat: ast::Pat = match var.kind(db) {
469469
hir::StructKind::Tuple => {
470-
let mut name_generator = suggest_name::NameGenerator::new();
470+
let mut name_generator = suggest_name::NameGenerator::default();
471471
let pats = fields.into_iter().map(|f| {
472472
let name = name_generator.for_type(&f.ty(db), db, edition);
473473
match name {

crates/ide-assists/src/handlers/add_turbo_fish.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
141141
|builder| {
142142
builder.trigger_parameter_hints();
143143

144-
let make = SyntaxFactory::new();
144+
let make = SyntaxFactory::with_mappings();
145145
let mut editor = match &turbofish_target {
146146
Either::Left(it) => builder.make_editor(it.syntax()),
147147
Either::Right(it) => builder.make_editor(it.syntax()),

crates/ide-assists/src/handlers/apply_demorgan.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub(crate) fn apply_demorgan(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
6464
_ => return None,
6565
};
6666

67-
let make = SyntaxFactory::new();
67+
let make = SyntaxFactory::with_mappings();
6868

6969
let demorganed = bin_expr.clone_subtree();
7070
let mut editor = SyntaxEditor::new(demorganed.syntax().clone());
@@ -111,7 +111,7 @@ pub(crate) fn apply_demorgan(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
111111
"Apply De Morgan's law",
112112
op_range,
113113
|builder| {
114-
let make = SyntaxFactory::new();
114+
let make = SyntaxFactory::with_mappings();
115115
let paren_expr = bin_expr.syntax().parent().and_then(ast::ParenExpr::cast);
116116
let neg_expr = paren_expr
117117
.clone()
@@ -194,7 +194,7 @@ pub(crate) fn apply_demorgan_iterator(acc: &mut Assists, ctx: &AssistContext<'_>
194194
label,
195195
op_range,
196196
|builder| {
197-
let make = SyntaxFactory::new();
197+
let make = SyntaxFactory::with_mappings();
198198
let mut editor = builder.make_editor(method_call.syntax());
199199
// replace the method name
200200
let new_name = match name.text().as_str() {

crates/ide-assists/src/handlers/convert_bool_then.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub(crate) fn convert_if_to_bool_then(acc: &mut Assists, ctx: &AssistContext<'_>
9898
let closure_body = ast::Expr::cast(edit.new_root().clone()).unwrap();
9999

100100
let mut editor = builder.make_editor(expr.syntax());
101-
let make = SyntaxFactory::new();
101+
let make = SyntaxFactory::with_mappings();
102102
let closure_body = match closure_body {
103103
ast::Expr::BlockExpr(block) => unwrap_trivial_block(block),
104104
e => e,
@@ -216,7 +216,7 @@ pub(crate) fn convert_bool_then_to_if(acc: &mut Assists, ctx: &AssistContext<'_>
216216
let closure_body = ast::BlockExpr::cast(edit.new_root().clone()).unwrap();
217217

218218
let mut editor = builder.make_editor(mcall.syntax());
219-
let make = SyntaxFactory::new();
219+
let make = SyntaxFactory::with_mappings();
220220

221221
let cond = match &receiver {
222222
ast::Expr::ParenExpr(expr) => expr.expr().unwrap_or(receiver),

0 commit comments

Comments
 (0)