-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Quantumplation
wants to merge
21
commits into
rust-lang:master
from
Quantumplation:65853/param-heuristics
Closed
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
acd679c
Initial implementation for 65853
Quantumplation c266c4c
Adds some basic test cases
Quantumplation 7fc8e3c
Rust cleanup
Quantumplation 5bf45b3
Prevent an ICE on empty params
Quantumplation f1916fa
Interpolate correct types into error messages
Quantumplation ae3c859
Fix a comment typo
Quantumplation 93ee0af
Small tweaks / typos fixed from code review
Quantumplation f369af6
Add a ton of test cases, refine error messages
Quantumplation 74faf96
Refactor final_arg_types to use a presized array
Quantumplation d455267
Remove an if clause that wasn't neccesary
Quantumplation d570d59
Make the fn_name more nuanced
Quantumplation 6eb1da0
Fixed a bug related to invalid arguments
Quantumplation ddb50d3
Corrects the spans and types for the Invalid case
Quantumplation b8c651f
A fix for a &str type check, and a pass at extra span alignment
Quantumplation 28b5a1f
Add a multipart_suggestion_verbose
552583c
Give preference to latter commas
de1a6c8
Another round of improvements on spans
807f656
Refactor the check code to simplify the suggestions.
c3dea90
Add back error span labels
Quantumplation 1d6bab0
Linting and formatting fixes
Quantumplation 5267285
--bless error messages
Quantumplation File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -280,6 +280,20 @@ impl<'a> DiagnosticBuilder<'a> { | |
self | ||
} | ||
|
||
/// See [`Diagnostic::multipart_suggestion_verbose()`]. | ||
pub fn multipart_suggestion_verbose( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This too? |
||
&mut self, | ||
msg: &str, | ||
suggestion: Vec<(Span, String)>, | ||
applicability: Applicability, | ||
) -> &mut Self { | ||
if !self.0.allow_suggestions { | ||
return self; | ||
} | ||
self.0.diagnostic.multipart_suggestion_verbose(msg, suggestion, applicability); | ||
self | ||
} | ||
|
||
/// See [`Diagnostic::multipart_suggestions()`]. | ||
pub fn multipart_suggestions( | ||
&mut self, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
error[E0308]: arguments to this function are incorrect | ||
--> $DIR/basic.rs:20:5 | ||
| | ||
LL | invalid(1.0); | ||
| ^^^^^^^^---^ | ||
| | | ||
| expected `u32`, found `{float}` | ||
| | ||
note: function defined here | ||
--> $DIR/basic.rs:13:4 | ||
| | ||
LL | fn invalid(_i: u32) {} | ||
| ^^^^^^^ ------- | ||
help: provide an argument of the correct type | ||
| | ||
LL | invalid({u32}); | ||
| ^^^^^^^^^^^^^^ | ||
|
||
error[E0308]: arguments to this function are incorrect | ||
--> $DIR/basic.rs:21:5 | ||
| | ||
LL | extra(""); | ||
| ^^^^^^--^ | ||
| | | ||
| argument unexpected | ||
| | ||
note: function defined here | ||
--> $DIR/basic.rs:14:4 | ||
| | ||
LL | fn extra() {} | ||
| ^^^^^ | ||
help: remove the extra argument | ||
| | ||
LL | extra(); | ||
| ^^^^^^^ | ||
|
||
error[E0308]: arguments to this function are incorrect | ||
--> $DIR/basic.rs:22:5 | ||
| | ||
LL | missing(); | ||
| ^^^^^^^^^ an argument of type u32 is missing | ||
| | ||
note: function defined here | ||
--> $DIR/basic.rs:15:4 | ||
| | ||
LL | fn missing(_i: u32) {} | ||
| ^^^^^^^ ------- | ||
help: provide the argument | ||
| | ||
LL | missing({u32}); | ||
| ^^^^^^^^^^^^^^ | ||
|
||
error[E0308]: arguments to this function are incorrect | ||
--> $DIR/basic.rs:23:5 | ||
| | ||
LL | swapped("", 1); | ||
| ^^^^^^^^--^^-^ | ||
| | | | ||
| | expected `&str`,found `{integer}` | ||
| expected `u32`,found `&'static str` | ||
| | ||
note: function defined here | ||
--> $DIR/basic.rs:16:4 | ||
| | ||
LL | fn swapped(_i: u32, _s: &str) {} | ||
| ^^^^^^^ ------- -------- | ||
help: swap these arguments | ||
| | ||
LL | swapped(1, ""); | ||
| ^^^^^^^^^^^^^^ | ||
|
||
error[E0308]: arguments to this function are incorrect | ||
--> $DIR/basic.rs:24:5 | ||
| | ||
LL | permuted(Y {}, Z {}, X {}); | ||
| ^^^^^^^^^----^^----^^----^ | ||
| | | | | ||
| | | expected `Z`,found `X` | ||
| | expected `Y`,found `Z` | ||
| expected `X`,found `Y` | ||
| | ||
note: function defined here | ||
--> $DIR/basic.rs:17:4 | ||
| | ||
LL | fn permuted(_x: X, _y: Y, _z: Z) {} | ||
| ^^^^^^^^ ----- ----- ----- | ||
help: reorder these arguments | ||
| | ||
LL | permuted(X {}, Y {}, Z {}); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
error[E0308]: arguments to this function are incorrect | ||
--> $DIR/complex.rs:14:3 | ||
| | ||
LL | complex(1.0, H {}, &"", G{}, F::X2, Z {}, X {}, Y {}); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
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: did you mean | ||
| | ||
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 E0308`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( //~ ERROR arguments to this function are incorrect | ||
1, | ||
1, | ||
"" | ||
); | ||
|
||
two_arg_diff( //~ ERROR arguments to this function are incorrect | ||
1, | ||
1, | ||
"" | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you split this into a separate PR?