From cc73abf72c46d9f13a176d93d1d38f3a72d638e3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 18 Jun 2021 23:33:01 +0300 Subject: minor: use minicore --- crates/ide/src/inlay_hints.rs | 4 +- crates/ide_completion/src/completions/postfix.rs | 18 ++--- .../handlers/missing_ok_or_some_in_tail_expr.rs | 76 ++-------------------- 3 files changed, 13 insertions(+), 85 deletions(-) (limited to 'crates') diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs index 335d57a0d..48bab0b2e 100644 --- a/crates/ide/src/inlay_hints.rs +++ b/crates/ide/src/inlay_hints.rs @@ -908,9 +908,7 @@ fn main() { fn unit_structs_have_no_type_hints() { check_types( r#" -enum Result { Ok(T), Err(E) } -use Result::*; - +//- minicore: result struct SyntheticSyntax; fn main() { diff --git a/crates/ide_completion/src/completions/postfix.rs b/crates/ide_completion/src/completions/postfix.rs index c3c7e4589..c11deebcb 100644 --- a/crates/ide_completion/src/completions/postfix.rs +++ b/crates/ide_completion/src/completions/postfix.rs @@ -436,18 +436,15 @@ fn main() { check_edit( "ifl", r#" -enum Option { Some(T), None } - +//- minicore: option fn main() { - let bar = Option::Some(true); + let bar = Some(true); bar.$0 } "#, r#" -enum Option { Some(T), None } - fn main() { - let bar = Option::Some(true); + let bar = Some(true); if let Some($1) = bar { $0 } @@ -461,18 +458,15 @@ fn main() { check_edit( "match", r#" -enum Result { Ok(T), Err(E) } - +//- minicore: result fn main() { - let bar = Result::Ok(true); + let bar = Ok(true); bar.$0 } "#, r#" -enum Result { Ok(T), Err(E) } - fn main() { - let bar = Result::Ok(true); + let bar = Ok(true); match bar { Ok(${1:_}) => {$2}, Err(${3:_}) => {$0}, diff --git a/crates/ide_diagnostics/src/handlers/missing_ok_or_some_in_tail_expr.rs b/crates/ide_diagnostics/src/handlers/missing_ok_or_some_in_tail_expr.rs index 63de54570..c0edcd7d3 100644 --- a/crates/ide_diagnostics/src/handlers/missing_ok_or_some_in_tail_expr.rs +++ b/crates/ide_diagnostics/src/handlers/missing_ok_or_some_in_tail_expr.rs @@ -49,26 +49,15 @@ mod tests { fn test_wrap_return_type_option() { check_fix( r#" -//- /main.rs crate:main deps:core -use core::option::Option::{self, Some, None}; - +//- minicore: option, result fn div(x: i32, y: i32) -> Option { if y == 0 { return None; } x / y$0 } -//- /core/lib.rs crate:core -pub mod result { - pub enum Result { Ok(T), Err(E) } -} -pub mod option { - pub enum Option { Some(T), None } -} "#, r#" -use core::option::Option::{self, Some, None}; - fn div(x: i32, y: i32) -> Option { if y == 0 { return None; @@ -83,26 +72,15 @@ fn div(x: i32, y: i32) -> Option { fn test_wrap_return_type() { check_fix( r#" -//- /main.rs crate:main deps:core -use core::result::Result::{self, Ok, Err}; - +//- minicore: option, result fn div(x: i32, y: i32) -> Result { if y == 0 { return Err(()); } x / y$0 } -//- /core/lib.rs crate:core -pub mod result { - pub enum Result { Ok(T), Err(E) } -} -pub mod option { - pub enum Option { Some(T), None } -} "#, r#" -use core::result::Result::{self, Ok, Err}; - fn div(x: i32, y: i32) -> Result { if y == 0 { return Err(()); @@ -117,26 +95,15 @@ fn div(x: i32, y: i32) -> Result { fn test_wrap_return_type_handles_generic_functions() { check_fix( r#" -//- /main.rs crate:main deps:core -use core::result::Result::{self, Ok, Err}; - +//- minicore: option, result fn div(x: T) -> Result { if x == 0 { return Err(7); } $0x } -//- /core/lib.rs crate:core -pub mod result { - pub enum Result { Ok(T), Err(E) } -} -pub mod option { - pub enum Option { Some(T), None } -} "#, r#" -use core::result::Result::{self, Ok, Err}; - fn div(x: T) -> Result { if x == 0 { return Err(7); @@ -151,9 +118,7 @@ fn div(x: T) -> Result { fn test_wrap_return_type_handles_type_aliases() { check_fix( r#" -//- /main.rs crate:main deps:core -use core::result::Result::{self, Ok, Err}; - +//- minicore: option, result type MyResult = Result; fn div(x: i32, y: i32) -> MyResult { @@ -162,17 +127,8 @@ fn div(x: i32, y: i32) -> MyResult { } x $0/ y } -//- /core/lib.rs crate:core -pub mod result { - pub enum Result { Ok(T), Err(E) } -} -pub mod option { - pub enum Option { Some(T), None } -} "#, r#" -use core::result::Result::{self, Ok, Err}; - type MyResult = Result; fn div(x: i32, y: i32) -> MyResult { @@ -189,18 +145,8 @@ fn div(x: i32, y: i32) -> MyResult { fn test_wrap_return_type_not_applicable_when_expr_type_does_not_match_ok_type() { check_diagnostics( r#" -//- /main.rs crate:main deps:core -use core::result::Result::{self, Ok, Err}; - +//- minicore: option, result fn foo() -> Result<(), i32> { 0 } - -//- /core/lib.rs crate:core -pub mod result { - pub enum Result { Ok(T), Err(E) } -} -pub mod option { - pub enum Option { Some(T), None } -} "#, ); } @@ -209,20 +155,10 @@ pub mod option { fn test_wrap_return_type_not_applicable_when_return_type_is_not_result_or_option() { check_diagnostics( r#" -//- /main.rs crate:main deps:core -use core::result::Result::{self, Ok, Err}; - +//- minicore: option, result enum SomeOtherEnum { Ok(i32), Err(String) } fn foo() -> SomeOtherEnum { 0 } - -//- /core/lib.rs crate:core -pub mod result { - pub enum Result { Ok(T), Err(E) } -} -pub mod option { - pub enum Option { Some(T), None } -} "#, ); } -- cgit v1.2.3