From 98e889a86333d3607c190ab4a64983814f938101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 30 Jul 2026 20:36:12 +0000 Subject: [PATCH] Always use short ty path for call with missing arguments suggestion Mitigate having too long of a suggestion when there are many arguments missing by not printing the full path of the expected types. ``` error[E0061]: this function takes 5 arguments but 0 arguments were supplied --> $DIR/verbose-suggestion-for-missing-fn-args.rs:5:5 | LL | my_very_long_function_name_with_lots_of_args(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-- multiple arguments are missing | note: function defined here --> $DIR/verbose-suggestion-for-missing-fn-args.rs:8:4 | LL | fn my_very_long_function_name_with_lots_of_args( | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ LL | _first_long_param: bool, | ----------------------- LL | _second_long_param: HashMap, Vec>>, | -------------------------------------------------------------- LL | _third_long_param: usize, | ------------------------ LL | _fourth_long_param: String, | -------------------------- LL | _fifth_long_param: Mutex>>>, | ------------------------------------------------------- help: provide the arguments | LL | my_very_long_function_name_with_lots_of_args(/* bool */, /* HashMap, Vec>> */, /* usize */, /* String */, /* Mutex>>> */); | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ``` --- .../rustc_hir_typeck/src/fn_ctxt/checks.rs | 3 +- .../display-is-suggestable.stderr | 4 +-- ...-closure-call-recovery-issue-157951.stderr | 4 +-- .../verbose-suggestion-for-missing-fn-args.rs | 15 ++++++++++ ...bose-suggestion-for-missing-fn-args.stderr | 29 +++++++++++++++++++ 5 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 tests/ui/type/verbose-suggestion-for-missing-fn-args.rs create mode 100644 tests/ui/type/verbose-suggestion-for-missing-fn-args.stderr diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 9d300a86f9e12..b25a904d240af 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -18,6 +18,7 @@ use rustc_index::IndexVec; use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes, InferOk, TypeTrace}; use rustc_middle::ty::adjustment::AllowTwoPhase; use rustc_middle::ty::error::TypeError; +use rustc_middle::ty::print::with_forced_trimmed_paths; use rustc_middle::ty::{self, IsSuggestable, Ty, TyCtxt, TypeVisitableExt, Unnormalized}; use rustc_middle::{bug, span_bug}; use rustc_session::Session; @@ -3489,7 +3490,7 @@ impl<'a, 'tcx> CallCtxt<'a, 'tcx> { if ty.is_unit() { "()".to_string() } else if ty.is_suggestable(self.tcx, false) { - format!("/* {ty} */") + with_forced_trimmed_paths!(format!("/* {ty} */")) } else if let Some(fn_def_id) = self.fn_def_id && self.tcx.def_kind(fn_def_id).is_fn_like() && let self_implicit = diff --git a/tests/ui/argument-suggestions/display-is-suggestable.stderr b/tests/ui/argument-suggestions/display-is-suggestable.stderr index 921cc12333870..ece65b59a67db 100644 --- a/tests/ui/argument-suggestions/display-is-suggestable.stderr +++ b/tests/ui/argument-suggestions/display-is-suggestable.stderr @@ -11,8 +11,8 @@ LL | fn foo(x: &(dyn Display + Send)) {} | ^^^ ------------------------ help: provide the argument | -LL | foo(/* &dyn std::fmt::Display + Send */); - | +++++++++++++++++++++++++++++++++++ +LL | foo(/* &dyn Display + Send */); + | +++++++++++++++++++++++++ error: aborting due to 1 previous error diff --git a/tests/ui/traits/next-solver/deferred-closure-call-recovery-issue-157951.stderr b/tests/ui/traits/next-solver/deferred-closure-call-recovery-issue-157951.stderr index a20e5f331d31a..935830a81016f 100644 --- a/tests/ui/traits/next-solver/deferred-closure-call-recovery-issue-157951.stderr +++ b/tests/ui/traits/next-solver/deferred-closure-call-recovery-issue-157951.stderr @@ -30,8 +30,8 @@ LL | let f = |f: dyn Fn()| f; | ^^^^^^^^^^^^^ help: provide the argument | -LL | f(/* (dyn Fn() + 'static) */); - | ++++++++++++++++++++++++++ +LL | f(/* dyn Fn() */); + | ++++++++++++++ error: aborting due to 3 previous errors diff --git a/tests/ui/type/verbose-suggestion-for-missing-fn-args.rs b/tests/ui/type/verbose-suggestion-for-missing-fn-args.rs new file mode 100644 index 0000000000000..5c0f52fe8ec3f --- /dev/null +++ b/tests/ui/type/verbose-suggestion-for-missing-fn-args.rs @@ -0,0 +1,15 @@ +use std::collections::{BTreeSet, HashMap, VecDeque}; +use std::sync::{Arc, Mutex}; + +fn main() { + my_very_long_function_name_with_lots_of_args(); //~ ERROR E0061 +} + +fn my_very_long_function_name_with_lots_of_args( + _first_long_param: bool, + _second_long_param: HashMap, Vec>>, + _third_long_param: usize, + _fourth_long_param: String, + _fifth_long_param: Mutex>>>, +) { +} diff --git a/tests/ui/type/verbose-suggestion-for-missing-fn-args.stderr b/tests/ui/type/verbose-suggestion-for-missing-fn-args.stderr new file mode 100644 index 0000000000000..610d4a9e83e12 --- /dev/null +++ b/tests/ui/type/verbose-suggestion-for-missing-fn-args.stderr @@ -0,0 +1,29 @@ +error[E0061]: this function takes 5 arguments but 0 arguments were supplied + --> $DIR/verbose-suggestion-for-missing-fn-args.rs:5:5 + | +LL | my_very_long_function_name_with_lots_of_args(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-- multiple arguments are missing + | +note: function defined here + --> $DIR/verbose-suggestion-for-missing-fn-args.rs:8:4 + | +LL | fn my_very_long_function_name_with_lots_of_args( + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | _first_long_param: bool, + | ----------------------- +LL | _second_long_param: HashMap, Vec>>, + | -------------------------------------------------------------- +LL | _third_long_param: usize, + | ------------------------ +LL | _fourth_long_param: String, + | -------------------------- +LL | _fifth_long_param: Mutex>>>, + | ------------------------------------------------------- +help: provide the arguments + | +LL | my_very_long_function_name_with_lots_of_args(/* bool */, /* HashMap, Vec>> */, /* usize */, /* String */, /* Mutex>>> */); + | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0061`.