Skip to content
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

coverage: Avoid creating malformed macro name spans #117827

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions compiler/rustc_mir_transform/src/coverage/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,12 @@ impl<'a> CoverageSpansGenerator<'a> {

let merged_prefix_len = self.curr_original_span.lo() - curr.span.lo();
let after_macro_bang = merged_prefix_len + BytePos(visible_macro.as_str().len() as u32 + 1);
if self.curr().span.lo() + after_macro_bang > self.curr().span.hi() {
// Something is wrong with the macro name span;
// return now to avoid emitting malformed mappings.
// FIXME(#117788): Track down why this happens.
return;
}
Comment on lines +384 to +389
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though curr is already available as a local variable, the change that extracted that variable isn't part of the current (1.74) beta branch. So instead I'm calling self.curr() explicitly here, so that the same lines of code can simply be copied over to beta if desired.

let mut macro_name_cov = curr.clone();
self.curr_mut().span = curr.span.with_lo(curr.span.lo() + after_macro_bang);
macro_name_cov.span =
Expand Down
Loading