From 181184a350046a460441209fd34821c2c796b066 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 18 Jun 2021 23:28:37 +0300 Subject: minor: use minicore --- .../src/handlers/replace_if_let_with_match.rs | 66 ++++++---------------- .../src/handlers/replace_unwrap_with_match.rs | 53 ++++++++--------- 2 files changed, 43 insertions(+), 76 deletions(-) (limited to 'crates/ide_assists') diff --git a/crates/ide_assists/src/handlers/replace_if_let_with_match.rs b/crates/ide_assists/src/handlers/replace_if_let_with_match.rs index 9404aa26d..f37aa0d53 100644 --- a/crates/ide_assists/src/handlers/replace_if_let_with_match.rs +++ b/crates/ide_assists/src/handlers/replace_if_let_with_match.rs @@ -262,9 +262,7 @@ impl VariantData { check_assist( replace_if_let_with_match, r#" -enum Option { Some(T), None } -use Option::*; - +//- minicore: option fn foo(x: Option) { $0if let Some(x) = x { println!("{}", x) @@ -272,18 +270,15 @@ fn foo(x: Option) { println!("none") } } - "#, +"#, r#" -enum Option { Some(T), None } -use Option::*; - fn foo(x: Option) { match x { Some(x) => println!("{}", x), None => println!("none"), } } - "#, +"#, ); } @@ -292,9 +287,7 @@ fn foo(x: Option) { check_assist( replace_if_let_with_match, r#" -enum Option { Some(T), None } -use Option::*; - +//- minicore: option fn foo(x: Option) { $0if let None = x { println!("none") @@ -302,18 +295,15 @@ fn foo(x: Option) { println!("some") } } - "#, +"#, r#" -enum Option { Some(T), None } -use Option::*; - fn foo(x: Option) { match x { None => println!("none"), Some(_) => println!("some"), } } - "#, +"#, ); } @@ -322,9 +312,7 @@ fn foo(x: Option) { check_assist( replace_if_let_with_match, r#" -enum Result { Ok(T), Err(E) } -use Result::*; - +//- minicore: result fn foo(x: Result) { $0if let Ok(x) = x { println!("{}", x) @@ -332,18 +320,15 @@ fn foo(x: Result) { println!("none") } } - "#, +"#, r#" -enum Result { Ok(T), Err(E) } -use Result::*; - fn foo(x: Result) { match x { Ok(x) => println!("{}", x), Err(_) => println!("none"), } } - "#, +"#, ); } @@ -352,9 +337,7 @@ fn foo(x: Result) { check_assist( replace_if_let_with_match, r#" -enum Result { Ok(T), Err(E) } -use Result::*; - +//- minicore: result fn foo(x: Result) { $0if let Err(x) = x { println!("{}", x) @@ -362,18 +345,15 @@ fn foo(x: Result) { println!("ok") } } - "#, +"#, r#" -enum Result { Ok(T), Err(E) } -use Result::*; - fn foo(x: Result) { match x { Err(x) => println!("{}", x), Ok(_) => println!("ok"), } } - "#, +"#, ); } @@ -488,20 +468,15 @@ impl VariantData { check_assist( replace_match_with_if_let, r#" -enum Option { Some(T), None } -use Option::*; - +//- minicore: option fn foo(x: Option) { $0match x { Some(x) => println!("{}", x), None => println!("none"), } } - "#, +"#, r#" -enum Option { Some(T), None } -use Option::*; - fn foo(x: Option) { if let Some(x) = x { println!("{}", x) @@ -509,7 +484,7 @@ fn foo(x: Option) { println!("none") } } - "#, +"#, ); } @@ -518,20 +493,15 @@ fn foo(x: Option) { check_assist( replace_match_with_if_let, r#" -enum Result { Ok(T), Err(E) } -use Result::*; - +//- minicore: result fn foo(x: Result) { $0match x { Ok(x) => println!("{}", x), Err(_) => println!("none"), } } - "#, +"#, r#" -enum Result { Ok(T), Err(E) } -use Result::*; - fn foo(x: Result) { if let Ok(x) = x { println!("{}", x) @@ -539,7 +509,7 @@ fn foo(x: Result) { println!("none") } } - "#, +"#, ); } diff --git a/crates/ide_assists/src/handlers/replace_unwrap_with_match.rs b/crates/ide_assists/src/handlers/replace_unwrap_with_match.rs index a3bfa221c..7e57353c6 100644 --- a/crates/ide_assists/src/handlers/replace_unwrap_with_match.rs +++ b/crates/ide_assists/src/handlers/replace_unwrap_with_match.rs @@ -97,25 +97,24 @@ mod tests { fn test_replace_result_unwrap_with_match() { check_assist( replace_unwrap_with_match, - r" -enum Result { Ok(T), Err(E) } + r#" +//- minicore: result fn i(a: T) -> T { a } fn main() { - let x: Result = Result::Ok(92); + let x: Result = Ok(92); let y = i(x).$0unwrap(); } - ", - r" -enum Result { Ok(T), Err(E) } +"#, + r#" fn i(a: T) -> T { a } fn main() { - let x: Result = Result::Ok(92); + let x: Result = Ok(92); let y = match i(x) { Ok(it) => it, $0_ => unreachable!(), }; } - ", +"#, ) } @@ -123,25 +122,24 @@ fn main() { fn test_replace_option_unwrap_with_match() { check_assist( replace_unwrap_with_match, - r" -enum Option { Some(T), None } + r#" +//- minicore: option fn i(a: T) -> T { a } fn main() { - let x = Option::Some(92); + let x = Some(92); let y = i(x).$0unwrap(); } - ", - r" -enum Option { Some(T), None } +"#, + r#" fn i(a: T) -> T { a } fn main() { - let x = Option::Some(92); + let x = Some(92); let y = match i(x) { Some(it) => it, $0_ => unreachable!(), }; } - ", +"#, ); } @@ -149,25 +147,24 @@ fn main() { fn test_replace_result_unwrap_with_match_chaining() { check_assist( replace_unwrap_with_match, - r" -enum Result { Ok(T), Err(E) } + r#" +//- minicore: result fn i(a: T) -> T { a } fn main() { - let x: Result = Result::Ok(92); + let x: Result = Ok(92); let y = i(x).$0unwrap().count_zeroes(); } - ", - r" -enum Result { Ok(T), Err(E) } +"#, + r#" fn i(a: T) -> T { a } fn main() { - let x: Result = Result::Ok(92); + let x: Result = Ok(92); let y = match i(x) { Ok(it) => it, $0_ => unreachable!(), }.count_zeroes(); } - ", +"#, ) } @@ -175,14 +172,14 @@ fn main() { fn replace_unwrap_with_match_target() { check_assist_target( replace_unwrap_with_match, - r" -enum Option { Some(T), None } + r#" +//- minicore: option fn i(a: T) -> T { a } fn main() { - let x = Option::Some(92); + let x = Some(92); let y = i(x).$0unwrap(); } - ", +"#, r"i(x).unwrap()", ); } -- cgit v1.2.3