Skip to content

Commit c629ec7

Browse files
committed
clone_on_copy
1 parent 6a2a603 commit c629ec7

File tree

4 files changed

+33
-39
lines changed

4 files changed

+33
-39
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ new_ret_no_self = "allow"
169169
## Following lints should be tackled at some point
170170
borrowed_box = "allow"
171171
borrow_deref_ref = "allow"
172-
clone_on_copy = "allow"
173172
derivable_impls = "allow"
174173
derived_hash_with_manual_eq = "allow"
175174
explicit_auto_deref = "allow"

crates/hir-def/src/body.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ impl BodySourceMap {
369369
}
370370

371371
pub fn label_syntax(&self, label: LabelId) -> LabelSource {
372-
self.label_map_back[label].clone()
372+
self.label_map_back[label]
373373
}
374374

375375
pub fn node_label(&self, node: InFile<&ast::Label>) -> Option<LabelId> {
@@ -378,11 +378,11 @@ impl BodySourceMap {
378378
}
379379

380380
pub fn field_syntax(&self, expr: ExprId) -> FieldSource {
381-
self.field_map_back[&expr].clone()
381+
self.field_map_back[&expr]
382382
}
383383

384384
pub fn pat_field_syntax(&self, pat: PatId) -> PatFieldSource {
385-
self.pat_field_map_back[&pat].clone()
385+
self.pat_field_map_back[&pat]
386386
}
387387

388388
pub fn macro_expansion_expr(&self, node: InFile<&ast::MacroExpr>) -> Option<ExprId> {

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

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -776,11 +776,10 @@ impl ExprCollector<'_> {
776776
None => self.collect_expr_opt(e.condition()),
777777
};
778778

779-
let break_expr =
780-
self.alloc_expr(Expr::Break { expr: None, label: None }, syntax_ptr.clone());
779+
let break_expr = self.alloc_expr(Expr::Break { expr: None, label: None }, syntax_ptr);
781780
let if_expr = self.alloc_expr(
782781
Expr::If { condition, then_branch: body, else_branch: Some(break_expr) },
783-
syntax_ptr.clone(),
782+
syntax_ptr,
784783
);
785784
self.alloc_expr(Expr::Loop { body: if_expr, label }, syntax_ptr)
786785
}
@@ -811,19 +810,19 @@ impl ExprCollector<'_> {
811810
return self.alloc_expr(Expr::Missing, syntax_ptr);
812811
};
813812
let head = self.collect_expr_opt(e.iterable());
814-
let into_iter_fn_expr = self.alloc_expr(Expr::Path(into_iter_fn), syntax_ptr.clone());
813+
let into_iter_fn_expr = self.alloc_expr(Expr::Path(into_iter_fn), syntax_ptr);
815814
let iterator = self.alloc_expr(
816815
Expr::Call {
817816
callee: into_iter_fn_expr,
818817
args: Box::new([head]),
819818
is_assignee_expr: false,
820819
},
821-
syntax_ptr.clone(),
820+
syntax_ptr,
822821
);
823822
let none_arm = MatchArm {
824823
pat: self.alloc_pat_desugared(Pat::Path(Box::new(option_none))),
825824
guard: None,
826-
expr: self.alloc_expr(Expr::Break { expr: None, label: None }, syntax_ptr.clone()),
825+
expr: self.alloc_expr(Expr::Break { expr: None, label: None }, syntax_ptr),
827826
};
828827
let some_pat = Pat::TupleStruct {
829828
path: Some(Box::new(option_some)),
@@ -839,27 +838,25 @@ impl ExprCollector<'_> {
839838
}),
840839
};
841840
let iter_name = Name::generate_new_name();
842-
let iter_expr =
843-
self.alloc_expr(Expr::Path(Path::from(iter_name.clone())), syntax_ptr.clone());
841+
let iter_expr = self.alloc_expr(Expr::Path(Path::from(iter_name.clone())), syntax_ptr);
844842
let iter_expr_mut = self.alloc_expr(
845843
Expr::Ref { expr: iter_expr, rawness: Rawness::Ref, mutability: Mutability::Mut },
846-
syntax_ptr.clone(),
844+
syntax_ptr,
847845
);
848-
let iter_next_fn_expr = self.alloc_expr(Expr::Path(iter_next_fn), syntax_ptr.clone());
846+
let iter_next_fn_expr = self.alloc_expr(Expr::Path(iter_next_fn), syntax_ptr);
849847
let iter_next_expr = self.alloc_expr(
850848
Expr::Call {
851849
callee: iter_next_fn_expr,
852850
args: Box::new([iter_expr_mut]),
853851
is_assignee_expr: false,
854852
},
855-
syntax_ptr.clone(),
853+
syntax_ptr,
856854
);
857855
let loop_inner = self.alloc_expr(
858856
Expr::Match { expr: iter_next_expr, arms: Box::new([none_arm, some_arm]) },
859-
syntax_ptr.clone(),
857+
syntax_ptr,
860858
);
861-
let loop_outer =
862-
self.alloc_expr(Expr::Loop { body: loop_inner, label }, syntax_ptr.clone());
859+
let loop_outer = self.alloc_expr(Expr::Loop { body: loop_inner, label }, syntax_ptr);
863860
let iter_binding = self.alloc_binding(iter_name, BindingAnnotation::Mutable);
864861
let iter_pat = self.alloc_pat_desugared(Pat::Bind { id: iter_binding, subpat: None });
865862
self.add_definition_to_binding(iter_binding, iter_pat);
@@ -868,7 +865,7 @@ impl ExprCollector<'_> {
868865
expr: iterator,
869866
arms: Box::new([MatchArm { pat: iter_pat, guard: None, expr: loop_outer }]),
870867
},
871-
syntax_ptr.clone(),
868+
syntax_ptr,
872869
)
873870
}
874871

