Skip to content

Commit

Permalink
Merge pull request #1896 from Mark-Simulacrum/fix-ignore-adjacency
Browse files Browse the repository at this point in the history
Fix adjacent ignore block handling
  • Loading branch information
jackh726 authored Feb 2, 2025
2 parents fedb383 + 08262ea commit a9ed2b9
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion parser/src/ignore_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ impl IgnoreBlocks {
pub fn overlaps_ignore(&self, region: Range<usize>) -> Option<Range<usize>> {
for ignore in &self.ignore {
// See https://stackoverflow.com/questions/3269434.
if ignore.start <= region.end && region.start <= ignore.end {
// We have strictly < because `end` is not included in our ranges.
if ignore.start < region.end && region.start < ignore.end {
return Some(ignore.clone());
}
}
Expand All @@ -77,13 +78,16 @@ fn bodies(s: &str) -> Vec<Ignore<'_>> {
for range in &cbs.ignore {
let range = range.clone();
if previous.end != range.start {
assert!(cbs.overlaps_ignore(previous.end..range.start).is_none());
bodies.push(Ignore::No(&s[previous.end..range.start]));
}
assert!(cbs.overlaps_ignore(range.clone()).is_some());
bodies.push(Ignore::Yes(&s[range.clone()]));
previous = range.clone();
}
if let Some(range) = cbs.ignore.last() {
if range.end != s.len() {
assert!(cbs.overlaps_ignore(range.end..s.len()).is_none());
bodies.push(Ignore::No(&s[range.end..]));
}
}
Expand Down Expand Up @@ -282,3 +286,14 @@ This is an HTML comment.
],
);
}

#[test]
fn cbs_13() {
assert_eq!(
bodies("<!-- q -->\n@rustbot label +F-trait_upcasting"),
[
Ignore::Yes("<!-- q -->\n"),
Ignore::No("@rustbot label +F-trait_upcasting")
],
);
}

0 comments on commit a9ed2b9

Please sign in to comment.