-
Notifications
You must be signed in to change notification settings - Fork 13k
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
More accurate spans for arg removal suggestion #106347
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
This comment was marked as resolved.
This comment was marked as resolved.
r? rust-lang/compiler |
@petrochenkov Consider removing yourself from the review rotation and readding yourself once you are ready to take them on, just to avoid spam on your end :) Happy new year. |
@estebank I have some code for the case where arguments must be added, but that code relies on this code to be merged first. Also I think I have found a bug with this PR: fn foo(x: &str) {}
fn main() {
foo(1, 2, "hello");
} emits this:
Note the leading comma. |
Yeah, you're right :-/ Would you have time to try and fix the bug in a subsequent PR? |
Yeah, I can have a look at this. Honestly the whole error printing bit of that function needs a rewrite, it's all based around the whole-span idea. Ideally we can get this merged soon so that I can create my PRs for the additional suggestion and to fix that bug. |
// Incorporate the argument changes in the removal suggestion. | ||
let mut prev = -1; | ||
for (expected_idx, provided_idx) in matched_inputs.iter_enumerated() { | ||
if let Some(provided_idx) = provided_idx { | ||
prev = provided_idx.index() as i64; | ||
} | ||
let idx = ProvidedIdx::from_usize((prev + 1) as usize); | ||
if let None = provided_idx | ||
&& let Some((_, arg_span)) = provided_arg_tys.get(idx) | ||
{ | ||
let (_, expected_ty) = formal_and_expected_inputs[expected_idx]; | ||
suggestions.push((*arg_span, ty_to_snippet(expected_ty, expected_idx))); | ||
} | ||
} |
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 explain what this does?
It's breaking my code :(
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.
What do you mean by "breaking your code"? Do you have an example of a broken suggestion that we can put as a test?
estebank: I don't really understand what this is doing either.
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.
It's been a while since I wrote this and now I don't recall exactly what this does, but this weird code was so that I could also incorporate the "change this argument for this other one" suggestions into the removal one, but it is quite messy :-/
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.
The last commit now shows the effect of this block taken out on the tests.
@estebank What's happening with this PR? I intend to write some more changes but obviously they rely on this PR. Also could you look at my review comment, thanks! |
@Ezrashaw this PR is awaiting review. Different reviewers have different schedules when they are available. |
| ~~~~~~ | ||
LL - 1, | ||
LL + 1 | ||
| |
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.
This suggestion is missing a bit of context.
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.
I would like to address this in a separate PR. This is a consequence of how the suggestion machinery works. I find it unreasonable to address that as part of an "unrelated" change.
| ~~~~~~~ | ||
LL - 1, | ||
LL + 1, | ||
| |
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.
This one too.
@@ -1098,7 +1153,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||
Some(format!("provide the argument{}", if plural { "s" } else { "" })) | |||
} | |||
SuggestionText::Remove(plural) => { | |||
Some(format!("remove the extra argument{}", if plural { "s" } else { "" })) | |||
err.multipart_suggestion_verbose( |
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.
If we are just suggesting a removal, is a verbose suggestion the best choice?
From the ui diff when arguments span multiple lines, the terse version may be better.
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.
I tend to prefer the verbose output in general, because I feel showing the resulting code ends up being clearer, but I can change this to terse, it shouldn't be too much of an issue.
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.
Changed. It's on its own commit so that you can review it.
// Incorporate the argument changes in the removal suggestion. | ||
let mut prev = -1; | ||
for (expected_idx, provided_idx) in matched_inputs.iter_enumerated() { | ||
if let Some(provided_idx) = provided_idx { | ||
prev = provided_idx.index() as i64; | ||
} | ||
let idx = ProvidedIdx::from_usize((prev + 1) as usize); | ||
if let None = provided_idx | ||
&& let Some((_, arg_span)) = provided_arg_tys.get(idx) | ||
{ | ||
let (_, expected_ty) = formal_and_expected_inputs[expected_idx]; | ||
suggestions.push((*arg_span, ty_to_snippet(expected_ty, expected_idx))); | ||
} | ||
} |
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.
What do you mean by "breaking your code"? Do you have an example of a broken suggestion that we can put as a test?
estebank: I don't really understand what this is doing either.
if let Some(provided_idx) = provided_idx { | ||
prev = provided_idx.index() as i64; | ||
} | ||
let idx = ProvidedIdx::from_usize((prev + 1) as usize); | ||
if let None = provided_idx | ||
&& let Some((_, arg_span)) = provided_arg_tys.get(idx) | ||
{ | ||
let (_, expected_ty) = formal_and_expected_inputs[expected_idx]; | ||
suggestions.push((*arg_span, ty_to_snippet(expected_ty, expected_idx))); | ||
} |
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.
if let Some(provided_idx) = provided_idx { | |
prev = provided_idx.index() as i64; | |
} | |
let idx = ProvidedIdx::from_usize((prev + 1) as usize); | |
if let None = provided_idx | |
&& let Some((_, arg_span)) = provided_arg_tys.get(idx) | |
{ | |
let (_, expected_ty) = formal_and_expected_inputs[expected_idx]; | |
suggestions.push((*arg_span, ty_to_snippet(expected_ty, expected_idx))); | |
} | |
if let Some(provided_idx) = provided_idx { | |
prev = provided_idx.index() as i64; | |
} else { | |
let idx = ProvidedIdx::from_usize((prev + 1) as usize); | |
if let Some((_, arg_span)) = provided_arg_tys.get(idx) { | |
let (_, expected_ty) = formal_and_expected_inputs[expected_idx]; | |
suggestions.push((*arg_span, ty_to_snippet(expected_ty, expected_idx))); | |
} | |
} |
?
| ++ | ||
LL - fn oom() -> ! { | ||
LL - loop {} | ||
LL - } |
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.
This suggestion is weird too. Any idea why?
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.
I think this is caused by the macro spans :-/
4d85fb2
to
134a305
Compare
Cloud you rebase the commits? |
134a305
to
dff10d0
Compare
@TaKO8Ki I just rebased and pushed, but the changes were merging cleanly. |
@bors r+ |
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#106347 (More accurate spans for arg removal suggestion) - rust-lang#108057 (Prevent some attributes from being merged with others on reexports) - rust-lang#108090 (`if $c:expr { Some($r:expr) } else { None }` =>> `$c.then(|| $r)`) - rust-lang#108092 (note issue for feature(packed_bundled_libs)) - rust-lang#108099 (use chars instead of strings where applicable) - rust-lang#108115 (Do not ICE on unmet trait alias bounds) - rust-lang#108125 (Add new people to the compiletest review rotation) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Partially address #106304.