- 
                Notifications
    
You must be signed in to change notification settings  - Fork 13.9k
 
Better method call error messages #71827
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
          
     Closed
      
      
            Quantumplation
  wants to merge
  21
  commits into
  rust-lang:master
from
Quantumplation:65853/param-heuristics
  
      
      
   
      
    
  
     Closed
                    Changes from 8 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
Large diffs are not rendered by default.
      
      Oops, something went wrong.
      
    
  
  
    
      This file contains hidden or 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 hidden or 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,79 @@ | ||
| 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) {} | ||
| | ^^^^^^^ ------- | ||
| 
     | 
||
| error[E0059]: arguments to this function are incorrect | ||
| --> $DIR/basic.rs:21:11 | ||
| | | ||
| LL | extra(""); | ||
| | ^^ | ||
| | | | ||
| | no parameter of type &'static str is needed in 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) {} | ||
| | ^^^^^^^ ------- | ||
| 
     | 
||
| error[E0059]: arguments to this function are incorrect | ||
| --> $DIR/basic.rs:23:13 | ||
| | | ||
| 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: 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 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: 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`. | ||
  
    
      This file contains hidden or 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 hidden or 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,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 Y | ||
| | | | || | | | | ||
| | | | || | | expected Y, found X | ||
| | | | || | expected X, found Z | ||
| | | | || expected G, found F | ||
| | | | |expected F, found G | ||
| | | | missing argument of type E | ||
| | | no parameter of type H is needed in 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`. | 
  
    
      This file contains hidden or 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,20 @@ | ||
| 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 | ||
| } | 
        
          
          
            168 changes: 168 additions & 0 deletions
          
          168 
        
  src/test/ui/argument-suggestions/extra_arguments.stderr
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or 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,168 @@ | ||
| error[E0059]: arguments to this function are incorrect | ||
| --> $DIR/extra_arguments.rs:7:9 | ||
| | | ||
| LL | empty(""); | ||
| | ^^ | ||
| | | | ||
| | no parameter of type &'static str is needed in empty | ||
| | help: removing this argument may help | ||
| | | ||
| note: function defined here | ||
| --> $DIR/extra_arguments.rs:1:4 | ||
| | | ||
| LL | fn empty() {} | ||
| | ^^^^^ | ||
| 
     | 
||
| error[E0059]: arguments to this function are incorrect | ||
| --> $DIR/extra_arguments.rs:9:14 | ||
| | | ||
| LL | one_arg(1, 1); | ||
| | ^ | ||
| | | | ||
| | no parameter of type {integer} is needed in one_arg | ||
| | help: removing this argument may help | ||
| | | ||
| note: function defined here | ||
| --> $DIR/extra_arguments.rs:2:4 | ||
| | | ||
| LL | fn one_arg(_a: i32) {} | ||
| | ^^^^^^^ ------- | ||
| 
     | 
||
| error[E0059]: arguments to this function are incorrect | ||
| --> $DIR/extra_arguments.rs:10:14 | ||
| | | ||
| LL | one_arg(1, ""); | ||
| | ^^ | ||
| | | | ||
| | no parameter of type &'static str is needed in one_arg | ||
| | help: removing this argument may help | ||
| | | ||
| note: function defined here | ||
| --> $DIR/extra_arguments.rs:2:4 | ||
| | | ||
| LL | fn one_arg(_a: i32) {} | ||
| | ^^^^^^^ ------- | ||
| 
     | 
||
| error[E0059]: multiple arguments to this function are incorrect | ||
| --> $DIR/extra_arguments.rs:11:14 | ||
| | | ||
| LL | one_arg(1, "", 1.0); | ||
| | ^^ ^^^ no parameter of type {float} is needed in one_arg | ||
| | | | ||
| | no parameter of type &'static str is needed in one_arg | ||
| | | ||
| note: function defined here | ||
| --> $DIR/extra_arguments.rs:2:4 | ||
| | | ||
| LL | fn one_arg(_a: i32) {} | ||
| | ^^^^^^^ ------- | ||
| help: removing these argument may help | ||
| | | ||
| LL | one_arg(1, ); | ||
| | -- -- | ||
| 
     | 
