Skip to content

Commit 21f8e37

Browse files
Rollup merge of #160234 - estebank:issue-101242, r=oli-obk
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<Arc<String>, Vec<BTreeSet<usize>>>, | -------------------------------------------------------------- LL | _third_long_param: usize, | ------------------------ LL | _fourth_long_param: String, | -------------------------- LL | _fifth_long_param: Mutex<Option<VecDeque<Arc<String>>>>, | ------------------------------------------------------- help: provide the arguments | LL | my_very_long_function_name_with_lots_of_args(/* bool */, /* HashMap<Arc<String>, Vec<BTreeSet<usize>>> */, /* usize */, /* String */, /* Mutex<Option<VecDeque<Arc<String>>>> */); | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ``` Partially address #101242. More work is needed to close that ticket, but this is an easy stop gap.
2 parents 593e3b3 + 98e889a commit 21f8e37

5 files changed

Lines changed: 50 additions & 5 deletions

File tree

‎compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use rustc_index::IndexVec;
1818
use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes, InferOk, TypeTrace};
1919
use rustc_middle::ty::adjustment::AllowTwoPhase;
2020
use rustc_middle::ty::error::TypeError;
21+
use rustc_middle::ty::print::with_forced_trimmed_paths;
2122
use rustc_middle::ty::{self, IsSuggestable, Ty, TyCtxt, TypeVisitableExt, Unnormalized};
2223
use rustc_middle::{bug, span_bug};
2324
use rustc_session::Session;
@@ -3489,7 +3490,7 @@ impl<'a, 'tcx> CallCtxt<'a, 'tcx> {
34893490
if ty.is_unit() {
34903491
"()".to_string()
34913492
} else if ty.is_suggestable(self.tcx, false) {
3492-
format!("/* {ty} */")
3493+
with_forced_trimmed_paths!(format!("/* {ty} */"))
34933494
} else if let Some(fn_def_id) = self.fn_def_id
34943495
&& self.tcx.def_kind(fn_def_id).is_fn_like()
34953496
&& let self_implicit =

‎tests/ui/argument-suggestions/display-is-suggestable.stderr‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ LL | fn foo(x: &(dyn Display + Send)) {}
1111
| ^^^ ------------------------
1212
help: provide the argument
1313
|
14-
LL | foo(/* &dyn std::fmt::Display + Send */);
15-
| +++++++++++++++++++++++++++++++++++
14+
LL | foo(/* &dyn Display + Send */);
15+
| +++++++++++++++++++++++++
1616

1717
error: aborting due to 1 previous error
1818

‎tests/ui/traits/next-solver/deferred-closure-call-recovery-issue-157951.stderr‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ LL | let f = |f: dyn Fn()| f;
3030
| ^^^^^^^^^^^^^
3131
help: provide the argument
3232
|
33-
LL | f(/* (dyn Fn() + 'static) */);
34-
| ++++++++++++++++++++++++++
33+
LL | f(/* dyn Fn() */);
34+
| ++++++++++++++
3535

3636
error: aborting due to 3 previous errors
3737

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use std::collections::{BTreeSet, HashMap, VecDeque};
2+
use std::sync::{Arc, Mutex};
3+
4+
fn main() {
5+
my_very_long_function_name_with_lots_of_args(); //~ ERROR E0061
6+
}
7+
8+
fn my_very_long_function_name_with_lots_of_args(
9+
_first_long_param: bool,
10+
_second_long_param: HashMap<Arc<String>, Vec<BTreeSet<usize>>>,
11+
_third_long_param: usize,
12+
_fourth_long_param: String,
13+
_fifth_long_param: Mutex<Option<VecDeque<Arc<String>>>>,
14+
) {
15+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
error[E0061]: this function takes 5 arguments but 0 arguments were supplied
2+
--> $DIR/verbose-suggestion-for-missing-fn-args.rs:5:5
3+
|
4+
LL | my_very_long_function_name_with_lots_of_args();
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-- multiple arguments are missing
6+
|
7+
note: function defined here
8+
--> $DIR/verbose-suggestion-for-missing-fn-args.rs:8:4
9+
|
10+
LL | fn my_very_long_function_name_with_lots_of_args(
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
LL | _first_long_param: bool,
13+
| -----------------------
14+
LL | _second_long_param: HashMap<Arc<String>, Vec<BTreeSet<usize>>>,
15+
| --------------------------------------------------------------
16+
LL | _third_long_param: usize,
17+
| ------------------------
18+
LL | _fourth_long_param: String,
19+
| --------------------------
20+
LL | _fifth_long_param: Mutex<Option<VecDeque<Arc<String>>>>,
21+
| -------------------------------------------------------
22+
help: provide the arguments
23+
|
24+
LL | my_very_long_function_name_with_lots_of_args(/* bool */, /* HashMap<Arc<String>, Vec<BTreeSet<usize>>> */, /* usize */, /* String */, /* Mutex<Option<VecDeque<Arc<String>>>> */);
25+
| +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
26+
27+
error: aborting due to 1 previous error
28+
29+
For more information about this error, try `rustc --explain E0061`.

0 commit comments

Comments
 (0)