Skip to content
Permalink
Browse files

review comment: do not rely on path str to identify std::clone::Clone

  • Loading branch information...
estebank committed Jun 14, 2019
1 parent ae8d6a8 commit 34c4117f5f28c8eb8dd61600df1611fd29c8b66e
Showing with 10 additions and 6 deletions.
  1. +10 −6 src/librustc_typeck/check/demand.rs
@@ -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.
You can’t perform that action at this time.