@@ -896,10 +893,10 @@ impl ExprCollector<'_> {
896893
return self.alloc_expr(Expr::Missing, syntax_ptr);
897894
};
898895
let operand = self.collect_expr_opt(e.expr());
899-
let try_branch = self.alloc_expr(Expr::Path(try_branch), syntax_ptr.clone());
896+
let try_branch = self.alloc_expr(Expr::Path(try_branch), syntax_ptr);
900897
let expr = self.alloc_expr(
901898
Expr::Call { callee: try_branch, args: Box::new([operand]), is_assignee_expr: false },
902-
syntax_ptr.clone(),
899+
syntax_ptr,
903900
);
904901
let continue_name = Name::generate_new_name();
905902
let continue_binding =
@@ -914,7 +911,7 @@ impl ExprCollector<'_> {
914911
ellipsis: None,
915912
}),
916913
guard: None,
917-
expr: self.alloc_expr(Expr::Path(Path::from(continue_name)), syntax_ptr.clone()),
914+
expr: self.alloc_expr(Expr::Path(Path::from(continue_name)), syntax_ptr),
918915
};
919916
let break_name = Name::generate_new_name();
920917
let break_binding = self.alloc_binding(break_name.clone(), BindingAnnotation::Unannotated);
@@ -928,18 +925,18 @@ impl ExprCollector<'_> {
928925
}),
929926
guard: None,
930927
expr: {
931-
let it = self.alloc_expr(Expr::Path(Path::from(break_name)), syntax_ptr.clone());
932-
let callee = self.alloc_expr(Expr::Path(try_from_residual), syntax_ptr.clone());
928+
let it = self.alloc_expr(Expr::Path(Path::from(break_name)), syntax_ptr);
929+
let callee = self.alloc_expr(Expr::Path(try_from_residual), syntax_ptr);
933930
let result = self.alloc_expr(
934931
Expr::Call { callee, args: Box::new([it]), is_assignee_expr: false },
935-
syntax_ptr.clone(),
932+
syntax_ptr,
936933
);
937934
self.alloc_expr(
938935
match self.current_try_block_label {
939936
Some(label) => Expr::Break { expr: Some(result), label: Some(label) },
940937
None => Expr::Return { expr: Some(result) },
941938
},
942-
syntax_ptr.clone(),
939+
syntax_ptr,
943940
)
944941
},
945942
};
@@ -1994,7 +1991,7 @@ impl ExprCollector<'_> {
19941991
fn alloc_expr(&mut self, expr: Expr, ptr: ExprPtr) -> ExprId {
19951992
let src = self.expander.in_file(ptr);
19961993
let id = self.body.exprs.alloc(expr);
1997-
self.source_map.expr_map_back.insert(id, src.clone());
1994+
self.source_map.expr_map_back.insert(id, src);
19981995
self.source_map.expr_map.insert(src, id);
19991996
id
20001997
}
@@ -2022,7 +2019,7 @@ impl ExprCollector<'_> {
20222019
fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId {
20232020
let src = self.expander.in_file(ptr);
20242021
let id = self.body.pats.alloc(pat);
2025-
self.source_map.pat_map_back.insert(id, src.clone());
2022+
self.source_map.pat_map_back.insert(id, src);
20262023
self.source_map.pat_map.insert(src, id);
20272024
id
20282025
}
@@ -2037,7 +2034,7 @@ impl ExprCollector<'_> {
20372034
fn alloc_label(&mut self, label: Label, ptr: LabelPtr) -> LabelId {
20382035
let src = self.expander.in_file(ptr);
20392036
let id = self.body.labels.alloc(label);
2040-
self.source_map.label_map_back.insert(id, src.clone());
2037+
self.source_map.label_map_back.insert(id, src);
20412038
self.source_map.label_map.insert(src, id);
20422039
id
20432040
}

