-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
"help: remove the extra argument" prints too much of the function arguments #106304
Comments
@estebank says
|
@rustbot claim |
Ok, I'll have a look. Might be a little out of my skill level so if you or @jyn514 could mentor be a bit that would be great. I also haven't looked at your PR yet so I assume that would be a good place to start. @rustbot claim |
@estebank It appears you have fixed the trailing commas? |
I figured a cheat to get that to work (when removing remove |
I've been looking around the relevant bits of |
@Ezrashaw I would try to collect the vec with the suggestions always, and if we detect that it is the straightforward case you emit the targeted suggestion, otherwise you fallback on the current logic. I would look at swap for example: if there're only swapped arg cases, then the logic for coming up with the suggestion would be relatively easy, where you suggest one snippet in the span of the other, as many times as necessary. |
@estebank And then the old full-span logic can be phased out eventually. I'll be working on this, just slowly because I'm new and on holiday. |
…O8Ki More accurate spans for arg removal suggestion Partially address rust-lang#106304.
I'm not sure exactly what the status is here. I will work on it at some point, but if someone else wants to then that's all good. AFAIK, Esteban's PR was expanded a bit to cover some extra cases, however there are still some sub-optimal cases where the full span is used. |
We should make sure we have a single test that covers all of the different cases, at the very least to notice when anyone changes the handling of these :) |
Just hit a version of this today. For the following snippet: fn foo(a: (), b: u32) {}
fn main() {
foo("hi", (), 42u32, ());
} rustc gives:
Not sure why @WaffleLapkin 's #109782 didn't work in this instance... |
…chenkov Added more scenarios where comma to be removed in the function arg This is an attempt to address the problem methion in rust-lang#106304 (comment). Copy the annotation to explain the fix If the next Error::Extra ("next") doesn't next to current ("current") ``` fn foo(_: (), _: u32) {} - foo("current", (), 1u32, "next") + foo((), 1u32) ``` If the previous error is not a `Error::Extra`, then do not trim the next comma ``` - foo((), "current", 42u32, "next") + foo((), 42u32) ``` Frankly, this is a fix from a test case and may not cover all scenarios
Rollup merge of rust-lang#126588 - linyihai:trim-extra-comma, r=petrochenkov Added more scenarios where comma to be removed in the function arg This is an attempt to address the problem methion in rust-lang#106304 (comment). Copy the annotation to explain the fix If the next Error::Extra ("next") doesn't next to current ("current") ``` fn foo(_: (), _: u32) {} - foo("current", (), 1u32, "next") + foo((), 1u32) ``` If the previous error is not a `Error::Extra`, then do not trim the next comma ``` - foo((), "current", 42u32, "next") + foo((), 42u32) ``` Frankly, this is a fix from a test case and may not cover all scenarios
Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=d6dfe3d605639255444883813f8376db
The current output is:
Ideally the output should look like:
Printing the entire body of the closure is ... a bit much 😆
The text was updated successfully, but these errors were encountered: