Skip to content

Commit 34c4117

Browse files
committed
review comment: do not rely on path str to identify std::clone::Clone
1 parent ae8d6a8 commit 34c4117

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/librustc_typeck/check/demand.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,16 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
380380
};
381381
if self.can_coerce(ref_ty, expected) {
382382
let mut sugg_sp = sp;
383-
if let hir::ExprKind::MethodCall(_segment, _sp, args) = &expr.node {
384-
let clone_path = "std::clone::Clone::clone";
385-
if let ([arg], Some(true)) = (&args[..], self.tables.borrow()
386-
.type_dependent_def_id(expr.hir_id)
387-
.map(|did| self.tcx.def_path_str(did).as_str() == clone_path))
388-
{
383+
if let hir::ExprKind::MethodCall(segment, _sp, args) = &expr.node {
384+
let clone_trait = self.tcx.lang_items().clone_trait().unwrap();
385+
if let ([arg], Some(true), "clone") = (
386+
&args[..],
387+
self.tables.borrow().type_dependent_def_id(expr.hir_id).map(|did| {
388+
let ai = self.tcx.associated_item(did);
389+
ai.container == ty::TraitContainer(clone_trait)
390+
}),
391+
&segment.ident.as_str()[..],
392+
) {
389393
// If this expression had a clone call when suggesting borrowing
390394
// we want to suggest removing it because it'd now be unecessary.
391395
sugg_sp = arg.span;

0 commit comments

Comments
 (0)