-
Notifications
You must be signed in to change notification settings - Fork 14k
Fix/Make proc_macro span_close() and span_open() more accurate after set_span() calls #149052
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
base: main
Are you sure you want to change the base?
Conversation
|
rustbot has assigned @petrochenkov. Use |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
I think it would be better to test the opening/closing span recovery strategy on the compiler first, and then do the same for proc macros.
|
I can look at adding something to the compiler side of things first. I suppose we could inspect parts of the stream itself if that is desired. However, at least on the proc_macro side I did not do that. That's because someone could assign a span not directly associated to the underlying stream that the group contains. Therefore, inspecting the stream may not provide any useful information. Thusly, I chose what I did since it would more accurate in most cases than just using the whole span. From a quick look the As for the four options:
As for the diagnostic output is there anything you're particularly looking for or wanting to avoid when you mention experimentally testing? |
I was not suggesting to inspect token stream, "source map" is some source text to which all spans map, not tokens. |
Just want to look at the results with different options for a start. |
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
So I have here the Honestly, in the compiler I would say that it might better to have not just some catch all This still does nothing about my main concern though about fixing the |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Could you update the tests (to make CI green) and submit the compiler changes in a separate PR? |
|
Okay that did not get rid of the superfluous labels -_- -- Edit -- |
…r set_span call. This tries to recover the open in and close delimiter spans for the new span, otherwise it reverts to old behavior of using the the whole span for the open and close delimiter.
|
Okay, I updated the this to only handle the obvious case. I also make sure the the current delimiter of the group matches if not it just goes to the old behavior. I also thought about maybe adding this, but was not sure we wanted to loop through the source text like this? My reasoning was a span in theory could be for a fragment of text like this let mut depth = 1usize;
let mut iter = src.iter().skip(1);
while depth > 0
&& let Some(&c) = iter.next()
{
if c == open_chr {
depth += 1;
}
if c == close_chr {
depth -= 1;
}
}
// We possibly don't have a true matching pair because the depth did not
// reach zero or the iterator did not finish. This could be a false
// positive because of comments and literals. However, we are falling
// back to the default.
if depth != 0 || iter.next().is_some() {
self.0.span = bridge::DelimSpan::from_single(span.0);
return;
}The false positive I am talking about is something like this: { /* comment } */ let _code = 0; }So it would revert to old behavior, however in cases where there is no delimiter character in like a string literal or comment it still would allow @rustbot ready -- Edit -- |
|
Requested reviewer is already assigned to this pull request. Please choose another assignee. |
When
Group::set_span()is called the span's forGroup::span_open()andGroup::span_close()methods just become the whole span instead where it should be the span of the delimiters. This PR ensures they have at least a more usable value after a call toGroup::set_span().Here is a kinda of motivating example of this issue I observed. If you compare the current behavior the outputs the diagnostics will not be on the opening and closing delimiters after calling set span. If you look at the outputs after using this PR they will match. Further, afterward
Span::eq()then evaluates to true which nice to see.This is all I did to invoke the proc_macro example above.