||
| error[E0059]: arguments to this function are incorrect | ||
| --> $DIR/extra_arguments.rs:13:22 | ||
| | | ||
| LL | two_arg_same(1, 1, 1); | ||
| | ^ | ||
| | | | ||
| | no parameter of type {integer} is needed in two_arg_same | ||
| | help: removing this argument may help | ||
| | | ||
| note: function defined here | ||
| --> $DIR/extra_arguments.rs:3:4 | ||
| | | ||
| LL | fn two_arg_same(_a: i32, _b: i32) {} | ||
| | ^^^^^^^^^^^^ ------- ------- | ||
| 
     | 
||
| error[E0059]: arguments to this function are incorrect | ||
| --> $DIR/extra_arguments.rs:14:22 | ||
| | | ||
| LL | two_arg_same(1, 1, 1.0); | ||
| | ^^^ | ||
| | | | ||
| | no parameter of type {float} is needed in two_arg_same | ||
| | help: removing this argument may help | ||
| | | ||
| note: function defined here | ||
| --> $DIR/extra_arguments.rs:3:4 | ||
| | | ||
| LL | fn two_arg_same(_a: i32, _b: i32) {} | ||
| | ^^^^^^^^^^^^ ------- ------- | ||
| 
     | 
||
| error[E0059]: multiple arguments to this function are incorrect | ||
| --> $DIR/extra_arguments.rs:16:19 | ||
| | | ||
| LL | two_arg_diff(1, 1, ""); | ||
| | ^ ^^^ no parameter of type &'static str is needed in two_arg_diff | ||
| | | | | ||
| | | missing argument of type &str | ||
| | no parameter of type {integer} is needed in two_arg_diff | ||
| | | ||
| note: function defined here | ||
| --> $DIR/extra_arguments.rs:4:4 | ||
| | | ||
| LL | fn two_arg_diff(_a: i32, _b: &str) {} | ||
| | ^^^^^^^^^^^^ ------- -------- | ||
| help: the following changes might help | ||
| | | ||
| LL | two_arg_diff(1, {&str}, ); | ||
| | -- ^^^^^^^-- | ||
| 
     | 
||
| error[E0059]: arguments to this function are incorrect | ||
| --> $DIR/extra_arguments.rs:17:23 | ||
| | | ||
| LL | two_arg_diff(1, "", ""); | ||
| | ^^ | ||
| | | | ||
| | no parameter of type &'static str is needed in two_arg_diff | ||
| | help: removing this argument may help | ||
| | | ||
| note: function defined here | ||
| --> $DIR/extra_arguments.rs:4:4 | ||
| | | ||
| LL | fn two_arg_diff(_a: i32, _b: &str) {} | ||
| | ^^^^^^^^^^^^ ------- -------- | ||
| 
     | 
||
| error[E0059]: multiple arguments to this function are incorrect | ||
| --> $DIR/extra_arguments.rs:18:19 | ||
| | | ||
| LL | two_arg_diff(1, 1, "", ""); | ||
| | ^ ^^^ ^^ no parameter of type &'static str is needed in two_arg_diff | ||
| | | || | ||
| | | |no parameter of type &'static str is needed in two_arg_diff | ||
| | | missing argument of type &str | ||
| | no parameter of type {integer} is needed in two_arg_diff | ||
| | | ||
| note: function defined here | ||
| --> $DIR/extra_arguments.rs:4:4 | ||
| | | ||
| LL | fn two_arg_diff(_a: i32, _b: &str) {} | ||
| | ^^^^^^^^^^^^ ------- -------- | ||
| help: the following changes might help | ||
| | | ||
| LL | two_arg_diff(1, {&str}, ); | ||
| | -- ^^^^^^^--- | ||
| 
     | 
