Skip to content

Commit 17a8ba9

Browse files
committed
Implement region negation to minicore and add a flag fmt_before_1_89_0
1 parent 110bacd commit 17a8ba9

File tree

2 files changed

+49
-8
lines changed

2 files changed

+49
-8
lines changed

src/tools/rust-analyzer/crates/test-utils/src/fixture.rs

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -412,44 +412,70 @@ impl MiniCore {
412412
}
413413

414414
let mut active_regions = Vec::new();
415+
let mut inactive_regions = Vec::new();
415416
let mut seen_regions = Vec::new();
416417
for line in lines {
417418
let trimmed = line.trim();
418419
if let Some(region) = trimmed.strip_prefix("// region:") {
419-
active_regions.push(region);
420-
continue;
420+
if let Some(region) = region.strip_prefix('!') {
421+
inactive_regions.push(region);
422+
continue;
423+
} else {
424+
active_regions.push(region);
425+
continue;
426+
}
421427
}
422428
if let Some(region) = trimmed.strip_prefix("// endregion:") {
423-
let prev = active_regions.pop().unwrap();
429+
let (prev, region) = if let Some(region) = region.strip_prefix('!') {
430+
(inactive_regions.pop().unwrap(), region)
431+
} else {
432+
(active_regions.pop().unwrap(), region)
433+
};
424434
assert_eq!(prev, region, "unbalanced region pairs");
425435
continue;
426436
}
427437

428-
let mut line_region = false;
429-
if let Some(idx) = trimmed.find("// :") {
430-
line_region = true;
438+
let mut active_line_region = false;
439+
let mut inactive_line_region = false;
440+
if let Some(idx) = trimmed.find("// :!") {
441+
inactive_line_region = true;
442+
inactive_regions.push(&trimmed[idx + "// :!".len()..]);
443+
} else if let Some(idx) = trimmed.find("// :") {
444+
active_line_region = true;
431445
active_regions.push(&trimmed[idx + "// :".len()..]);
432446
}
433447

434448
let mut keep = true;
435-
for &region in &active_regions {
449+
for &region in active_regions.iter() {
436450
assert!(!region.starts_with(' '), "region marker starts with a space: {region:?}");
437451
self.assert_valid_flag(region);
438452
seen_regions.push(region);
439453
keep &= self.has_flag(region);
440454
}
455+
for &region in inactive_regions.iter() {
456+
assert!(!region.starts_with(' '), "region marker starts with a space: {region:?}");
457+
self.assert_valid_flag(region);
458+
seen_regions.push(region);
459+
keep &= !self.has_flag(region);
460+
}
441461

442462
if keep {
443463
buf.push_str(line);
444464
}
445-
if line_region {
465+
if active_line_region {
446466
active_regions.pop().unwrap();
447467
}
468+
if inactive_line_region {
469+
inactive_regions.pop().unwrap();
470+
}
448471
}
449472

450473
if !active_regions.is_empty() {
451474
panic!("unclosed regions: {active_regions:?} Add an `endregion` comment");
452475
}
476+
if !inactive_regions.is_empty() {
477+
panic!("unclosed regions: {inactive_regions:?} Add an `endregion` comment");
478+
}
453479

454480
for flag in &self.valid_flags {
455481
if !seen_regions.iter().any(|it| it == flag) {

src/tools/rust-analyzer/crates/test-utils/src/minicore.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
//! eq: sized
3232
//! error: fmt
3333
//! fmt: option, result, transmute, coerce_unsized, copy, clone, derive
34+
//! fmt_before_1_89_0: fmt
3435
//! fn: tuple
3536
//! from: sized, result
3637
//! future: pin
@@ -1175,6 +1176,7 @@ pub mod fmt {
11751176
}
11761177
}
11771178

1179+
// region:fmt_before_1_89_0
11781180
#[lang = "format_unsafe_arg"]
11791181
pub struct UnsafeArg {
11801182
_private: (),
@@ -1185,6 +1187,7 @@ pub mod fmt {
11851187
UnsafeArg { _private: () }
11861188
}
11871189
}
1190+
// endregion:fmt_before_1_89_0
11881191
}
11891192

11901193
#[derive(Copy, Clone)]
@@ -1204,6 +1207,7 @@ pub mod fmt {
12041207
Arguments { pieces, fmt: None, args: &[] }
12051208
}
12061209

1210+
// region:fmt_before_1_89_0
12071211
pub fn new_v1_formatted(
12081212
pieces: &'a [&'static str],
12091213
args: &'a [rt::Argument<'a>],
@@ -1212,6 +1216,17 @@ pub mod fmt {
12121216
) -> Arguments<'a> {
12131217
Arguments { pieces, fmt: Some(fmt), args }
12141218
}
1219+
// endregion:fmt_before_1_89_0
1220+
1221+
// region:!fmt_before_1_89_0
1222+
pub unsafe fn new_v1_formatted(
1223+
pieces: &'a [&'static str],
1224+
args: &'a [rt::Argument<'a>],
1225+
fmt: &'a [rt::Placeholder],
1226+
) -> Arguments<'a> {
1227+
Arguments { pieces, fmt: Some(fmt), args }
1228+
}
1229+
// endregion:!fmt_before_1_89_0
12151230

12161231
pub const fn as_str(&self) -> Option<&'static str> {
12171232
match (self.pieces, self.args) {

0 commit comments

Comments
 (0)