mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-16 17:58:16 +00:00
Merge #9332
9332: minor: use minicore r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
664912fbf8
8 changed files with 109 additions and 257 deletions
|
@ -661,9 +661,7 @@ fn main() {
|
|||
fn function_call_parameter_hint() {
|
||||
check_params(
|
||||
r#"
|
||||
enum Option<T> { None, Some(T) }
|
||||
use Option::*;
|
||||
|
||||
//- minicore: option
|
||||
struct FileId {}
|
||||
struct SmolStr {}
|
||||
|
||||
|
@ -872,7 +870,6 @@ fn main() {
|
|||
check_types(
|
||||
r#"
|
||||
//- minicore: fn, sized
|
||||
|
||||
fn foo() -> impl Fn() { loop {} }
|
||||
fn foo1() -> impl Fn(f64) { loop {} }
|
||||
fn foo2() -> impl Fn(f64, f64) { loop {} }
|
||||
|
@ -908,9 +905,7 @@ fn main() {
|
|||
fn unit_structs_have_no_type_hints() {
|
||||
check_types(
|
||||
r#"
|
||||
enum Result<T, E> { Ok(T), Err(E) }
|
||||
use Result::*;
|
||||
|
||||
//- minicore: result
|
||||
struct SyntheticSyntax;
|
||||
|
||||
fn main() {
|
||||
|
@ -962,9 +957,7 @@ fn main() {
|
|||
fn if_expr() {
|
||||
check_types(
|
||||
r#"
|
||||
enum Option<T> { None, Some(T) }
|
||||
use Option::*;
|
||||
|
||||
//- minicore: option
|
||||
struct Test { a: Option<u32>, b: u8 }
|
||||
|
||||
fn main() {
|
||||
|
@ -994,9 +987,7 @@ fn main() {
|
|||
fn while_expr() {
|
||||
check_types(
|
||||
r#"
|
||||
enum Option<T> { None, Some(T) }
|
||||
use Option::*;
|
||||
|
||||
//- minicore: option
|
||||
struct Test { a: Option<u32>, b: u8 }
|
||||
|
||||
fn main() {
|
||||
|
@ -1012,9 +1003,7 @@ fn main() {
|
|||
fn match_arm_list() {
|
||||
check_types(
|
||||
r#"
|
||||
enum Option<T> { None, Some(T) }
|
||||
use Option::*;
|
||||
|
||||
//- minicore: option
|
||||
struct Test { a: Option<u32>, b: u8 }
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -481,26 +481,21 @@ fn main() {
|
|||
check_assist(
|
||||
fill_match_arms,
|
||||
r#"
|
||||
enum Option<T> { Some(T), None }
|
||||
use Option::*;
|
||||
|
||||
//- minicore: option
|
||||
fn main() {
|
||||
match None$0 {
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
"#,
|
||||
"#,
|
||||
r#"
|
||||
enum Option<T> { Some(T), None }
|
||||
use Option::*;
|
||||
|
||||
fn main() {
|
||||
match None {
|
||||
None => {}
|
||||
Some(${0:_}) => todo!(),
|
||||
}
|
||||
}
|
||||
"#,
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -262,9 +262,7 @@ impl VariantData {
|
|||
check_assist(
|
||||
replace_if_let_with_match,
|
||||
r#"
|
||||
enum Option<T> { Some(T), None }
|
||||
use Option::*;
|
||||
|
||||
//- minicore: option
|
||||
fn foo(x: Option<i32>) {
|
||||
$0if let Some(x) = x {
|
||||
println!("{}", x)
|
||||
|
@ -272,18 +270,15 @@ fn foo(x: Option<i32>) {
|
|||
println!("none")
|
||||
}
|
||||
}
|
||||
"#,
|
||||
"#,
|
||||
r#"
|
||||
enum Option<T> { Some(T), None }
|
||||
use Option::*;
|
||||
|
||||
fn foo(x: Option<i32>) {
|
||||
match x {
|
||||
Some(x) => println!("{}", x),
|
||||
None => println!("none"),
|
||||
}
|
||||
}
|
||||
"#,
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -292,9 +287,7 @@ fn foo(x: Option<i32>) {
|
|||
check_assist(
|
||||
replace_if_let_with_match,
|
||||
r#"
|
||||
enum Option<T> { Some(T), None }
|
||||
use Option::*;
|
||||
|
||||
//- minicore: option
|
||||
fn foo(x: Option<i32>) {
|
||||
$0if let None = x {
|
||||
println!("none")
|
||||
|
@ -302,18 +295,15 @@ fn foo(x: Option<i32>) {
|
|||
println!("some")
|
||||
}
|
||||
}
|
||||
"#,
|
||||
"#,
|
||||
r#"
|
||||
enum Option<T> { Some(T), None }
|
||||
use Option::*;
|
||||
|
||||
fn foo(x: Option<i32>) {
|
||||
match x {
|
||||
None => println!("none"),
|
||||
Some(_) => println!("some"),
|
||||
}
|
||||
}
|
||||
"#,
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -322,9 +312,7 @@ fn foo(x: Option<i32>) {
|
|||
check_assist(
|
||||
replace_if_let_with_match,
|
||||
r#"
|
||||
enum Result<T, E> { Ok(T), Err(E) }
|
||||
use Result::*;
|
||||
|
||||
//- minicore: result
|
||||
fn foo(x: Result<i32, ()>) {
|
||||
$0if let Ok(x) = x {
|
||||
println!("{}", x)
|
||||
|
@ -332,18 +320,15 @@ fn foo(x: Result<i32, ()>) {
|
|||
println!("none")
|
||||
}
|
||||
}
|
||||
"#,
|
||||
"#,
|
||||
r#"
|
||||
enum Result<T, E> { Ok(T), Err(E) }
|
||||
use Result::*;
|
||||
|
||||
fn foo(x: Result<i32, ()>) {
|
||||
match x {
|
||||
Ok(x) => println!("{}", x),
|
||||
Err(_) => println!("none"),
|
||||
}
|
||||
}
|
||||
"#,
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -352,9 +337,7 @@ fn foo(x: Result<i32, ()>) {
|
|||
check_assist(
|
||||
replace_if_let_with_match,
|
||||
r#"
|
||||
enum Result<T, E> { Ok(T), Err(E) }
|
||||
use Result::*;
|
||||
|
||||
//- minicore: result
|
||||
fn foo(x: Result<i32, ()>) {
|
||||
$0if let Err(x) = x {
|
||||
println!("{}", x)
|
||||
|
@ -362,18 +345,15 @@ fn foo(x: Result<i32, ()>) {
|
|||
println!("ok")
|
||||
}
|
||||
}
|
||||
"#,
|
||||
"#,
|
||||
r#"
|
||||
enum Result<T, E> { Ok(T), Err(E) }
|
||||
use Result::*;
|
||||
|
||||
fn foo(x: Result<i32, ()>) {
|
||||
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<T> { Some(T), None }
|
||||
use Option::*;
|
||||
|
||||
//- minicore: option
|
||||
fn foo(x: Option<i32>) {
|
||||
$0match x {
|
||||
Some(x) => println!("{}", x),
|
||||
None => println!("none"),
|
||||
}
|
||||
}
|
||||
"#,
|
||||
"#,
|
||||
r#"
|
||||
enum Option<T> { Some(T), None }
|
||||
use Option::*;
|
||||
|
||||
fn foo(x: Option<i32>) {
|
||||
if let Some(x) = x {
|
||||
println!("{}", x)
|
||||
|
@ -509,7 +484,7 @@ fn foo(x: Option<i32>) {
|
|||
println!("none")
|
||||
}
|
||||
}
|
||||
"#,
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -518,20 +493,15 @@ fn foo(x: Option<i32>) {
|
|||
check_assist(
|
||||
replace_match_with_if_let,
|
||||
r#"
|
||||
enum Result<T, E> { Ok(T), Err(E) }
|
||||
use Result::*;
|
||||
|
||||
//- minicore: result
|
||||
fn foo(x: Result<i32, ()>) {
|
||||
$0match x {
|
||||
Ok(x) => println!("{}", x),
|
||||
Err(_) => println!("none"),
|
||||
}
|
||||
}
|
||||
"#,
|
||||
"#,
|
||||
r#"
|
||||
enum Result<T, E> { Ok(T), Err(E) }
|
||||
use Result::*;
|
||||
|
||||
fn foo(x: Result<i32, ()>) {
|
||||
if let Ok(x) = x {
|
||||
println!("{}", x)
|
||||
|
@ -539,7 +509,7 @@ fn foo(x: Result<i32, ()>) {
|
|||
println!("none")
|
||||
}
|
||||
}
|
||||
"#,
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -97,25 +97,24 @@ mod tests {
|
|||
fn test_replace_result_unwrap_with_match() {
|
||||
check_assist(
|
||||
replace_unwrap_with_match,
|
||||
r"
|
||||
enum Result<T, E> { Ok(T), Err(E) }
|
||||
r#"
|
||||
//- minicore: result
|
||||
fn i<T>(a: T) -> T { a }
|
||||
fn main() {
|
||||
let x: Result<i32, i32> = Result::Ok(92);
|
||||
let x: Result<i32, i32> = Ok(92);
|
||||
let y = i(x).$0unwrap();
|
||||
}
|
||||
",
|
||||
r"
|
||||
enum Result<T, E> { Ok(T), Err(E) }
|
||||
"#,
|
||||
r#"
|
||||
fn i<T>(a: T) -> T { a }
|
||||
fn main() {
|
||||
let x: Result<i32, i32> = Result::Ok(92);
|
||||
let x: Result<i32, i32> = 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<T> { Some(T), None }
|
||||
r#"
|
||||
//- minicore: option
|
||||
fn i<T>(a: T) -> T { a }
|
||||
fn main() {
|
||||
let x = Option::Some(92);
|
||||
let x = Some(92);
|
||||
let y = i(x).$0unwrap();
|
||||
}
|
||||
",
|
||||
r"
|
||||
enum Option<T> { Some(T), None }
|
||||
"#,
|
||||
r#"
|
||||
fn i<T>(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<T, E> { Ok(T), Err(E) }
|
||||
r#"
|
||||
//- minicore: result
|
||||
fn i<T>(a: T) -> T { a }
|
||||
fn main() {
|
||||
let x: Result<i32, i32> = Result::Ok(92);
|
||||
let x: Result<i32, i32> = Ok(92);
|
||||
let y = i(x).$0unwrap().count_zeroes();
|
||||
}
|
||||
",
|
||||
r"
|
||||
enum Result<T, E> { Ok(T), Err(E) }
|
||||
"#,
|
||||
r#"
|
||||
fn i<T>(a: T) -> T { a }
|
||||
fn main() {
|
||||
let x: Result<i32, i32> = Result::Ok(92);
|
||||
let x: Result<i32, i32> = 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<T> { Some(T), None }
|
||||
r#"
|
||||
//- minicore: option
|
||||
fn i<T>(a: T) -> T { a }
|
||||
fn main() {
|
||||
let x = Option::Some(92);
|
||||
let x = Some(92);
|
||||
let y = i(x).$0unwrap();
|
||||
}
|
||||
",
|
||||
"#,
|
||||
r"i(x).unwrap()",
|
||||
);
|
||||
}
|
||||
|
|
|
@ -436,18 +436,15 @@ fn main() {
|
|||
check_edit(
|
||||
"ifl",
|
||||
r#"
|
||||
enum Option<T> { Some(T), None }
|
||||
|
||||
//- minicore: option
|
||||
fn main() {
|
||||
let bar = Option::Some(true);
|
||||
let bar = Some(true);
|
||||
bar.$0
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
enum Option<T> { 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<T, E> { Ok(T), Err(E) }
|
||||
|
||||
//- minicore: result
|
||||
fn main() {
|
||||
let bar = Result::Ok(true);
|
||||
let bar = Ok(true);
|
||||
bar.$0
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
enum Result<T, E> { Ok(T), Err(E) }
|
||||
|
||||
fn main() {
|
||||
let bar = Result::Ok(true);
|
||||
let bar = Ok(true);
|
||||
match bar {
|
||||
Ok(${1:_}) => {$2},
|
||||
Err(${3:_}) => {$0},
|
||||
|
@ -515,18 +509,15 @@ fn main() {
|
|||
check_edit(
|
||||
"ifl",
|
||||
r#"
|
||||
enum Option<T> { Some(T), None }
|
||||
|
||||
//- minicore: option
|
||||
fn main() {
|
||||
let bar = &Option::Some(true);
|
||||
let bar = &Some(true);
|
||||
bar.$0
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
enum Option<T> { Some(T), None }
|
||||
|
||||
fn main() {
|
||||
let bar = &Option::Some(true);
|
||||
let bar = &Some(true);
|
||||
if let Some($1) = bar {
|
||||
$0
|
||||
}
|
||||
|
|
|
@ -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<i32> {
|
||||
if y == 0 {
|
||||
return None;
|
||||
}
|
||||
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#"
|
||||
use core::option::Option::{self, Some, None};
|
||||
|
||||
fn div(x: i32, y: i32) -> Option<i32> {
|
||||
if y == 0 {
|
||||
return None;
|
||||
|
@ -83,26 +72,15 @@ fn div(x: i32, y: i32) -> Option<i32> {
|
|||
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<i32, ()> {
|
||||
if y == 0 {
|
||||
return Err(());
|
||||
}
|
||||
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#"
|
||||
use core::result::Result::{self, Ok, Err};
|
||||
|
||||
fn div(x: i32, y: i32) -> Result<i32, ()> {
|
||||
if y == 0 {
|
||||
return Err(());
|
||||
|
@ -117,26 +95,15 @@ fn div(x: i32, y: i32) -> Result<i32, ()> {
|
|||
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<T>(x: T) -> Result<T, i32> {
|
||||
if x == 0 {
|
||||
return Err(7);
|
||||
}
|
||||
$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#"
|
||||
use core::result::Result::{self, Ok, Err};
|
||||
|
||||
fn div<T>(x: T) -> Result<T, i32> {
|
||||
if x == 0 {
|
||||
return Err(7);
|
||||
|
@ -151,9 +118,7 @@ fn div<T>(x: T) -> Result<T, i32> {
|
|||
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<T> = Result<T, ()>;
|
||||
|
||||
fn div(x: i32, y: i32) -> MyResult<i32> {
|
||||
|
@ -162,17 +127,8 @@ fn div(x: i32, y: i32) -> MyResult<i32> {
|
|||
}
|
||||
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#"
|
||||
use core::result::Result::{self, Ok, Err};
|
||||
|
||||
type MyResult<T> = Result<T, ()>;
|
||||
|
||||
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() {
|
||||
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<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() {
|
||||
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<T, E> { Ok(T), Err(E) }
|
||||
}
|
||||
pub mod option {
|
||||
pub enum Option<T> { Some(T), None }
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -55,44 +55,16 @@ fn fixes(
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::tests::check_fix;
|
||||
|
||||
// Register the required standard library types to make the tests work
|
||||
#[track_caller]
|
||||
fn check_diagnostics(ra_fixture: &str) {
|
||||
let prefix = r#"
|
||||
//- /main.rs crate:main deps:core
|
||||
use core::iter::Iterator;
|
||||
use core::option::Option::{self, Some, None};
|
||||
"#;
|
||||
let suffix = r#"
|
||||
//- /core/lib.rs crate:core
|
||||
pub mod option {
|
||||
pub enum Option<T> { Some(T), None }
|
||||
}
|
||||
pub mod iter {
|
||||
pub trait Iterator {
|
||||
type Item;
|
||||
fn filter_map<B, F>(self, f: F) -> FilterMap where F: FnMut(Self::Item) -> Option<B> { FilterMap }
|
||||
fn next(&mut self) -> Option<Self::Item>;
|
||||
}
|
||||
pub struct FilterMap {}
|
||||
impl Iterator for FilterMap {
|
||||
type Item = i32;
|
||||
fn next(&mut self) -> i32 { 7 }
|
||||
}
|
||||
}
|
||||
"#;
|
||||
crate::tests::check_diagnostics(&format!("{}{}{}", prefix, ra_fixture, suffix))
|
||||
}
|
||||
use crate::tests::{check_diagnostics, check_fix};
|
||||
|
||||
#[test]
|
||||
fn replace_filter_map_next_with_find_map2() {
|
||||
check_diagnostics(
|
||||
r#"
|
||||
fn foo() {
|
||||
let m = [1, 2, 3].iter().filter_map(|x| Some(92)).next();
|
||||
} //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 💡 weak: replace filter_map(..).next() with find_map(..)
|
||||
//- minicore: iterators
|
||||
fn foo() {
|
||||
let m = core::iter::repeat(()).filter_map(|()| Some(92)).next();
|
||||
} //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 💡 weak: replace filter_map(..).next() with find_map(..)
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
@ -101,11 +73,11 @@ pub mod iter {
|
|||
fn replace_filter_map_next_with_find_map_no_diagnostic_without_next() {
|
||||
check_diagnostics(
|
||||
r#"
|
||||
//- minicore: iterators
|
||||
fn foo() {
|
||||
let m = [1, 2, 3]
|
||||
.iter()
|
||||
.filter_map(|x| Some(92))
|
||||
.len();
|
||||
let m = core::iter::repeat(())
|
||||
.filter_map(|()| Some(92))
|
||||
.count();
|
||||
}
|
||||
"#,
|
||||
);
|
||||
|
@ -115,12 +87,12 @@ fn foo() {
|
|||
fn replace_filter_map_next_with_find_map_no_diagnostic_with_intervening_methods() {
|
||||
check_diagnostics(
|
||||
r#"
|
||||
//- minicore: iterators
|
||||
fn foo() {
|
||||
let m = [1, 2, 3]
|
||||
.iter()
|
||||
.filter_map(|x| Some(92))
|
||||
let m = core::iter::repeat(())
|
||||
.filter_map(|()| Some(92))
|
||||
.map(|x| x + 2)
|
||||
.len();
|
||||
.next();
|
||||
}
|
||||
"#,
|
||||
);
|
||||
|
@ -130,10 +102,10 @@ fn foo() {
|
|||
fn replace_filter_map_next_with_find_map_no_diagnostic_if_not_in_chain() {
|
||||
check_diagnostics(
|
||||
r#"
|
||||
//- minicore: iterators
|
||||
fn foo() {
|
||||
let m = [1, 2, 3]
|
||||
.iter()
|
||||
.filter_map(|x| Some(92));
|
||||
let m = core::iter::repeat(())
|
||||
.filter_map(|()| Some(92));
|
||||
let n = m.next();
|
||||
}
|
||||
"#,
|
||||
|
@ -144,34 +116,14 @@ fn foo() {
|
|||
fn replace_with_wind_map() {
|
||||
check_fix(
|
||||
r#"
|
||||
//- /main.rs crate:main deps:core
|
||||
use core::iter::Iterator;
|
||||
use core::option::Option::{self, Some, None};
|
||||
//- minicore: iterators
|
||||
fn foo() {
|
||||
let m = [1, 2, 3].iter().$0filter_map(|x| Some(92)).next();
|
||||
}
|
||||
//- /core/lib.rs crate:core
|
||||
pub mod option {
|
||||
pub enum Option<T> { Some(T), None }
|
||||
}
|
||||
pub mod iter {
|
||||
pub trait Iterator {
|
||||
type Item;
|
||||
fn filter_map<B, F>(self, f: F) -> FilterMap where F: FnMut(Self::Item) -> Option<B> { FilterMap }
|
||||
fn next(&mut self) -> Option<Self::Item>;
|
||||
}
|
||||
pub struct FilterMap {}
|
||||
impl Iterator for FilterMap {
|
||||
type Item = i32;
|
||||
fn next(&mut self) -> i32 { 7 }
|
||||
}
|
||||
let m = core::iter::repeat(()).$0filter_map(|()| Some(92)).next();
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
use core::iter::Iterator;
|
||||
use core::option::Option::{self, Some, None};
|
||||
fn foo() {
|
||||
let m = [1, 2, 3].iter().find_map(|x| Some(92));
|
||||
let m = core::iter::repeat(()).find_map(|()| Some(92));
|
||||
}
|
||||
"#,
|
||||
)
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
//! option:
|
||||
//! result:
|
||||
//! iterator: option
|
||||
//! iterators: iterator
|
||||
//! iterators: iterator, fn
|
||||
//! default: sized
|
||||
//! clone: sized
|
||||
//! copy: clone
|
||||
|
@ -390,7 +390,6 @@ pub mod iter {
|
|||
iter: I,
|
||||
n: usize,
|
||||
}
|
||||
|
||||
impl<I> Iterator for Take<I>
|
||||
where
|
||||
I: Iterator,
|
||||
|
@ -401,6 +400,22 @@ pub mod iter {
|
|||
loop {}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FilterMap<I, F> {
|
||||
iter: I,
|
||||
f: F,
|
||||
}
|
||||
impl<B, I: Iterator, F> Iterator for FilterMap<I, F>
|
||||
where
|
||||
F: FnMut(I::Item) -> Option<B>,
|
||||
{
|
||||
type Item = B;
|
||||
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<B> {
|
||||
loop {}
|
||||
}
|
||||
}
|
||||
}
|
||||
pub use self::adapters::Take;
|
||||
|
||||
|
@ -448,6 +463,13 @@ pub mod iter {
|
|||
fn take(self, n: usize) -> crate::iter::Take<Self> {
|
||||
loop {}
|
||||
}
|
||||
fn filter_map<B, F>(self, f: F) -> crate::iter::FilterMap<Self, F>
|
||||
where
|
||||
Self: Sized,
|
||||
F: FnMut(Self::Item) -> Option<B>,
|
||||
{
|
||||
loop {}
|
||||
}
|
||||
// endregion:iterators
|
||||
}
|
||||
impl<I: Iterator + ?Sized> Iterator for &mut I {
|
||||
|
|
Loading…
Reference in a new issue