about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2023-01-08 01:53:39 +0000
committerEsteban Küber <esteban@kuber.com.ar>2023-01-08 01:53:39 +0000
commitebbc5dafd351551bdeab3e4edbdf9a03898a9017 (patch)
tree139a5e436e25b35cdfcc2c402acb7f8854ad32c9
parentd85d38b7b8ad9faa12231bbcc9a0214410c0719c (diff)
downloadrust-ebbc5dafd351551bdeab3e4edbdf9a03898a9017.tar.gz
rust-ebbc5dafd351551bdeab3e4edbdf9a03898a9017.zip
Do not emit wrong E0308 suggestion for closure mismatch
-rw-r--r--compiler/rustc_hir_typeck/src/demand.rs5
-rw-r--r--src/test/ui/type/closure-with-wrong-borrows.stderr4
2 files changed, 4 insertions, 5 deletions
diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs
index 0f191c21a0a..f15cf5e3ef9 100644
--- a/compiler/rustc_hir_typeck/src/demand.rs
+++ b/compiler/rustc_hir_typeck/src/demand.rs
@@ -1379,7 +1379,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                         }
                     }
                     // If we've reached our target type with just removing `&`, then just print now.
-                    if steps == 0 {
+                    if steps == 0 && !remove.trim().is_empty() {
                         return Some((
                             prefix_span,
                             format!("consider removing the `{}`", remove.trim()),
@@ -1438,6 +1438,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                         } else {
                             (prefix_span, format!("{}{}", prefix, "*".repeat(steps)))
                         };
+                        if suggestion.trim().is_empty() {
+                            return None;
+                        }
 
                         return Some((
                             span,
diff --git a/src/test/ui/type/closure-with-wrong-borrows.stderr b/src/test/ui/type/closure-with-wrong-borrows.stderr
index e13db6c325a..7370bc76467 100644
--- a/src/test/ui/type/closure-with-wrong-borrows.stderr
+++ b/src/test/ui/type/closure-with-wrong-borrows.stderr
@@ -13,10 +13,6 @@ note: function defined here
    |
 LL | fn f(inner: fn(&str, &S)) {
    |    ^ -------------------
-help: consider removing the ``
-   |
-LL |     f(inner);
-   |
 
 error: aborting due to previous error