Skip to content

Commit

Permalink
review comment: do not rely on path str to identify std::clone::Clone
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Jun 14, 2019
1 parent ae8d6a8 commit 34c4117
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/librustc_typeck/check/demand.rs
Original file line number Diff line number Diff line change
@@ -380,12 +380,16 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
};
if self.can_coerce(ref_ty, expected) {
let mut sugg_sp = sp;
if let hir::ExprKind::MethodCall(_segment, _sp, args) = &expr.node {
let clone_path = "std::clone::Clone::clone";
if let ([arg], Some(true)) = (&args[..], self.tables.borrow()
.type_dependent_def_id(expr.hir_id)
.map(|did| self.tcx.def_path_str(did).as_str() == clone_path))
{
if let hir::ExprKind::MethodCall(segment, _sp, args) = &expr.node {
let clone_trait = self.tcx.lang_items().clone_trait().unwrap();
if let ([arg], Some(true), "clone") = (
&args[..],
self.tables.borrow().type_dependent_def_id(expr.hir_id).map(|did| {
let ai = self.tcx.associated_item(did);
ai.container == ty::TraitContainer(clone_trait)
}),
&segment.ident.as_str()[..],
) {
// If this expression had a clone call when suggesting borrowing
// we want to suggest removing it because it'd now be unecessary.
sugg_sp = arg.span;

0 comments on commit 34c4117

Please sign in to comment.