||
| error[E0059]: multiple arguments to this function are incorrect | ||
| --> $DIR/extra_arguments.rs:19:23 | ||
| | | ||
| LL | two_arg_diff(1, "", 1, ""); | ||
| | ^ ^^ no parameter of type &'static str is needed in two_arg_diff | ||
| | | | ||
| | no parameter of type {integer} is needed in two_arg_diff | ||
| | | ||
| note: function defined here | ||
| --> $DIR/extra_arguments.rs:4:4 | ||
| | | ||
| LL | fn two_arg_diff(_a: i32, _b: &str) {} | ||
| | ^^^^^^^^^^^^ ------- -------- | ||
| help: removing these argument may help | ||
| | | ||
| LL | two_arg_diff(1, "", ); | ||
| | -- -- | ||
| 
     | 
||
| error: aborting due to 10 previous errors | ||
| 
     | 
||
| For more information about this error, try `rustc --explain E0059`. | 
  
    
      This file contains hidden or 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,43 @@ | ||
| // More nuanced test cases for invalid arguments #65853 | ||
| 
     | 
||
| struct X {} | ||
| 
     | 
||
| fn one_arg(_a: i32) {} | ||
| fn two_arg_same(_a: i32, _b: i32) {} | ||
| fn two_arg_diff(_a: i32, _b: f32) {} | ||
| fn three_arg_diff(_a: i32, _b: f32, _c: &str) {} | ||
| fn three_arg_repeat(_a: i32, _b: i32, _c: &str) {} | ||
| 
     | 
||
| fn main() { | ||
| // Providing an incorrect argument for a single parameter function | ||
| one_arg(1.0); //~ ERROR arguments to this function are incorrect | ||
| 
     | 
||
| // Providing one or two invalid arguments to a two parameter function | ||
| two_arg_same(1, ""); //~ ERROR arguments to this function are incorrect | ||
| two_arg_same("", 1); //~ ERROR arguments to this function are incorrect | ||
| two_arg_same("", ""); //~ ERROR arguments to this function are incorrect | ||
| two_arg_diff(1, ""); //~ ERROR arguments to this function are incorrect | ||
| two_arg_diff("", 1.0); //~ ERROR arguments to this function are incorrect | ||
| two_arg_diff("", ""); //~ ERROR arguments to this function are incorrect | ||
| 
     | 
||
| // Providing invalid arguments to a three parameter function | ||
| three_arg_diff(X{}, 1.0, ""); //~ ERROR arguments to this function are incorrect | ||
| three_arg_diff(1, X {}, ""); //~ ERROR arguments to this function are incorrect | ||
| three_arg_diff(1, 1.0, X {}); //~ ERROR arguments to this function are incorrect | ||
| 
     | 
||
| three_arg_diff(X {}, X {}, ""); //~ ERROR arguments to this function are incorrect | ||
| three_arg_diff(X {}, 1.0, X {}); //~ ERROR arguments to this function are incorrect | ||
| three_arg_diff(1, X {}, X {}); //~ ERROR arguments to this function are incorrect | ||
| 
     | 
||
| three_arg_diff(X {}, X {}, X {}); //~ ERROR arguments to this function are incorrect | ||
| 
     | 
||
| three_arg_repeat(X {}, 1, ""); //~ ERROR arguments to this function are incorrect | ||
| three_arg_repeat(1, X {}, ""); //~ ERROR arguments to this function are incorrect | ||
| three_arg_repeat(1, 1, X {}); //~ ERROR arguments to this function are incorrect | ||
| 
     | 
||
| three_arg_repeat(X {}, X {}, ""); //~ ERROR arguments to this function are incorrect | ||
| three_arg_repeat(X {}, 1, X {}); //~ ERROR arguments to this function are incorrect | ||
| three_arg_repeat(1, X {}, X{}); //~ ERROR arguments to this function are incorrect | ||
| 
     | 
||
| three_arg_repeat(X {}, X {}, X {}); //~ ERROR arguments to this function are incorrect | ||
| } | 
      
      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.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.