diff options
| author | Michael Goulet <michael@errs.io> | 2024-07-26 13:56:02 -0400 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2024-07-26 13:56:06 -0400 |
| commit | e7eae5370e304fb1534c1964852a6c127f1f09f8 (patch) | |
| tree | 95cbfb8db4c879791a4e7eda6c2b31b42d7eb826 /compiler/rustc_borrowck | |
| parent | 2d5a628a1de1d38318909a710ef37da6251e362e (diff) | |
| download | rust-e7eae5370e304fb1534c1964852a6c127f1f09f8.tar.gz rust-e7eae5370e304fb1534c1964852a6c127f1f09f8.zip | |
Remove logic to suggest clone of function output
Diffstat (limited to 'compiler/rustc_borrowck')
| -rw-r--r-- | compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs | 31 |
1 files changed, 0 insertions, 31 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 2d9bc45ebc8..a5635344b4a 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -1306,37 +1306,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { // result of `foo(...)` won't help. break 'outer; } - - // We're suggesting `.clone()` on an borrowed value. See if the expression we have - // is an argument to a function or method call, and try to suggest cloning the - // *result* of the call, instead of the argument. This is closest to what people - // would actually be looking for in most cases, with maybe the exception of things - // like `fn(T) -> T`, but even then it is reasonable. - let typeck_results = self.infcx.tcx.typeck(self.mir_def_id()); - let mut prev = expr; - while let hir::Node::Expr(parent) = self.infcx.tcx.parent_hir_node(prev.hir_id) { - if let hir::ExprKind::Call(..) | hir::ExprKind::MethodCall(..) = parent.kind - && let Some(call_ty) = typeck_results.node_type_opt(parent.hir_id) - && let call_ty = call_ty.peel_refs() - && (!call_ty - .walk() - .any(|t| matches!(t.unpack(), ty::GenericArgKind::Lifetime(_))) - || if let ty::Alias(ty::Projection, _) = call_ty.kind() { - // FIXME: this isn't quite right with lifetimes on assoc types, - // but ignore for now. We will only suggest cloning if - // `<Ty as Trait>::Assoc: Clone`, which should keep false positives - // down to a managable ammount. - true - } else { - false - }) - && self.implements_clone(call_ty) - && self.suggest_cloning_inner(err, call_ty, parent) - { - return; - } - prev = parent; - } } } let ty = ty.peel_refs(); |
