-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add debug assertions for empty replacements and overlapping spans #13567
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -101,17 +101,21 @@ impl SemicolonBlock { | |
); | ||
} | ||
|
||
fn semicolon_outside_block( | ||
&self, | ||
cx: &LateContext<'_>, | ||
block: &Block<'_>, | ||
tail_stmt_expr: &Expr<'_>, | ||
semi_span: Span, | ||
) { | ||
fn semicolon_outside_block(&self, cx: &LateContext<'_>, block: &Block<'_>, tail_stmt_expr: &Expr<'_>) { | ||
let insert_span = block.span.with_lo(block.span.hi()); | ||
// account for macro calls | ||
let semi_span = cx.sess().source_map().stmt_span(semi_span, block.span); | ||
let remove_span = semi_span.with_lo(tail_stmt_expr.span.source_callsite().hi()); | ||
|
||
// For macro call semicolon statements (`mac!();`), the statement's span does not actually | ||
// include the semicolon itself, so use `mac_call_stmt_semi_span`, which finds the semicolon | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting that this function exists! |
||
// based on a source snippet. | ||
// (Does not use `stmt_span` as that requires `.from_expansion()` to return true, | ||
// which is not the case for e.g. `line!();` and `asm!();`) | ||
let Some(remove_span) = cx | ||
.sess() | ||
.source_map() | ||
.mac_call_stmt_semi_span(tail_stmt_expr.span.source_callsite()) | ||
else { | ||
return; | ||
}; | ||
|
||
if self.semicolon_outside_block_ignore_multiline && get_line(cx, remove_span) != get_line(cx, insert_span) { | ||
return; | ||
|
@@ -150,13 +154,12 @@ impl LateLintPass<'_> for SemicolonBlock { | |
}; | ||
let &Stmt { | ||
kind: StmtKind::Semi(expr), | ||
span, | ||
.. | ||
} = stmt | ||
else { | ||
return; | ||
}; | ||
self.semicolon_outside_block(cx, block, expr, span); | ||
self.semicolon_outside_block(cx, block, expr); | ||
}, | ||
StmtKind::Semi(Expr { | ||
kind: ExprKind::Block(block @ Block { expr: Some(tail), .. }, _), | ||
|
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -80,5 +80,13 @@ fn main() { | |
|
||
{ unit_fn_block(); }; | ||
|
||
unsafe { | ||
std::arch::asm!("") | ||
}; | ||
|
||
{ | ||
line!() | ||
}; | ||
|
||
unit_fn_block() | ||
} |
This file contains 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 |
---|---|---|
|
@@ -80,5 +80,13 @@ fn main() { | |
|
||
{ unit_fn_block(); }; | ||
|
||
unsafe { | ||
std::arch::asm!(""); | ||
} | ||
|
||
{ | ||
line!(); | ||
} | ||
|
||
unit_fn_block() | ||
} |
This file contains 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
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.
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 noticed that this didn't get synced (together with a few other things) when doing the Josh setup. With Josh all of that would be synced. The problem with
subtree
is, that if you mess up a merge once, it will never be synced correctly again. Luckily this didn't happen that often yet and will get fixed, once we move to Josh.This is a commit fixing everything that wasn't correctly synced with
subtree
: flip1995@89f1145