From d2c9f3add10a020d6ef7b674b7a722a1d0846f2d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 16 Jun 2021 10:30:29 +0300 Subject: internal: add deref_mut to minicore --- crates/test_utils/src/fixture.rs | 54 +++++++++++++++++++++++++-------------- crates/test_utils/src/minicore.rs | 8 ++++++ 2 files changed, 43 insertions(+), 19 deletions(-) (limited to 'crates/test_utils') diff --git a/crates/test_utils/src/fixture.rs b/crates/test_utils/src/fixture.rs index 6ba112de8..313088c37 100644 --- a/crates/test_utils/src/fixture.rs +++ b/crates/test_utils/src/fixture.rs @@ -129,8 +129,18 @@ impl Fixture { if line.starts_with("//-") { let meta = Fixture::parse_meta_line(line); res.push(meta) - } else if let Some(entry) = res.last_mut() { - entry.text.push_str(line); + } else { + if line.starts_with("// ") + && line.contains(":") + && !line.contains("::") + && line.chars().all(|it| !it.is_uppercase()) + { + panic!("looks like invalid metadata line: {:?}", line) + } + + if let Some(entry) = res.last_mut() { + entry.text.push_str(line); + } } } @@ -276,38 +286,44 @@ impl MiniCore { } } - let mut curr_region = ""; + let mut active_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:") { - assert_eq!(curr_region, ""); - curr_region = region; + active_regions.push(region); continue; } if let Some(region) = trimmed.strip_prefix("// endregion:") { - assert_eq!(curr_region, region); - curr_region = ""; + let prev = active_regions.pop().unwrap(); + assert_eq!(prev, region); continue; } - seen_regions.push(curr_region); - let mut flag = curr_region; + let mut line_region = false; if let Some(idx) = trimmed.find("// :") { - flag = &trimmed[idx + "// :".len()..]; + line_region = true; + active_regions.push(&trimmed[idx + "// :".len()..]); } - let skip = if flag == "" { - false - } else { - assert!(!flag.starts_with(' '), "region marker starts with a space: {:?}", flag); - self.assert_valid_flag(flag); - !self.has_flag(flag) - }; + let mut keep = true; + for ®ion in &active_regions { + 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 !skip { + if keep { buf.push_str(line) } + if line_region { + active_regions.pop().unwrap(); + } } for flag in &self.valid_flags { @@ -315,7 +331,7 @@ impl MiniCore { panic!("unused minicore flag: {:?}", flag); } } - + format!("{}", buf); buf } } diff --git a/crates/test_utils/src/minicore.rs b/crates/test_utils/src/minicore.rs index 5ff60178c..8555ff935 100644 --- a/crates/test_utils/src/minicore.rs +++ b/crates/test_utils/src/minicore.rs @@ -13,6 +13,7 @@ //! range: //! unsize: sized //! deref: sized +//! deref_mut: deref //! coerce_unsized: unsize //! pin: //! future: pin @@ -64,8 +65,15 @@ pub mod ops { type Target: ?Sized; fn deref(&self) -> &Self::Target; } + // region:deref_mut + #[lang = "deref_mut"] + pub trait DerefMut: Deref { + fn deref_mut(&mut self) -> &mut Self::Target; + } + // endregion:deref_mut } pub use self::deref::Deref; + pub use self::deref::DerefMut; //:deref_mut // endregion:deref // region:range -- cgit v1.2.3 From 8a4d9bb80a484193dc24c474af30d0d0e091963b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 16 Jun 2021 10:48:07 +0300 Subject: internal: add fn to minicore --- crates/test_utils/src/fixture.rs | 4 +++- crates/test_utils/src/minicore.rs | 28 +++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) (limited to 'crates/test_utils') diff --git a/crates/test_utils/src/fixture.rs b/crates/test_utils/src/fixture.rs index 313088c37..005a5c092 100644 --- a/crates/test_utils/src/fixture.rs +++ b/crates/test_utils/src/fixture.rs @@ -164,7 +164,9 @@ impl Fixture { let mut env = FxHashMap::default(); let mut introduce_new_source_root = false; for component in components[1..].iter() { - let (key, value) = component.split_once(':').unwrap(); + let (key, value) = component + .split_once(':') + .unwrap_or_else(|| panic!("invalid meta line: {:?}", meta)); match key { "crate" => krate = Some(value.to_string()), "deps" => deps = value.split(',').map(|it| it.to_string()).collect(), diff --git a/crates/test_utils/src/minicore.rs b/crates/test_utils/src/minicore.rs index 8555ff935..e04ca58d2 100644 --- a/crates/test_utils/src/minicore.rs +++ b/crates/test_utils/src/minicore.rs @@ -9,12 +9,13 @@ //! //! Available flags: //! sized: +//! unsize: sized +//! coerce_unsized: unsize //! slice: //! range: -//! unsize: sized //! deref: sized //! deref_mut: deref -//! coerce_unsized: unsize +//! fn: //! pin: //! future: pin //! option: @@ -74,7 +75,7 @@ pub mod ops { } pub use self::deref::Deref; pub use self::deref::DerefMut; //:deref_mut - // endregion:deref + // endregion:deref // region:range mod range { @@ -112,6 +113,26 @@ pub mod ops { pub use self::range::{Range, RangeFrom, RangeFull, RangeTo}; pub use self::range::{RangeInclusive, RangeToInclusive}; // endregion:range + + // region:fn + mod function { + #[lang = "fn"] + #[fundamental] + pub trait Fn: FnMut {} + + #[lang = "fn_mut"] + #[fundamental] + pub trait FnMut: FnOnce {} + + #[lang = "fn_once"] + #[fundamental] + pub trait FnOnce { + #[lang = "fn_once_output"] + type Output; + } + } + pub use self::function::{Fn, FnMut, FnOnce}; + // endregion:fn } // region:slice @@ -189,6 +210,7 @@ pub mod prelude { pub mod v1 { pub use crate::{ marker::Sized, // :sized + ops::{Fn, FnMut, FnOnce}, // :fn option::Option::{self, None, Some}, // :option result::Result::{self, Err, Ok}, // :result }; -- cgit v1.2.3