about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2023-11-09 01:23:10 +0000
committerEsteban Küber <esteban@kuber.com.ar>2023-11-19 17:50:47 +0000
commit4d16171f563761e19798c220ee415f84d62df26c (patch)
treed71983824f03aa3a9bdd96ee858ef44bd784358e /compiler
parent00265f0cc0e963f83d76b3c43c9d41e839522778 (diff)
downloadrust-4d16171f563761e19798c220ee415f84d62df26c.tar.gz
rust-4d16171f563761e19798c220ee415f84d62df26c.zip
Account for number of arguments in suggestion
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_resolve/src/late/diagnostics.rs29
1 files changed, 24 insertions, 5 deletions
diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs
index a0b0abd6555..b0bb9a383db 100644
--- a/compiler/rustc_resolve/src/late/diagnostics.rs
+++ b/compiler/rustc_resolve/src/late/diagnostics.rs
@@ -1762,16 +1762,16 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
                     } else {
                         3
                     };
-                    Some((order, item.name))
+                    Some((order, item.name, input_len))
                 } else {
                     None
                 }
             })
             .collect::<Vec<_>>();
-        items.sort_by_key(|(order, _)| *order);
+        items.sort_by_key(|(order, _, _)| *order);
         match &items[..] {
             [] => {}
-            [(_, name)] => {
+            [(_, name, len)] if *len == args.len() => {
                 err.span_suggestion_verbose(
                     path_span.shrink_to_hi(),
                     format!("you might have meant to use the `{name}` associated function",),
@@ -1779,11 +1779,30 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
                     Applicability::MaybeIncorrect,
                 );
             }
+            [(_, name, len)] => {
+                err.span_suggestion_verbose(
+                    path_span.shrink_to_hi().with_hi(call_span.hi()),
+                    format!("you might have meant to use the `{name}` associated function",),
+                    format!(
+                        "::{name}({})",
+                        std::iter::repeat("_").take(*len).collect::<Vec<_>>().join(", ")
+                    ),
+                    Applicability::MaybeIncorrect,
+                );
+            }
             _ => {
                 err.span_suggestions_with_style(
-                    path_span.shrink_to_hi(),
+                    path_span.shrink_to_hi().with_hi(call_span.hi()),
                     "you might have meant to use an associated function to build this type",
-                    items.iter().map(|(_, name)| format!("::{name}")).collect::<Vec<String>>(),
+                    items
+                        .iter()
+                        .map(|(_, name, len)| {
+                            format!(
+                                "::{name}({})",
+                                std::iter::repeat("_").take(*len).collect::<Vec<_>>().join(", ")
+                            )
+                        })
+                        .collect::<Vec<String>>(),
                     Applicability::MaybeIncorrect,
                     SuggestionStyle::ShowAlways,
                 );