crates/hir/src/lib.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,20 +1594,19 @@ impl DefWithBody {
15941594
for diag in source_map.diagnostics() {
15951595
match diag {
15961596
BodyDiagnostic::InactiveCode { node, cfg, opts } => acc.push(
1597-
InactiveCode { node: node.clone(), cfg: cfg.clone(), opts: opts.clone() }
1598-
.into(),
1597+
InactiveCode { node: *node, cfg: cfg.clone(), opts: opts.clone() }.into(),
15991598
),
16001599
BodyDiagnostic::MacroError { node, message } => acc.push(
16011600
MacroError {
1602-
node: node.clone().map(|it| it.into()),
1601+
node: (*node).map(|it| it.into()),
16031602
precise_location: None,
16041603
message: message.to_string(),
16051604
}
16061605
.into(),
16071606
),
16081607
BodyDiagnostic::UnresolvedProcMacro { node, krate } => acc.push(
16091608
UnresolvedProcMacro {
1610-
node: node.clone().map(|it| it.into()),
1609+
node: (*node).map(|it| it.into()),
16111610
precise_location: None,
16121611
macro_name: None,
16131612
kind: MacroKind::ProcMacro,
@@ -1617,18 +1616,18 @@ impl DefWithBody {
16171616
),
16181617
BodyDiagnostic::UnresolvedMacroCall { node, path } => acc.push(
16191618
UnresolvedMacroCall {
1620-
macro_call: node.clone().map(|ast_ptr| ast_ptr.into()),
1619+
macro_call: (*node).map(|ast_ptr| ast_ptr.into()),
16211620
precise_location: None,
16221621
path: path.clone(),
16231622
is_bang: true,
16241623
}
16251624
.into(),
16261625
),
16271626
BodyDiagnostic::UnreachableLabel { node, name } => {
1628-
acc.push(UnreachableLabel { node: node.clone(), name: name.clone() }.into())
1627+
acc.push(UnreachableLabel { node: *node, name: name.clone() }.into())
16291628
}
16301629
BodyDiagnostic::UndeclaredLabel { node, name } => {
1631-
acc.push(UndeclaredLabel { node: node.clone(), name: name.clone() }.into())
1630+
acc.push(UndeclaredLabel { node: *node, name: name.clone() }.into())
16321631
}
16331632
}
16341633
}
@@ -1715,7 +1714,7 @@ impl DefWithBody {
17151714
field_with_same_name: field_with_same_name
17161715
.clone()
17171716
.map(|ty| Type::new(db, DefWithBodyId::from(self), ty)),
1718-
assoc_func_with_same_name: assoc_func_with_same_name.clone(),
1717+
assoc_func_with_same_name: *assoc_func_with_same_name,
17191718
}
17201719
.into(),
17211720
)
@@ -1931,8 +1930,7 @@ impl DefWithBody {
19311930
},
19321931
Either::Right(record_pat) => match source_map.pat_syntax(record_pat) {
19331932
Ok(source_ptr) => {
1934-
if let Some(ptr) = source_ptr.value.clone().cast::<ast::RecordPat>()
1935-
{
1933+
if let Some(ptr) = source_ptr.value.cast::<ast::RecordPat>() {
19361934
let root = source_ptr.file_syntax(db.upcast());
19371935
let record_pat = ptr.to_node(&root);
19381936
if record_pat.record_pat_field_list().is_some() {

0 commit comments

Comments
 (0)