mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Implement region negation to minicore and add a flag fmt_before_1_89_0
This commit is contained in:
parent
56de2113f1
commit
c13859903c
@ -412,44 +412,70 @@ impl MiniCore {
|
||||
}
|
||||
|
||||
let mut active_regions = Vec::new();
|
||||
let mut inactive_regions = Vec::new();
|
||||
let mut seen_regions = Vec::new();
|
||||
for line in lines {
|
||||
let trimmed = line.trim();
|
||||
if let Some(region) = trimmed.strip_prefix("// region:") {
|
||||
active_regions.push(region);
|
||||
continue;
|
||||
if let Some(region) = region.strip_prefix('!') {
|
||||
inactive_regions.push(region);
|
||||
continue;
|
||||
} else {
|
||||
active_regions.push(region);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if let Some(region) = trimmed.strip_prefix("// endregion:") {
|
||||
let prev = active_regions.pop().unwrap();
|
||||
let (prev, region) = if let Some(region) = region.strip_prefix('!') {
|
||||
(inactive_regions.pop().unwrap(), region)
|
||||
} else {
|
||||
(active_regions.pop().unwrap(), region)
|
||||
};
|
||||
assert_eq!(prev, region, "unbalanced region pairs");
|
||||
continue;
|
||||
}
|
||||
|
||||
let mut line_region = false;
|
||||
if let Some(idx) = trimmed.find("// :") {
|
||||
line_region = true;
|
||||
let mut active_line_region = false;
|
||||
let mut inactive_line_region = false;
|
||||
if let Some(idx) = trimmed.find("// :!") {
|
||||
inactive_line_region = true;
|
||||
inactive_regions.push(&trimmed[idx + "// :!".len()..]);
|
||||
} else if let Some(idx) = trimmed.find("// :") {
|
||||
active_line_region = true;
|
||||
active_regions.push(&trimmed[idx + "// :".len()..]);
|
||||
}
|
||||
|
||||
let mut keep = true;
|
||||
for ®ion in &active_regions {
|
||||
for ®ion in active_regions.iter() {
|
||||
assert!(!region.starts_with(' '), "region marker starts with a space: {region:?}");
|
||||
self.assert_valid_flag(region);
|
||||
seen_regions.push(region);
|
||||
keep &= self.has_flag(region);
|
||||
}
|
||||
for ®ion in inactive_regions.iter() {
|
||||
assert!(!region.starts_with(' '), "region marker starts with a space: {region:?}");
|
||||
self.assert_valid_flag(region);
|
||||
seen_regions.push(region);
|
||||
keep &= !self.has_flag(region);
|
||||
}
|
||||
|
||||
if keep {
|
||||
buf.push_str(line);
|
||||
}
|
||||
if line_region {
|
||||
if active_line_region {
|
||||
active_regions.pop().unwrap();
|
||||
}
|
||||
if inactive_line_region {
|
||||
inactive_regions.pop().unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
if !active_regions.is_empty() {
|
||||
panic!("unclosed regions: {active_regions:?} Add an `endregion` comment");
|
||||
}
|
||||
if !inactive_regions.is_empty() {
|
||||
panic!("unclosed regions: {inactive_regions:?} Add an `endregion` comment");
|
||||
}
|
||||
|
||||
for flag in &self.valid_flags {
|
||||
if !seen_regions.iter().any(|it| it == flag) {
|
||||
|
@ -31,6 +31,7 @@
|
||||
//! eq: sized
|
||||
//! error: fmt
|
||||
//! fmt: option, result, transmute, coerce_unsized, copy, clone, derive
|
||||
//! fmt_before_1_89_0: fmt
|
||||
//! fn: tuple
|
||||
//! from: sized, result
|
||||
//! future: pin
|
||||
@ -1175,6 +1176,7 @@ pub mod fmt {
|
||||
}
|
||||
}
|
||||
|
||||
// region:fmt_before_1_89_0
|
||||
#[lang = "format_unsafe_arg"]
|
||||
pub struct UnsafeArg {
|
||||
_private: (),
|
||||
@ -1185,6 +1187,7 @@ pub mod fmt {
|
||||
UnsafeArg { _private: () }
|
||||
}
|
||||
}
|
||||
// endregion:fmt_before_1_89_0
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
@ -1204,6 +1207,7 @@ pub mod fmt {
|
||||
Arguments { pieces, fmt: None, args: &[] }
|
||||
}
|
||||
|
||||
// region:fmt_before_1_89_0
|
||||
pub fn new_v1_formatted(
|
||||
pieces: &'a [&'static str],
|
||||
args: &'a [rt::Argument<'a>],
|
||||
@ -1212,6 +1216,17 @@ pub mod fmt {
|
||||
) -> Arguments<'a> {
|
||||
Arguments { pieces, fmt: Some(fmt), args }
|
||||
}
|
||||
// endregion:fmt_before_1_89_0
|
||||
|
||||
// region:!fmt_before_1_89_0
|
||||
pub unsafe fn new_v1_formatted(
|
||||
pieces: &'a [&'static str],
|
||||
args: &'a [rt::Argument<'a>],
|
||||
fmt: &'a [rt::Placeholder],
|
||||
) -> Arguments<'a> {
|
||||
Arguments { pieces, fmt: Some(fmt), args }
|
||||
}
|
||||
// endregion:!fmt_before_1_89_0
|
||||
|
||||
pub const fn as_str(&self) -> Option<&'static str> {
|
||||
match (self.pieces, self.args) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user