mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
clone_on_copy
This commit is contained in:
parent
6a2a603a8c
commit
c629ec7611
4 changed files with 33 additions and 39 deletions
|
@ -169,7 +169,6 @@ new_ret_no_self = "allow"
|
|||
## Following lints should be tackled at some point
|
||||
borrowed_box = "allow"
|
||||
borrow_deref_ref = "allow"
|
||||
clone_on_copy = "allow"
|
||||
derivable_impls = "allow"
|
||||
derived_hash_with_manual_eq = "allow"
|
||||
explicit_auto_deref = "allow"
|
||||
|
|
|
@ -369,7 +369,7 @@ impl BodySourceMap {
|
|||
}
|
||||
|
||||
pub fn label_syntax(&self, label: LabelId) -> LabelSource {
|
||||
self.label_map_back[label].clone()
|
||||
self.label_map_back[label]
|
||||
}
|
||||
|
||||
pub fn node_label(&self, node: InFile<&ast::Label>) -> Option<LabelId> {
|
||||
|
@ -378,11 +378,11 @@ impl BodySourceMap {
|
|||
}
|
||||
|
||||
pub fn field_syntax(&self, expr: ExprId) -> FieldSource {
|
||||
self.field_map_back[&expr].clone()
|
||||
self.field_map_back[&expr]
|
||||
}
|
||||
|
||||
pub fn pat_field_syntax(&self, pat: PatId) -> PatFieldSource {
|
||||
self.pat_field_map_back[&pat].clone()
|
||||
self.pat_field_map_back[&pat]
|
||||
}
|
||||
|
||||
pub fn macro_expansion_expr(&self, node: InFile<&ast::MacroExpr>) -> Option<ExprId> {
|
||||
|
|
|
@ -776,11 +776,10 @@ impl ExprCollector<'_> {
|
|||
None => self.collect_expr_opt(e.condition()),
|
||||
};
|
||||
|
||||
let break_expr =
|
||||
self.alloc_expr(Expr::Break { expr: None, label: None }, syntax_ptr.clone());
|
||||
let break_expr = self.alloc_expr(Expr::Break { expr: None, label: None }, syntax_ptr);
|
||||
let if_expr = self.alloc_expr(
|
||||
Expr::If { condition, then_branch: body, else_branch: Some(break_expr) },
|
||||
syntax_ptr.clone(),
|
||||
syntax_ptr,
|
||||
);
|
||||
self.alloc_expr(Expr::Loop { body: if_expr, label }, syntax_ptr)
|
||||
}
|
||||
|
@ -811,19 +810,19 @@ impl ExprCollector<'_> {
|
|||
return self.alloc_expr(Expr::Missing, syntax_ptr);
|
||||
};
|
||||
let head = self.collect_expr_opt(e.iterable());
|
||||
let into_iter_fn_expr = self.alloc_expr(Expr::Path(into_iter_fn), syntax_ptr.clone());
|
||||
let into_iter_fn_expr = self.alloc_expr(Expr::Path(into_iter_fn), syntax_ptr);
|
||||
let iterator = self.alloc_expr(
|
||||
Expr::Call {
|
||||
callee: into_iter_fn_expr,
|
||||
args: Box::new([head]),
|
||||
is_assignee_expr: false,
|
||||
},
|
||||
syntax_ptr.clone(),
|
||||
syntax_ptr,
|
||||
);
|
||||
let none_arm = MatchArm {
|
||||
pat: self.alloc_pat_desugared(Pat::Path(Box::new(option_none))),
|
||||
guard: None,
|
||||
expr: self.alloc_expr(Expr::Break { expr: None, label: None }, syntax_ptr.clone()),
|
||||
expr: self.alloc_expr(Expr::Break { expr: None, label: None }, syntax_ptr),
|
||||
};
|
||||
let some_pat = Pat::TupleStruct {
|
||||
path: Some(Box::new(option_some)),
|
||||
|
@ -839,27 +838,25 @@ impl ExprCollector<'_> {
|
|||
}),
|
||||
};
|
||||
let iter_name = Name::generate_new_name();
|
||||
let iter_expr =
|
||||
self.alloc_expr(Expr::Path(Path::from(iter_name.clone())), syntax_ptr.clone());
|
||||
let iter_expr = self.alloc_expr(Expr::Path(Path::from(iter_name.clone())), syntax_ptr);
|
||||
let iter_expr_mut = self.alloc_expr(
|
||||
Expr::Ref { expr: iter_expr, rawness: Rawness::Ref, mutability: Mutability::Mut },
|
||||
syntax_ptr.clone(),
|
||||
syntax_ptr,
|
||||
);
|
||||
let iter_next_fn_expr = self.alloc_expr(Expr::Path(iter_next_fn), syntax_ptr.clone());
|
||||
let iter_next_fn_expr = self.alloc_expr(Expr::Path(iter_next_fn), syntax_ptr);
|
||||
let iter_next_expr = self.alloc_expr(
|
||||
Expr::Call {
|
||||
callee: iter_next_fn_expr,
|
||||
args: Box::new([iter_expr_mut]),
|
||||
is_assignee_expr: false,
|
||||
},
|
||||
syntax_ptr.clone(),
|
||||
syntax_ptr,
|
||||
);
|
||||
let loop_inner = self.alloc_expr(
|
||||
Expr::Match { expr: iter_next_expr, arms: Box::new([none_arm, some_arm]) },
|
||||
syntax_ptr.clone(),
|
||||
syntax_ptr,
|
||||
);
|
||||
let loop_outer =
|
||||
self.alloc_expr(Expr::Loop { body: loop_inner, label }, syntax_ptr.clone());
|
||||
let loop_outer = self.alloc_expr(Expr::Loop { body: loop_inner, label }, syntax_ptr);
|
||||
let iter_binding = self.alloc_binding(iter_name, BindingAnnotation::Mutable);
|
||||
let iter_pat = self.alloc_pat_desugared(Pat::Bind { id: iter_binding, subpat: None });
|
||||
self.add_definition_to_binding(iter_binding, iter_pat);
|
||||
|
@ -868,7 +865,7 @@ impl ExprCollector<'_> {
|
|||
expr: iterator,
|
||||
arms: Box::new([MatchArm { pat: iter_pat, guard: None, expr: loop_outer }]),
|
||||
},
|
||||
syntax_ptr.clone(),
|
||||
syntax_ptr,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -896,10 +893,10 @@ impl ExprCollector<'_> {
|
|||
return self.alloc_expr(Expr::Missing, syntax_ptr);
|
||||
};
|
||||
let operand = self.collect_expr_opt(e.expr());
|
||||
let try_branch = self.alloc_expr(Expr::Path(try_branch), syntax_ptr.clone());
|
||||
let try_branch = self.alloc_expr(Expr::Path(try_branch), syntax_ptr);
|
||||
let expr = self.alloc_expr(
|
||||
Expr::Call { callee: try_branch, args: Box::new([operand]), is_assignee_expr: false },
|
||||
syntax_ptr.clone(),
|
||||
syntax_ptr,
|
||||
);
|
||||
let continue_name = Name::generate_new_name();
|
||||
let continue_binding =
|
||||
|
@ -914,7 +911,7 @@ impl ExprCollector<'_> {
|
|||
ellipsis: None,
|
||||
}),
|
||||
guard: None,
|
||||
expr: self.alloc_expr(Expr::Path(Path::from(continue_name)), syntax_ptr.clone()),
|
||||
expr: self.alloc_expr(Expr::Path(Path::from(continue_name)), syntax_ptr),
|
||||
};
|
||||
let break_name = Name::generate_new_name();
|
||||
let break_binding = self.alloc_binding(break_name.clone(), BindingAnnotation::Unannotated);
|
||||
|
@ -928,18 +925,18 @@ impl ExprCollector<'_> {
|
|||
}),
|
||||
guard: None,
|
||||
expr: {
|
||||
let it = self.alloc_expr(Expr::Path(Path::from(break_name)), syntax_ptr.clone());
|
||||
let callee = self.alloc_expr(Expr::Path(try_from_residual), syntax_ptr.clone());
|
||||
let it = self.alloc_expr(Expr::Path(Path::from(break_name)), syntax_ptr);
|
||||
let callee = self.alloc_expr(Expr::Path(try_from_residual), syntax_ptr);
|
||||
let result = self.alloc_expr(
|
||||
Expr::Call { callee, args: Box::new([it]), is_assignee_expr: false },
|
||||
syntax_ptr.clone(),
|
||||
syntax_ptr,
|
||||
);
|
||||
self.alloc_expr(
|
||||
match self.current_try_block_label {
|
||||
Some(label) => Expr::Break { expr: Some(result), label: Some(label) },
|
||||
None => Expr::Return { expr: Some(result) },
|
||||
},
|
||||
syntax_ptr.clone(),
|
||||
syntax_ptr,
|
||||
)
|
||||
},
|
||||
};
|
||||
|
@ -1994,7 +1991,7 @@ impl ExprCollector<'_> {
|
|||
fn alloc_expr(&mut self, expr: Expr, ptr: ExprPtr) -> ExprId {
|
||||
let src = self.expander.in_file(ptr);
|
||||
let id = self.body.exprs.alloc(expr);
|
||||
self.source_map.expr_map_back.insert(id, src.clone());
|
||||
self.source_map.expr_map_back.insert(id, src);
|
||||
self.source_map.expr_map.insert(src, id);
|
||||
id
|
||||
}
|
||||
|
@ -2022,7 +2019,7 @@ impl ExprCollector<'_> {
|
|||
fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId {
|
||||
let src = self.expander.in_file(ptr);
|
||||
let id = self.body.pats.alloc(pat);
|
||||
self.source_map.pat_map_back.insert(id, src.clone());
|
||||
self.source_map.pat_map_back.insert(id, src);
|
||||
self.source_map.pat_map.insert(src, id);
|
||||
id
|
||||
}
|
||||
|
@ -2037,7 +2034,7 @@ impl ExprCollector<'_> {
|
|||
fn alloc_label(&mut self, label: Label, ptr: LabelPtr) -> LabelId {
|
||||
let src = self.expander.in_file(ptr);
|
||||
let id = self.body.labels.alloc(label);
|
||||
self.source_map.label_map_back.insert(id, src.clone());
|
||||
self.source_map.label_map_back.insert(id, src);
|
||||
self.source_map.label_map.insert(src, id);
|
||||
id
|
||||
}
|
||||
|
|
|
@ -1594,12 +1594,11 @@ impl DefWithBody {
|
|||
for diag in source_map.diagnostics() {
|
||||
match diag {
|
||||
BodyDiagnostic::InactiveCode { node, cfg, opts } => acc.push(
|
||||
InactiveCode { node: node.clone(), cfg: cfg.clone(), opts: opts.clone() }
|
||||
.into(),
|
||||
InactiveCode { node: *node, cfg: cfg.clone(), opts: opts.clone() }.into(),
|
||||
),
|
||||
BodyDiagnostic::MacroError { node, message } => acc.push(
|
||||
MacroError {
|
||||
node: node.clone().map(|it| it.into()),
|
||||
node: (*node).map(|it| it.into()),
|
||||
precise_location: None,
|
||||
message: message.to_string(),
|
||||
}
|
||||
|
@ -1607,7 +1606,7 @@ impl DefWithBody {
|
|||
),
|
||||
BodyDiagnostic::UnresolvedProcMacro { node, krate } => acc.push(
|
||||
UnresolvedProcMacro {
|
||||
node: node.clone().map(|it| it.into()),
|
||||
node: (*node).map(|it| it.into()),
|
||||
precise_location: None,
|
||||
macro_name: None,
|
||||
kind: MacroKind::ProcMacro,
|
||||
|
@ -1617,7 +1616,7 @@ impl DefWithBody {
|
|||
),
|
||||
BodyDiagnostic::UnresolvedMacroCall { node, path } => acc.push(
|
||||
UnresolvedMacroCall {
|
||||
macro_call: node.clone().map(|ast_ptr| ast_ptr.into()),
|
||||
macro_call: (*node).map(|ast_ptr| ast_ptr.into()),
|
||||
precise_location: None,
|
||||
path: path.clone(),
|
||||
is_bang: true,
|
||||
|
@ -1625,10 +1624,10 @@ impl DefWithBody {
|
|||
.into(),
|
||||
),
|
||||
BodyDiagnostic::UnreachableLabel { node, name } => {
|
||||
acc.push(UnreachableLabel { node: node.clone(), name: name.clone() }.into())
|
||||
acc.push(UnreachableLabel { node: *node, name: name.clone() }.into())
|
||||
}
|
||||
BodyDiagnostic::UndeclaredLabel { node, name } => {
|
||||
acc.push(UndeclaredLabel { node: node.clone(), name: name.clone() }.into())
|
||||
acc.push(UndeclaredLabel { node: *node, name: name.clone() }.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1715,7 +1714,7 @@ impl DefWithBody {
|
|||
field_with_same_name: field_with_same_name
|
||||
.clone()
|
||||
.map(|ty| Type::new(db, DefWithBodyId::from(self), ty)),
|
||||
assoc_func_with_same_name: assoc_func_with_same_name.clone(),
|
||||
assoc_func_with_same_name: *assoc_func_with_same_name,
|
||||
}
|
||||
.into(),
|
||||
)
|
||||
|
@ -1931,8 +1930,7 @@ impl DefWithBody {
|
|||
},
|
||||
Either::Right(record_pat) => match source_map.pat_syntax(record_pat) {
|
||||
Ok(source_ptr) => {
|
||||
if let Some(ptr) = source_ptr.value.clone().cast::<ast::RecordPat>()
|
||||
{
|
||||
if let Some(ptr) = source_ptr.value.cast::<ast::RecordPat>() {
|
||||
let root = source_ptr.file_syntax(db.upcast());
|
||||
let record_pat = ptr.to_node(&root);
|
||||
if record_pat.record_pat_field_list().is_some() {
|
||||
|
|
Loading…
Reference in a new issue