From f64aacc0c1d3743f08a3be41562e4aab46f47871 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Sun, 8 Aug 2021 18:58:42 +0200 Subject: [PATCH] Use minicore --- crates/ide/src/hover.rs | 4 +- .../replace_derive_with_manual_impl.rs | 95 +++---------------- crates/test_utils/src/minicore.rs | 12 +++ 3 files changed, 27 insertions(+), 84 deletions(-) diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index 6789abfb0a7..a9e2b526394 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs @@ -2732,8 +2732,8 @@ fn foo() { file_id: FileId( 1, ), - full_range: 251..433, - focus_range: 290..296, + full_range: 252..434, + focus_range: 291..297, name: "Future", kind: Trait, description: "pub trait Future", diff --git a/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs b/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs index c842d3aa11e..009014396ca 100644 --- a/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs +++ b/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs @@ -304,36 +304,19 @@ mod tests { check_assist( replace_derive_with_manual_impl, r#" -mod fmt { - pub struct Error; - pub type Result = Result<(), Error>; - pub struct Formatter<'a>; - pub trait Debug { - fn fmt(&self, f: &mut Formatter<'_>) -> Result; - } -} - +//- minicore: fmt #[derive(Debu$0g)] struct Foo { bar: String, } "#, r#" -mod fmt { - pub struct Error; - pub type Result = Result<(), Error>; - pub struct Formatter<'a>; - pub trait Debug { - fn fmt(&self, f: &mut Formatter<'_>) -> Result; - } -} - struct Foo { bar: String, } -impl fmt::Debug for Foo { - $0fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { +impl core::fmt::Debug for Foo { + $0fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_struct("Foo").field("bar", &self.bar).finish() } } @@ -345,32 +328,14 @@ impl fmt::Debug for Foo { check_assist( replace_derive_with_manual_impl, r#" -mod fmt { - pub struct Error; - pub type Result = Result<(), Error>; - pub struct Formatter<'a>; - pub trait Debug { - fn fmt(&self, f: &mut Formatter<'_>) -> Result; - } -} - +//- minicore: fmt #[derive(Debu$0g)] struct Foo(String, usize); "#, - r#" -mod fmt { - pub struct Error; - pub type Result = Result<(), Error>; - pub struct Formatter<'a>; - pub trait Debug { - fn fmt(&self, f: &mut Formatter<'_>) -> Result; - } -} + r#"struct Foo(String, usize); -struct Foo(String, usize); - -impl fmt::Debug for Foo { - $0fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { +impl core::fmt::Debug for Foo { + $0fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_tuple("Foo").field(&self.0).field(&self.1).finish() } } @@ -382,32 +347,15 @@ impl fmt::Debug for Foo { check_assist( replace_derive_with_manual_impl, r#" -mod fmt { - pub struct Error; - pub type Result = Result<(), Error>; - pub struct Formatter<'a>; - pub trait Debug { - fn fmt(&self, f: &mut Formatter<'_>) -> Result; - } -} - +//- minicore: fmt #[derive(Debu$0g)] struct Foo; "#, r#" -mod fmt { - pub struct Error; - pub type Result = Result<(), Error>; - pub struct Formatter<'a>; - pub trait Debug { - fn fmt(&self, f: &mut Formatter<'_>) -> Result; - } -} - struct Foo; -impl fmt::Debug for Foo { - $0fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { +impl core::fmt::Debug for Foo { + $0fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_struct("Foo").finish() } } @@ -419,15 +367,7 @@ impl fmt::Debug for Foo { check_assist( replace_derive_with_manual_impl, r#" -mod fmt { - pub struct Error; - pub type Result = Result<(), Error>; - pub struct Formatter<'a>; - pub trait Debug { - fn fmt(&self, f: &mut Formatter<'_>) -> Result; - } -} - +//- minicore: fmt #[derive(Debu$0g)] enum Foo { Bar, @@ -435,22 +375,13 @@ enum Foo { } "#, r#" -mod fmt { - pub struct Error; - pub type Result = Result<(), Error>; - pub struct Formatter<'a>; - pub trait Debug { - fn fmt(&self, f: &mut Formatter<'_>) -> Result; - } -} - enum Foo { Bar, Baz, } -impl fmt::Debug for Foo { - $0fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { +impl core::fmt::Debug for Foo { + $0fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { Self::Bar => write!(f, "Bar"), Self::Baz => write!(f, "Baz"), diff --git a/crates/test_utils/src/minicore.rs b/crates/test_utils/src/minicore.rs index 2532738562b..eeadf2bee2e 100644 --- a/crates/test_utils/src/minicore.rs +++ b/crates/test_utils/src/minicore.rs @@ -31,6 +31,7 @@ //! eq: sized //! ord: eq, option //! derive: +//! fmt: pub mod marker { // region:sized @@ -334,6 +335,17 @@ pub mod cmp { } // endregion:eq +// region:fmt +pub mod fmt { + pub struct Error; + pub type Result = Result<(), Error>; + pub struct Formatter<'a>; + pub trait Debug { + fn fmt(&self, f: &mut Formatter<'_>) -> Result; + } +} +// endregion:fmt + // region:slice pub mod slice { #[lang = "slice"]