Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better method call error messages #71827

Closed
Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ty
}

fn check_expr_kind(
pub(super) fn check_expr_kind(
&self,
expr: &'tcx hir::Expr<'tcx>,
expected: Expectation<'tcx>,
Expand Down
1,028 changes: 787 additions & 241 deletions compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions src/test/ui/argument-suggestions/basic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Some basic "obvious" cases for the heuristic error messages added for #65853
// One for each of the detected cases

enum E { X, Y }
enum F { X2, Y2 }
struct G {}
struct H {}
struct X {}
struct Y {}
struct Z {}


fn invalid(_i: u32) {}
fn extra() {}
fn missing(_i: u32) {}
fn swapped(_i: u32, _s: &str) {}
fn permuted(_x: X, _y: Y, _z: Z) {}

fn main() {
invalid(1.0); //~ ERROR arguments to this function are incorrect
extra(""); //~ ERROR arguments to this function are incorrect
missing(); //~ ERROR arguments to this function are incorrect
swapped("", 1); //~ ERROR arguments to this function are incorrect
permuted(Y {}, Z {}, X {}); //~ ERROR arguments to this function are incorrect
}
87 changes: 87 additions & 0 deletions src/test/ui/argument-suggestions/basic.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
error[E0059]: arguments to this function are incorrect
--> $DIR/basic.rs:20:13
|
LL | invalid(1.0);
| ^^^ expected u32, found {float}
|
note: function defined here
--> $DIR/basic.rs:13:4
|
LL | fn invalid(_i: u32) {}
| ^^^^^^^ -------
help: provideing a parameter of the correct type here may help
|
LL | invalid({u32});
| ^^^^^

error[E0059]: arguments to this function are incorrect
--> $DIR/basic.rs:21:11
|
LL | extra("");
| ^^
| |
| this parameter of type &'static str isn't needed for extra
| help: removing this argument may help
|
note: function defined here
--> $DIR/basic.rs:14:4
|
LL | fn extra() {}
| ^^^^^

error[E0059]: arguments to this function are incorrect
--> $DIR/basic.rs:22:13
|
LL | missing();
| ^ missing argument of type u32
|
note: function defined here
--> $DIR/basic.rs:15:4
|
LL | fn missing(_i: u32) {}
| ^^^^^^^ -------
help: provideing a parameter of the correct type here may help
|
LL | missing( {u32},);
| ^^^^^^

error[E0059]: arguments to this function are incorrect
--> $DIR/basic.rs:23:13
|
LL | swapped("", 1);
| ^^ ^ expected &str, found &str
| |
| expected u32, found u32
|
note: function defined here
--> $DIR/basic.rs:16:4
|
LL | fn swapped(_i: u32, _s: &str) {}
| ^^^^^^^ ------- --------
help: swapping these two arguments might help
|
LL | swapped(1, "");
| ^ ^^

error[E0059]: arguments to this function are incorrect
--> $DIR/basic.rs:24:14
|
LL | permuted(Y {}, Z {}, X {});
| ^^^^ ^^^^ ^^^^ expected Z, found Z
| | |
| | expected Y, found Y
| expected X, found X
|
note: function defined here
--> $DIR/basic.rs:17:4
|
LL | fn permuted(_x: X, _y: Y, _z: Z) {}
| ^^^^^^^^ ----- ----- -----
help: reordering these parameters might help
|
LL | permuted(X {}, Y {}, Z {});
| ^^^^ ^^^^ ^^^^

error: aborting due to 5 previous errors

For more information about this error, try `rustc --explain E0059`.
16 changes: 16 additions & 0 deletions src/test/ui/argument-suggestions/complex.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// A complex case with mixed suggestions from #65853

enum E { X, Y }
enum F { X2, Y2 }
struct G {}
struct H {}
struct X {}
struct Y {}
struct Z {}

fn complex(_i: u32, _s: &str, _e: E, _f: F, _g: G, _x: X, _y: Y, _z: Z ) {}

fn main() {
complex(1.0, H {}, &"", G{}, F::X2, Z {}, X {}, Y {});
//~^ ERROR arguments to this function are incorrect
}
27 changes: 27 additions & 0 deletions src/test/ui/argument-suggestions/complex.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
error[E0059]: multiple arguments to this function are incorrect
--> $DIR/complex.rs:14:11
|
LL | complex(1.0, H {}, &"", G{}, F::X2, Z {}, X {}, Y {});
| ^^^ ^^^^ ^^^^ ^^^^^ ^^^^ ^^^^ ^^^^ expected Z, found Z
| | | || | | |
| | | || | | expected Y, found Y
| | | || | expected X, found X
| | | || expected G, found G
| | | |expected F, found F
| | | missing argument of type E
| | this parameter of type H isn't needed for complex
| expected u32, found {float}
|
note: function defined here
--> $DIR/complex.rs:11:4
|
LL | fn complex(_i: u32, _s: &str, _e: E, _f: F, _g: G, _x: X, _y: Y, _z: Z ) {}
| ^^^^^^^ ------- -------- ----- ----- ----- ----- ----- ------
help: the following changes might help
|
LL | complex({u32}, &"", {E}, F::X2, G{}, X {}, Y {}, Z {});
| ^^--^ ^^^^ ^^^^^ ^^^ ^^^^ ^^^^ ^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0059`.
35 changes: 35 additions & 0 deletions src/test/ui/argument-suggestions/extra_arguments.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
fn empty() {}
fn one_arg(_a: i32) {}
fn two_arg_same(_a: i32, _b: i32) {}
fn two_arg_diff(_a: i32, _b: &str) {}

fn main() {
empty(""); //~ ERROR arguments to this function are incorrect

one_arg(1, 1); //~ ERROR arguments to this function are incorrect
one_arg(1, ""); //~ ERROR arguments to this function are incorrect
one_arg(1, "", 1.0); //~ ERROR arguments to this function are incorrect

two_arg_same(1, 1, 1); //~ ERROR arguments to this function are incorrect
two_arg_same(1, 1, 1.0); //~ ERROR arguments to this function are incorrect

two_arg_diff(1, 1, ""); //~ ERROR arguments to this function are incorrect
two_arg_diff(1, "", ""); //~ ERROR arguments to this function are incorrect
two_arg_diff(1, 1, "", ""); //~ ERROR arguments to this function are incorrect
two_arg_diff(1, "", 1, ""); //~ ERROR arguments to this function are incorrect

// Check with weird spacing and newlines
two_arg_same(1, 1, ""); //~ ERROR arguments to this function are incorrect
two_arg_diff(1, 1, ""); //~ ERROR arguments to this function are incorrect
two_arg_same(
1,
1,
"" //~ ERROR arguments to this function are incorrect
);

two_arg_diff(
1,
1, //~ ERROR arguments to this function are incorrect
""
);
}
Loading