minor: use minicore

This commit is contained in:
Aleksey Kladov 2021-06-18 23:33:01 +03:00
parent 181184a350
commit cc73abf72c
3 changed files with 13 additions and 85 deletions

View File

@ -908,9 +908,7 @@ fn main() {
fn unit_structs_have_no_type_hints() { fn unit_structs_have_no_type_hints() {
check_types( check_types(
r#" r#"
enum Result<T, E> { Ok(T), Err(E) } //- minicore: result
use Result::*;
struct SyntheticSyntax; struct SyntheticSyntax;
fn main() { fn main() {

View File

@ -436,18 +436,15 @@ fn main() {
check_edit( check_edit(
"ifl", "ifl",
r#" r#"
enum Option<T> { Some(T), None } //- minicore: option
fn main() { fn main() {
let bar = Option::Some(true); let bar = Some(true);
bar.$0 bar.$0
} }
"#, "#,
r#" r#"
enum Option<T> { Some(T), None }
fn main() { fn main() {
let bar = Option::Some(true); let bar = Some(true);
if let Some($1) = bar { if let Some($1) = bar {
$0 $0
} }
@ -461,18 +458,15 @@ fn main() {
check_edit( check_edit(
"match", "match",
r#" r#"
enum Result<T, E> { Ok(T), Err(E) } //- minicore: result
fn main() { fn main() {
let bar = Result::Ok(true); let bar = Ok(true);
bar.$0 bar.$0
} }
"#, "#,
r#" r#"
enum Result<T, E> { Ok(T), Err(E) }
fn main() { fn main() {
let bar = Result::Ok(true); let bar = Ok(true);
match bar { match bar {
Ok(${1:_}) => {$2}, Ok(${1:_}) => {$2},
Err(${3:_}) => {$0}, Err(${3:_}) => {$0},

View File

@ -49,26 +49,15 @@ mod tests {
fn test_wrap_return_type_option() { fn test_wrap_return_type_option() {
check_fix( check_fix(
r#" r#"
//- /main.rs crate:main deps:core //- minicore: option, result
use core::option::Option::{self, Some, None};
fn div(x: i32, y: i32) -> Option<i32> { fn div(x: i32, y: i32) -> Option<i32> {
if y == 0 { if y == 0 {
return None; return None;
} }
x / y$0 x / y$0
} }
//- /core/lib.rs crate:core
pub mod result {
pub enum Result<T, E> { Ok(T), Err(E) }
}
pub mod option {
pub enum Option<T> { Some(T), None }
}
"#, "#,
r#" r#"
use core::option::Option::{self, Some, None};
fn div(x: i32, y: i32) -> Option<i32> { fn div(x: i32, y: i32) -> Option<i32> {
if y == 0 { if y == 0 {
return None; return None;
@ -83,26 +72,15 @@ fn div(x: i32, y: i32) -> Option<i32> {
fn test_wrap_return_type() { fn test_wrap_return_type() {
check_fix( check_fix(
r#" r#"
//- /main.rs crate:main deps:core //- minicore: option, result
use core::result::Result::{self, Ok, Err};
fn div(x: i32, y: i32) -> Result<i32, ()> { fn div(x: i32, y: i32) -> Result<i32, ()> {
if y == 0 { if y == 0 {
return Err(()); return Err(());
} }
x / y$0 x / y$0
} }
//- /core/lib.rs crate:core
pub mod result {
pub enum Result<T, E> { Ok(T), Err(E) }
}
pub mod option {
pub enum Option<T> { Some(T), None }
}
"#, "#,
r#" r#"
use core::result::Result::{self, Ok, Err};
fn div(x: i32, y: i32) -> Result<i32, ()> { fn div(x: i32, y: i32) -> Result<i32, ()> {
if y == 0 { if y == 0 {
return Err(()); return Err(());
@ -117,26 +95,15 @@ fn div(x: i32, y: i32) -> Result<i32, ()> {
fn test_wrap_return_type_handles_generic_functions() { fn test_wrap_return_type_handles_generic_functions() {
check_fix( check_fix(
r#" r#"
//- /main.rs crate:main deps:core //- minicore: option, result
use core::result::Result::{self, Ok, Err};
fn div<T>(x: T) -> Result<T, i32> { fn div<T>(x: T) -> Result<T, i32> {
if x == 0 { if x == 0 {
return Err(7); return Err(7);
} }
$0x $0x
} }
//- /core/lib.rs crate:core
pub mod result {
pub enum Result<T, E> { Ok(T), Err(E) }
}
pub mod option {
pub enum Option<T> { Some(T), None }
}
"#, "#,
r#" r#"
use core::result::Result::{self, Ok, Err};
fn div<T>(x: T) -> Result<T, i32> { fn div<T>(x: T) -> Result<T, i32> {
if x == 0 { if x == 0 {
return Err(7); return Err(7);
@ -151,9 +118,7 @@ fn div<T>(x: T) -> Result<T, i32> {
fn test_wrap_return_type_handles_type_aliases() { fn test_wrap_return_type_handles_type_aliases() {
check_fix( check_fix(
r#" r#"
//- /main.rs crate:main deps:core //- minicore: option, result
use core::result::Result::{self, Ok, Err};
type MyResult<T> = Result<T, ()>; type MyResult<T> = Result<T, ()>;
fn div(x: i32, y: i32) -> MyResult<i32> { fn div(x: i32, y: i32) -> MyResult<i32> {
@ -162,17 +127,8 @@ fn div(x: i32, y: i32) -> MyResult<i32> {
} }
x $0/ y x $0/ y
} }
//- /core/lib.rs crate:core
pub mod result {
pub enum Result<T, E> { Ok(T), Err(E) }
}
pub mod option {
pub enum Option<T> { Some(T), None }
}
"#, "#,
r#" r#"
use core::result::Result::{self, Ok, Err};
type MyResult<T> = Result<T, ()>; type MyResult<T> = Result<T, ()>;
fn div(x: i32, y: i32) -> MyResult<i32> { fn div(x: i32, y: i32) -> MyResult<i32> {
@ -189,18 +145,8 @@ fn div(x: i32, y: i32) -> MyResult<i32> {
fn test_wrap_return_type_not_applicable_when_expr_type_does_not_match_ok_type() { fn test_wrap_return_type_not_applicable_when_expr_type_does_not_match_ok_type() {
check_diagnostics( check_diagnostics(
r#" r#"
//- /main.rs crate:main deps:core //- minicore: option, result
use core::result::Result::{self, Ok, Err};
fn foo() -> Result<(), i32> { 0 } fn foo() -> Result<(), i32> { 0 }
//- /core/lib.rs crate:core
pub mod result {
pub enum Result<T, E> { Ok(T), Err(E) }
}
pub mod option {
pub enum Option<T> { 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() { fn test_wrap_return_type_not_applicable_when_return_type_is_not_result_or_option() {
check_diagnostics( check_diagnostics(
r#" r#"
//- /main.rs crate:main deps:core //- minicore: option, result
use core::result::Result::{self, Ok, Err};
enum SomeOtherEnum { Ok(i32), Err(String) } enum SomeOtherEnum { Ok(i32), Err(String) }
fn foo() -> SomeOtherEnum { 0 } fn foo() -> SomeOtherEnum { 0 }
//- /core/lib.rs crate:core
pub mod result {
pub enum Result<T, E> { Ok(T), Err(E) }
}
pub mod option {
pub enum Option<T> { Some(T), None }
}
"#, "#,
); );
} }