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/ide_completion/src/render.rs | 22 +++++---------- crates/test_utils/src/fixture.rs | 54 ++++++++++++++++++++++++------------- crates/test_utils/src/minicore.rs | 8 ++++++ 3 files changed, 49 insertions(+), 35 deletions(-) diff --git a/crates/ide_completion/src/render.rs b/crates/ide_completion/src/render.rs index 3eb51e80b..fac83b650 100644 --- a/crates/ide_completion/src/render.rs +++ b/crates/ide_completion/src/render.rs @@ -1191,21 +1191,11 @@ fn main() { fn suggest_deref_mut() { check_relevance( r#" -#[lang = "deref"] -trait Deref { - type Target; - fn deref(&self) -> &Self::Target; -} - -#[lang = "deref_mut"] -pub trait DerefMut: Deref { - fn deref_mut(&mut self) -> &mut Self::Target; -} - +//- minicore: deref_mut struct S; struct T(S); -impl Deref for T { +impl core::ops::Deref for T { type Target = S; fn deref(&self) -> &Self::Target { @@ -1213,7 +1203,7 @@ impl Deref for T { } } -impl DerefMut for T { +impl core::ops::DerefMut for T { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } @@ -1232,12 +1222,12 @@ fn main() { lc m [local] lc t [local] lc &mut t [type+local] - tt DerefMut [] - tt Deref [] - fn foo(…) [] st T [] st S [] fn main() [] + fn foo(…) [] + md core [] + tt Sized [] "#]], ) } 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