about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2024-11-01 19:00:05 +0000
committerEsteban Küber <esteban@kuber.com.ar>2025-07-01 21:49:56 +0000
commitbb74f4732739d41bfca4e0689a3f00dda0439c4d (patch)
treefb8c8cd8fecd7dbcdbab8a576612b909279944d6 /compiler/rustc_trait_selection/src
parent076a0a26fd6f4c445647a33d6daaac56f732ac05 (diff)
downloadrust-bb74f4732739d41bfca4e0689a3f00dda0439c4d.tar.gz
rust-bb74f4732739d41bfca4e0689a3f00dda0439c4d.zip
Do not suggest borrow that is already there in fully-qualified call
When encountering `&str::from("value")` do not suggest `&&str::from("value")`.

Fix #132041.
Diffstat (limited to 'compiler/rustc_trait_selection/src')
-rw-r--r--compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs
index 2bbf90ed3ed..a81f7574c5e 100644
--- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs
+++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs
@@ -1195,6 +1195,15 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
             c @ ObligationCauseCode::WhereClauseInExpr(_, _, hir_id, _)
                 if self.tcx.hir_span(*hir_id).lo() == span.lo() =>
             {
+                if let hir::Node::Expr(expr) = self.tcx.parent_hir_node(*hir_id)
+                    && let hir::ExprKind::Call(base, _) = expr.kind
+                    && let hir::ExprKind::Path(hir::QPath::TypeRelative(ty, _)) = base.kind
+                    && ty.span == span
+                {
+                    // Do not suggest borrowing when we already do so. This would happen with
+                    // `let _ = &str::from("");` where the expression corresponds to the `str`.
+                    return false;
+                }
                 c
             }
             c if matches!(