From 15c4b3fa7f9d97029d64a7e13a12aa1ee42316d7 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 18 Jun 2021 22:10:29 +0300 Subject: internal: add Copy to minicore --- .../ide_assists/src/handlers/extract_function.rs | 711 ++++++++++++--------- 1 file changed, 409 insertions(+), 302 deletions(-) (limited to 'crates/ide_assists/src/handlers') diff --git a/crates/ide_assists/src/handlers/extract_function.rs b/crates/ide_assists/src/handlers/extract_function.rs index 7085a0c48..43e83d683 100644 --- a/crates/ide_assists/src/handlers/extract_function.rs +++ b/crates/ide_assists/src/handlers/extract_function.rs @@ -831,6 +831,7 @@ fn path_element_of_reference( })?; stdx::always!( matches!(path, ast::Expr::PathExpr(_) | ast::Expr::MacroCall(_)), + "unexpected expression type for variable usage: {:?}", path ); @@ -1501,7 +1502,8 @@ mod tests { r#" fn foo() { foo($01 + 1$0); -}"#, +} +"#, r#" fn foo() { foo(fun_name()); @@ -1509,7 +1511,8 @@ fn foo() { fn $0fun_name() -> i32 { 1 + 1 -}"#, +} +"#, ); } @@ -1522,7 +1525,8 @@ mod bar { fn foo() { foo($01 + 1$0); } -}"#, +} +"#, r#" mod bar { fn foo() { @@ -1532,7 +1536,8 @@ mod bar { fn $0fun_name() -> i32 { 1 + 1 } -}"#, +} +"#, ); } @@ -1543,7 +1548,8 @@ mod bar { r#" fn foo() { $0{ 1 + 1 }$0; -}"#, +} +"#, r#" fn foo() { fun_name(); @@ -1551,7 +1557,8 @@ fn foo() { fn $0fun_name() -> i32 { 1 + 1 -}"#, +} +"#, ); } @@ -1564,7 +1571,8 @@ fn foo() -> i32 { let k = 1; $0let m = 1; m + 1$0 -}"#, +} +"#, r#" fn foo() -> i32 { let k = 1; @@ -1574,7 +1582,8 @@ fn foo() -> i32 { fn $0fun_name() -> i32 { let m = 1; m + 1 -}"#, +} +"#, ); } @@ -1588,7 +1597,8 @@ fn foo() { $0let m = 1; let n = m + 1;$0 let g = 5; -}"#, +} +"#, r#" fn foo() { let k = 3; @@ -1599,7 +1609,8 @@ fn foo() { fn $0fun_name() { let m = 1; let n = m + 1; -}"#, +} +"#, ); } @@ -1610,7 +1621,8 @@ fn $0fun_name() { r#" fn foo() { $0if true { }$0 -}"#, +} +"#, r#" fn foo() { fun_name(); @@ -1618,7 +1630,8 @@ fn foo() { fn $0fun_name() { if true { } -}"#, +} +"#, ); } @@ -1629,7 +1642,8 @@ fn $0fun_name() { r#" fn foo() -> i32 { $0if true { 1 } else { 2 }$0 -}"#, +} +"#, r#" fn foo() -> i32 { fun_name() @@ -1637,7 +1651,8 @@ fn foo() -> i32 { fn $0fun_name() -> i32 { if true { 1 } else { 2 } -}"#, +} +"#, ); } @@ -1648,7 +1663,8 @@ fn $0fun_name() -> i32 { r#" fn foo() -> i32 { $0if let true = false { 1 } else { 2 }$0 -}"#, +} +"#, r#" fn foo() -> i32 { fun_name() @@ -1656,7 +1672,8 @@ fn foo() -> i32 { fn $0fun_name() -> i32 { if let true = false { 1 } else { 2 } -}"#, +} +"#, ); } @@ -1670,7 +1687,8 @@ fn foo() -> i32 { true => 1, false => 2, }$0 -}"#, +} +"#, r#" fn foo() -> i32 { fun_name() @@ -1681,7 +1699,8 @@ fn $0fun_name() -> i32 { true => 1, false => 2, } -}"#, +} +"#, ); } @@ -1692,7 +1711,8 @@ fn $0fun_name() -> i32 { r#" fn foo() { $0while true { }$0 -}"#, +} +"#, r#" fn foo() { fun_name(); @@ -1700,7 +1720,8 @@ fn foo() { fn $0fun_name() { while true { } -}"#, +} +"#, ); } @@ -1711,7 +1732,8 @@ fn $0fun_name() { r#" fn foo() { $0for v in &[0, 1] { }$0 -}"#, +} +"#, r#" fn foo() { fun_name(); @@ -1719,7 +1741,8 @@ fn foo() { fn $0fun_name() { for v in &[0, 1] { } -}"#, +} +"#, ); } @@ -1732,7 +1755,8 @@ fn foo() { $0loop { let m = 1; }$0 -}"#, +} +"#, r#" fn foo() { fun_name() @@ -1742,7 +1766,8 @@ fn $0fun_name() -> ! { loop { let m = 1; } -}"#, +} +"#, ); } @@ -1756,7 +1781,8 @@ fn foo() { let m = 1; break m; }$0; -}"#, +} +"#, r#" fn foo() { let v = fun_name(); @@ -1767,7 +1793,8 @@ fn $0fun_name() -> i32 { let m = 1; break m; } -}"#, +} +"#, ); } @@ -1781,7 +1808,8 @@ fn foo() { Some(x) => x, None => 0, }$0; -}"#, +} +"#, r#" fn foo() { let v: i32 = fun_name(); @@ -1792,7 +1820,8 @@ fn $0fun_name() -> i32 { Some(x) => x, None => 0, } -}"#, +} +"#, ); } @@ -1805,7 +1834,8 @@ fn foo() { let n = 1; let mut v = $0n * n;$0 v += 1; -}"#, +} +"#, r#" fn foo() { let n = 1; @@ -1816,7 +1846,8 @@ fn foo() { fn $0fun_name(n: i32) -> i32 { let mut v = n * n; v -}"#, +} +"#, ); } @@ -1832,7 +1863,8 @@ fn foo() { let mut w = 3;$0 v += 1; w += 1; -}"#, +} +"#, r#" fn foo() { let m = 2; @@ -1846,7 +1878,8 @@ fn $0fun_name(m: i32, n: i32) -> (i32, i32) { let mut v = m * n; let mut w = 3; (v, w) -}"#, +} +"#, ); } @@ -1854,12 +1887,13 @@ fn $0fun_name(m: i32, n: i32) -> (i32, i32) { fn argument_form_expr() { check_assist( extract_function, - r" + r#" fn foo() -> u32 { let n = 2; $0n+2$0 -}", - r" +} +"#, + r#" fn foo() -> u32 { let n = 2; fun_name(n) @@ -1867,7 +1901,8 @@ fn foo() -> u32 { fn $0fun_name(n: u32) -> u32 { n+2 -}", +} +"#, ) } @@ -1875,12 +1910,13 @@ fn $0fun_name(n: u32) -> u32 { fn argument_used_twice_form_expr() { check_assist( extract_function, - r" + r#" fn foo() -> u32 { let n = 2; $0n+n$0 -}", - r" +} +"#, + r#" fn foo() -> u32 { let n = 2; fun_name(n) @@ -1888,7 +1924,8 @@ fn foo() -> u32 { fn $0fun_name(n: u32) -> u32 { n+n -}", +} +"#, ) } @@ -1896,13 +1933,14 @@ fn $0fun_name(n: u32) -> u32 { fn two_arguments_form_expr() { check_assist( extract_function, - r" + r#" fn foo() -> u32 { let n = 2; let m = 3; $0n+n*m$0 -}", - r" +} +"#, + r#" fn foo() -> u32 { let n = 2; let m = 3; @@ -1911,7 +1949,8 @@ fn foo() -> u32 { fn $0fun_name(n: u32, m: u32) -> u32 { n+n*m -}", +} +"#, ) } @@ -1919,13 +1958,14 @@ fn $0fun_name(n: u32, m: u32) -> u32 { fn argument_and_locals() { check_assist( extract_function, - r" + r#" fn foo() -> u32 { let n = 2; $0let m = 1; n + m$0 -}", - r" +} +"#, + r#" fn foo() -> u32 { let n = 2; fun_name(n) @@ -1934,7 +1974,8 @@ fn foo() -> u32 { fn $0fun_name(n: u32) -> u32 { let m = 1; n + m -}", +} +"#, ) } @@ -1948,18 +1989,20 @@ fn $0fun_name(n: u32) -> u32 { fn part_of_expr_stmt() { check_assist( extract_function, - " + r#" fn foo() { $01$0 + 1; -}", - " +} +"#, + r#" fn foo() { fun_name() + 1; } fn $0fun_name() -> i32 { 1 -}", +} +"#, ); } @@ -1970,7 +2013,8 @@ fn $0fun_name() -> i32 { r#" fn foo() { $0bar(1 + 1)$0 -}"#, +} +"#, r#" fn foo() { fun_name(); @@ -1978,7 +2022,8 @@ fn foo() { fn $0fun_name() { bar(1 + 1) -}"#, +} +"#, ) } @@ -1986,15 +2031,16 @@ fn $0fun_name() { fn extract_from_nested() { check_assist( extract_function, - r" + r#" fn main() { let x = true; let tuple = match x { true => ($02 + 2$0, true) _ => (0, false) }; -}", - r" +} +"#, + r#" fn main() { let x = true; let tuple = match x { @@ -2005,7 +2051,8 @@ fn main() { fn $0fun_name() -> i32 { 2 + 2 -}", +} +"#, ); } @@ -2013,18 +2060,20 @@ fn $0fun_name() -> i32 { fn param_from_closure() { check_assist( extract_function, - r" + r#" fn main() { let lambda = |x: u32| $0x * 2$0; -}", - r" +} +"#, + r#" fn main() { let lambda = |x: u32| fun_name(x); } fn $0fun_name(x: u32) -> u32 { x * 2 -}", +} +"#, ); } @@ -2032,18 +2081,20 @@ fn $0fun_name(x: u32) -> u32 { fn extract_return_stmt() { check_assist( extract_function, - r" + r#" fn foo() -> u32 { $0return 2 + 2$0; -}", - r" +} +"#, + r#" fn foo() -> u32 { return fun_name(); } fn $0fun_name() -> u32 { 2 + 2 -}", +} +"#, ); } @@ -2051,13 +2102,14 @@ fn $0fun_name() -> u32 { fn does_not_add_extra_whitespace() { check_assist( extract_function, - r" + r#" fn foo() -> u32 { $0return 2 + 2$0; -}", - r" +} +"#, + r#" fn foo() -> u32 { @@ -2066,7 +2118,8 @@ fn foo() -> u32 { fn $0fun_name() -> u32 { 2 + 2 -}", +} +"#, ); } @@ -2074,13 +2127,14 @@ fn $0fun_name() -> u32 { fn break_stmt() { check_assist( extract_function, - r" + r#" fn main() { let result = loop { $0break 2 + 2$0; }; -}", - r" +} +"#, + r#" fn main() { let result = loop { break fun_name(); @@ -2089,7 +2143,8 @@ fn main() { fn $0fun_name() -> i32 { 2 + 2 -}", +} +"#, ); } @@ -2097,18 +2152,20 @@ fn $0fun_name() -> i32 { fn extract_cast() { check_assist( extract_function, - r" + r#" fn main() { let v = $00f32 as u32$0; -}", - r" +} +"#, + r#" fn main() { let v = fun_name(); } fn $0fun_name() -> u32 { 0f32 as u32 -}", +} +"#, ); } @@ -2121,15 +2178,16 @@ fn $0fun_name() -> u32 { fn method_to_freestanding() { check_assist( extract_function, - r" + r#" struct S; impl S { fn foo(&self) -> i32 { $01+1$0 } -}", - r" +} +"#, + r#" struct S; impl S { @@ -2140,7 +2198,8 @@ impl S { fn $0fun_name() -> i32 { 1+1 -}", +} +"#, ); } @@ -2148,15 +2207,16 @@ fn $0fun_name() -> i32 { fn method_with_reference() { check_assist( extract_function, - r" + r#" struct S { f: i32 }; impl S { fn foo(&self) -> i32 { $01+self.f$0 } -}", - r" +} +"#, + r#" struct S { f: i32 }; impl S { @@ -2167,7 +2227,8 @@ impl S { fn $0fun_name(&self) -> i32 { 1+self.f } -}", +} +"#, ); } @@ -2175,15 +2236,16 @@ impl S { fn method_with_mut() { check_assist( extract_function, - r" + r#" struct S { f: i32 }; impl S { fn foo(&mut self) { $0self.f += 1;$0 } -}", - r" +} +"#, + r#" struct S { f: i32 }; impl S { @@ -2194,7 +2256,8 @@ impl S { fn $0fun_name(&mut self) { self.f += 1; } -}", +} +"#, ); } @@ -2202,13 +2265,14 @@ impl S { fn variable_defined_inside_and_used_after_no_ret() { check_assist( extract_function, - r" + r#" fn foo() { let n = 1; $0let k = n * n;$0 let m = k + 1; -}", - r" +} +"#, + r#" fn foo() { let n = 1; let k = fun_name(n); @@ -2218,7 +2282,8 @@ fn foo() { fn $0fun_name(n: i32) -> i32 { let k = n * n; k -}", +} +"#, ); } @@ -2226,13 +2291,14 @@ fn $0fun_name(n: i32) -> i32 { fn variable_defined_inside_and_used_after_mutably_no_ret() { check_assist( extract_function, - r" + r#" fn foo() { let n = 1; $0let mut k = n * n;$0 k += 1; -}", - r" +} +"#, + r#" fn foo() { let n = 1; let mut k = fun_name(n); @@ -2242,7 +2308,8 @@ fn foo() { fn $0fun_name(n: i32) -> i32 { let mut k = n * n; k -}", +} +"#, ); } @@ -2250,14 +2317,15 @@ fn $0fun_name(n: i32) -> i32 { fn two_variables_defined_inside_and_used_after_no_ret() { check_assist( extract_function, - r" + r#" fn foo() { let n = 1; $0let k = n * n; let m = k + 2;$0 let h = k + m; -}", - r" +} +"#, + r#" fn foo() { let n = 1; let (k, m) = fun_name(n); @@ -2268,7 +2336,8 @@ fn $0fun_name(n: i32) -> (i32, i32) { let k = n * n; let m = k + 2; (k, m) -}", +} +"#, ); } @@ -2276,7 +2345,7 @@ fn $0fun_name(n: i32) -> (i32, i32) { fn multi_variables_defined_inside_and_used_after_mutably_no_ret() { check_assist( extract_function, - r" + r#" fn foo() { let n = 1; $0let mut k = n * n; @@ -2285,8 +2354,9 @@ fn foo() { o += 1;$0 k += o; m = 1; -}", - r" +} +"#, + r#" fn foo() { let n = 1; let (mut k, mut m, o) = fun_name(n); @@ -2300,7 +2370,8 @@ fn $0fun_name(n: i32) -> (i32, i32, i32) { let mut o = m + 3; o += 1; (k, m, o) -}", +} +"#, ); } @@ -2308,13 +2379,14 @@ fn $0fun_name(n: i32) -> (i32, i32, i32) { fn nontrivial_patterns_define_variables() { check_assist( extract_function, - r" + r#" struct Counter(i32); fn foo() { $0let Counter(n) = Counter(0);$0 let m = n; -}", - r" +} +"#, + r#" struct Counter(i32); fn foo() { let n = fun_name(); @@ -2324,7 +2396,8 @@ fn foo() { fn $0fun_name() -> i32 { let Counter(n) = Counter(0); n -}", +} +"#, ); } @@ -2332,13 +2405,14 @@ fn $0fun_name() -> i32 { fn struct_with_two_fields_pattern_define_variables() { check_assist( extract_function, - r" + r#" struct Counter { n: i32, m: i32 }; fn foo() { $0let Counter { n, m: k } = Counter { n: 1, m: 2 };$0 let h = n + k; -}", - r" +} +"#, + r#" struct Counter { n: i32, m: i32 }; fn foo() { let (n, k) = fun_name(); @@ -2348,7 +2422,8 @@ fn foo() { fn $0fun_name() -> (i32, i32) { let Counter { n, m: k } = Counter { n: 1, m: 2 }; (n, k) -}", +} +"#, ); } @@ -2356,13 +2431,14 @@ fn $0fun_name() -> (i32, i32) { fn mut_var_from_outer_scope() { check_assist( extract_function, - r" + r#" fn foo() { let mut n = 1; $0n += 1;$0 let m = n + 1; -}", - r" +} +"#, + r#" fn foo() { let mut n = 1; fun_name(&mut n); @@ -2371,7 +2447,8 @@ fn foo() { fn $0fun_name(n: &mut i32) { *n += 1; -}", +} +"#, ); } @@ -2379,14 +2456,15 @@ fn $0fun_name(n: &mut i32) { fn mut_field_from_outer_scope() { check_assist( extract_function, - r" + r#" struct C { n: i32 } fn foo() { let mut c = C { n: 0 }; $0c.n += 1;$0 let m = c.n + 1; -}", - r" +} +"#, + r#" struct C { n: i32 } fn foo() { let mut c = C { n: 0 }; @@ -2396,7 +2474,8 @@ fn foo() { fn $0fun_name(c: &mut C) { c.n += 1; -}", +} +"#, ); } @@ -2404,7 +2483,7 @@ fn $0fun_name(c: &mut C) { fn mut_nested_field_from_outer_scope() { check_assist( extract_function, - r" + r#" struct P { n: i32} struct C { p: P } fn foo() { @@ -2414,8 +2493,9 @@ fn foo() { $0c.p.n += u.p.n; let r = &mut v.p.n;$0 let m = c.p.n + v.p.n + u.p.n; -}", - r" +} +"#, + r#" struct P { n: i32} struct C { p: P } fn foo() { @@ -2429,7 +2509,8 @@ fn foo() { fn $0fun_name(c: &mut C, u: &C, v: &mut C) { c.p.n += u.p.n; let r = &mut v.p.n; -}", +} +"#, ); } @@ -2437,7 +2518,7 @@ fn $0fun_name(c: &mut C, u: &C, v: &mut C) { fn mut_param_many_usages_stmt() { check_assist( extract_function, - r" + r#" fn bar(k: i32) {} trait I: Copy { fn succ(&self) -> Self; @@ -2458,8 +2539,9 @@ fn foo() { *v = v.succ(); n.succ();$0 let m = n + 1; -}", - r" +} +"#, + r#" fn bar(k: i32) {} trait I: Copy { fn succ(&self) -> Self; @@ -2484,7 +2566,8 @@ fn $0fun_name(n: &mut i32) { let v = n; *v = v.succ(); n.succ(); -}", +} +"#, ); } @@ -2492,7 +2575,7 @@ fn $0fun_name(n: &mut i32) { fn mut_param_many_usages_expr() { check_assist( extract_function, - r" + r#" fn bar(k: i32) {} trait I: Copy { fn succ(&self) -> Self; @@ -2515,8 +2598,9 @@ fn foo() { n.succ(); }$0 let m = n + 1; -}", - r" +} +"#, + r#" fn bar(k: i32) {} trait I: Copy { fn succ(&self) -> Self; @@ -2541,7 +2625,8 @@ fn $0fun_name(n: &mut i32) { let v = n; *v = v.succ(); n.succ(); -}", +} +"#, ); } @@ -2549,11 +2634,12 @@ fn $0fun_name(n: &mut i32) { fn mut_param_by_value() { check_assist( extract_function, - r" + r#" fn foo() { let mut n = 1; $0n += 1;$0 -}", +} +"#, r" fn foo() { let mut n = 1; @@ -2562,7 +2648,8 @@ fn foo() { fn $0fun_name(mut n: i32) { n += 1; -}", +} +", ); } @@ -2570,14 +2657,15 @@ fn $0fun_name(mut n: i32) { fn mut_param_because_of_mut_ref() { check_assist( extract_function, - r" + r#" fn foo() { let mut n = 1; $0let v = &mut n; *v += 1;$0 let k = n; -}", - r" +} +"#, + r#" fn foo() { let mut n = 1; fun_name(&mut n); @@ -2587,7 +2675,8 @@ fn foo() { fn $0fun_name(n: &mut i32) { let v = n; *v += 1; -}", +} +"#, ); } @@ -2600,8 +2689,9 @@ fn foo() { let mut n = 1; $0let v = &mut n; *v += 1;$0 -}", - r" +} +", + r#" fn foo() { let mut n = 1; fun_name(n); @@ -2610,7 +2700,8 @@ fn foo() { fn $0fun_name(mut n: i32) { let v = &mut n; *v += 1; -}", +} +"#, ); } @@ -2618,7 +2709,7 @@ fn $0fun_name(mut n: i32) { fn mut_method_call() { check_assist( extract_function, - r" + r#" trait I { fn inc(&mut self); } @@ -2628,8 +2719,9 @@ impl I for i32 { fn foo() { let mut n = 1; $0n.inc();$0 -}", - r" +} +"#, + r#" trait I { fn inc(&mut self); } @@ -2643,7 +2735,8 @@ fn foo() { fn $0fun_name(mut n: i32) { n.inc(); -}", +} +"#, ); } @@ -2651,7 +2744,7 @@ fn $0fun_name(mut n: i32) { fn shared_method_call() { check_assist( extract_function, - r" + r#" trait I { fn succ(&self); } @@ -2661,7 +2754,8 @@ impl I for i32 { fn foo() { let mut n = 1; $0n.succ();$0 -}", +} +"#, r" trait I { fn succ(&self); @@ -2676,7 +2770,8 @@ fn foo() { fn $0fun_name(n: i32) { n.succ(); -}", +} +", ); } @@ -2684,7 +2779,7 @@ fn $0fun_name(n: i32) { fn mut_method_call_with_other_receiver() { check_assist( extract_function, - r" + r#" trait I { fn inc(&mut self, n: i32); } @@ -2695,7 +2790,8 @@ fn foo() { let mut n = 1; $0let mut m = 2; m.inc(n);$0 -}", +} +"#, r" trait I { fn inc(&mut self, n: i32); @@ -2711,7 +2807,8 @@ fn foo() { fn $0fun_name(n: i32) { let mut m = 2; m.inc(n); -}", +} +", ); } @@ -2719,12 +2816,13 @@ fn $0fun_name(n: i32) { fn non_copy_without_usages_after() { check_assist( extract_function, - r" + r#" struct Counter(i32); fn foo() { let c = Counter(0); $0let n = c.0;$0 -}", +} +"#, r" struct Counter(i32); fn foo() { @@ -2734,7 +2832,8 @@ fn foo() { fn $0fun_name(c: Counter) { let n = c.0; -}", +} +", ); } @@ -2748,8 +2847,9 @@ fn foo() { let c = Counter(0); $0let n = c.0;$0 let m = c.0; -}", - r" +} +", + r#" struct Counter(i32); fn foo() { let c = Counter(0); @@ -2759,7 +2859,8 @@ fn foo() { fn $0fun_name(c: &Counter) { let n = c.0; -}", +} +"#, ); } @@ -2767,19 +2868,15 @@ fn $0fun_name(c: &Counter) { fn copy_used_after() { check_assist( extract_function, - r##" -#[lang = "copy"] -pub trait Copy {} -impl Copy for i32 {} + r#" +//- minicore: copy fn foo() { let n = 0; $0let m = n;$0 let k = n; -}"##, - r##" -#[lang = "copy"] -pub trait Copy {} -impl Copy for i32 {} +} +"#, + r#" fn foo() { let n = 0; fun_name(n); @@ -2788,7 +2885,8 @@ fn foo() { fn $0fun_name(n: i32) { let m = n; -}"##, +} +"#, ) } @@ -2796,21 +2894,19 @@ fn $0fun_name(n: i32) { fn copy_custom_used_after() { check_assist( extract_function, - r##" -#[lang = "copy"] -pub trait Copy {} + r#" +//- minicore: copy, derive +#[derive(Clone, Copy)] struct Counter(i32); -impl Copy for Counter {} fn foo() { let c = Counter(0); $0let n = c.0;$0 let m = c.0; -}"##, - r##" -#[lang = "copy"] -pub trait Copy {} +} +"#, + r#" +#[derive(Clone, Copy)] struct Counter(i32); -impl Copy for Counter {} fn foo() { let c = Counter(0); fun_name(c); @@ -2819,7 +2915,8 @@ fn foo() { fn $0fun_name(c: Counter) { let n = c.0; -}"##, +} +"#, ); } @@ -2827,7 +2924,7 @@ fn $0fun_name(c: Counter) { fn indented_stmts() { check_assist( extract_function, - r" + r#" fn foo() { if true { loop { @@ -2835,8 +2932,9 @@ fn foo() { let m = 2;$0 } } -}", - r" +} +"#, + r#" fn foo() { if true { loop { @@ -2848,7 +2946,8 @@ fn foo() { fn $0fun_name() { let n = 1; let m = 2; -}", +} +"#, ); } @@ -2856,7 +2955,7 @@ fn $0fun_name() { fn indented_stmts_inside_mod() { check_assist( extract_function, - r" + r#" mod bar { fn foo() { if true { @@ -2866,8 +2965,9 @@ mod bar { } } } -}", - r" +} +"#, + r#" mod bar { fn foo() { if true { @@ -2881,7 +2981,8 @@ mod bar { let n = 1; let m = 2; } -}", +} +"#, ); } @@ -2889,7 +2990,7 @@ mod bar { fn break_loop() { check_assist( extract_function, - r##" + r#" enum Option { #[lang = "None"] None, #[lang = "Some"] Some(T), @@ -2903,8 +3004,9 @@ fn foo() { let k = 2;$0 let h = 1 + k; } -}"##, - r##" +} +"#, + r#" enum Option { #[lang = "None"] None, #[lang = "Some"] Some(T), @@ -2926,7 +3028,8 @@ fn $0fun_name(n: i32) -> Option { return None; let k = 2; Some(k) -}"##, +} +"#, ); } @@ -2934,31 +3037,17 @@ fn $0fun_name(n: i32) -> Option { fn return_to_parent() { check_assist( extract_function, - r##" -#[lang = "copy"] -pub trait Copy {} -impl Copy for i32 {} -enum Result { - #[lang = "Ok"] Ok(T), - #[lang = "Err"] Err(E), -} -use Result::*; + r#" +//- minicore: copy, result fn foo() -> i64 { let n = 1; $0let m = n + 1; return 1; let k = 2;$0 (n + k) as i64 -}"##, - r##" -#[lang = "copy"] -pub trait Copy {} -impl Copy for i32 {} -enum Result { - #[lang = "Ok"] Ok(T), - #[lang = "Err"] Err(E), -} -use Result::*; +} +"#, + r#" fn foo() -> i64 { let n = 1; let k = match fun_name(n) { @@ -2973,7 +3062,8 @@ fn $0fun_name(n: i32) -> Result { return Err(1); let k = 2; Ok(k) -}"##, +} +"#, ); } @@ -2982,7 +3072,7 @@ fn $0fun_name(n: i32) -> Result { cov_mark::check!(external_control_flow_break_and_continue); check_assist_not_applicable( extract_function, - r##" + r#" fn foo() { loop { let n = 1; @@ -2993,7 +3083,8 @@ fn foo() { let k = k + 1;$0 let r = n + k; } -}"##, +} +"#, ); } @@ -3002,7 +3093,7 @@ fn foo() { cov_mark::check!(external_control_flow_return_and_bc); check_assist_not_applicable( extract_function, - r##" + r#" fn foo() { loop { let n = 1; @@ -3013,7 +3104,8 @@ fn foo() { let k = k + 1;$0 let r = n + k; } -}"##, +} +"#, ); } @@ -3021,7 +3113,7 @@ fn foo() { fn break_loop_with_if() { check_assist( extract_function, - r##" + r#" fn foo() { loop { let mut n = 1; @@ -3030,8 +3122,9 @@ fn foo() { n += m;$0 let h = 1 + n; } -}"##, - r##" +} +"#, + r#" fn foo() { loop { let mut n = 1; @@ -3047,7 +3140,8 @@ fn $0fun_name(n: &mut i32) -> bool { return true; *n += m; false -}"##, +} +"#, ); } @@ -3055,7 +3149,7 @@ fn $0fun_name(n: &mut i32) -> bool { fn break_loop_nested() { check_assist( extract_function, - r##" + r#" fn foo() { loop { let mut n = 1; @@ -3065,8 +3159,9 @@ fn foo() { }$0 let h = 1; } -}"##, - r##" +} +"#, + r#" fn foo() { loop { let mut n = 1; @@ -3083,7 +3178,8 @@ fn $0fun_name(n: i32) -> bool { return true; } false -}"##, +} +"#, ); } @@ -3091,7 +3187,7 @@ fn $0fun_name(n: i32) -> bool { fn return_from_nested_loop() { check_assist( extract_function, - r##" + r#" fn foo() { loop { let n = 1; @@ -3103,8 +3199,9 @@ fn foo() { let m = k + 1;$0 let h = 1 + m; } -}"##, - r##" +} +"#, + r#" fn foo() { loop { let n = 1; @@ -3123,7 +3220,8 @@ fn $0fun_name() -> Option { } let m = k + 1; Some(m) -}"##, +} +"#, ); } @@ -3131,7 +3229,7 @@ fn $0fun_name() -> Option { fn break_from_nested_loop() { check_assist( extract_function, - r##" + r#" fn foo() { loop { let n = 1; @@ -3142,8 +3240,9 @@ fn foo() { let m = k + 1;$0 let h = 1 + m; } -}"##, - r##" +} +"#, + r#" fn foo() { loop { let n = 1; @@ -3159,7 +3258,8 @@ fn $0fun_name() -> i32 { } let m = k + 1; m -}"##, +} +"#, ); } @@ -3167,7 +3267,7 @@ fn $0fun_name() -> i32 { fn break_from_nested_and_outer_loops() { check_assist( extract_function, - r##" + r#" fn foo() { loop { let n = 1; @@ -3181,8 +3281,9 @@ fn foo() { let m = k + 1;$0 let h = 1 + m; } -}"##, - r##" +} +"#, + r#" fn foo() { loop { let n = 1; @@ -3204,7 +3305,8 @@ fn $0fun_name() -> Option { } let m = k + 1; Some(m) -}"##, +} +"#, ); } @@ -3212,7 +3314,7 @@ fn $0fun_name() -> Option { fn return_from_nested_fn() { check_assist( extract_function, - r##" + r#" fn foo() { loop { let n = 1; @@ -3223,8 +3325,9 @@ fn foo() { let m = k + 1;$0 let h = 1 + m; } -}"##, - r##" +} +"#, + r#" fn foo() { loop { let n = 1; @@ -3240,7 +3343,8 @@ fn $0fun_name() -> i32 { } let m = k + 1; m -}"##, +} +"#, ); } @@ -3248,7 +3352,7 @@ fn $0fun_name() -> i32 { fn break_with_value() { check_assist( extract_function, - r##" + r#" fn foo() -> i32 { loop { let n = 1; @@ -3259,8 +3363,9 @@ fn foo() -> i32 { let m = k + 1;$0 let h = 1; } -}"##, - r##" +} +"#, + r#" fn foo() -> i32 { loop { let n = 1; @@ -3278,7 +3383,8 @@ fn $0fun_name() -> Option { } let m = k + 1; None -}"##, +} +"#, ); } @@ -3286,7 +3392,7 @@ fn $0fun_name() -> Option { fn break_with_value_and_return() { check_assist( extract_function, - r##" + r#" fn foo() -> i64 { loop { let n = 1; @@ -3298,8 +3404,9 @@ fn foo() -> i64 { let m = k + 1;$0 let h = 1 + m; } -}"##, - r##" +} +"#, + r#" fn foo() -> i64 { loop { let n = 1; @@ -3318,7 +3425,8 @@ fn $0fun_name() -> Result { } let m = k + 1; Ok(m) -}"##, +} +"#, ); } @@ -3326,9 +3434,8 @@ fn $0fun_name() -> Result { fn try_option() { check_assist( extract_function, - r##" -enum Option { None, Some(T), } -use Option::*; + r#" +//- minicore: option fn bar() -> Option { None } fn foo() -> Option<()> { let n = bar()?; @@ -3336,10 +3443,9 @@ fn foo() -> Option<()> { let m = k + 1;$0 let h = 1 + m; Some(()) -}"##, - r##" -enum Option { None, Some(T), } -use Option::*; +} +"#, + r#" fn bar() -> Option { None } fn foo() -> Option<()> { let n = bar()?; @@ -3352,7 +3458,8 @@ fn $0fun_name() -> Option { let k = foo()?; let m = k + 1; Some(m) -}"##, +} +"#, ); } @@ -3360,19 +3467,17 @@ fn $0fun_name() -> Option { fn try_option_unit() { check_assist( extract_function, - r##" -enum Option { None, Some(T), } -use Option::*; + r#" +//- minicore: option fn foo() -> Option<()> { let n = 1; $0let k = foo()?; let m = k + 1;$0 let h = 1 + n; Some(()) -}"##, - r##" -enum Option { None, Some(T), } -use Option::*; +} +"#, + r#" fn foo() -> Option<()> { let n = 1; fun_name()?; @@ -3384,7 +3489,8 @@ fn $0fun_name() -> Option<()> { let k = foo()?; let m = k + 1; Some(()) -}"##, +} +"#, ); } @@ -3392,19 +3498,17 @@ fn $0fun_name() -> Option<()> { fn try_result() { check_assist( extract_function, - r##" -enum Result { Ok(T), Err(E), } -use Result::*; + r#" +//- minicore: result fn foo() -> Result<(), i64> { let n = 1; $0let k = foo()?; let m = k + 1;$0 let h = 1 + m; Ok(()) -}"##, - r##" -enum Result { Ok(T), Err(E), } -use Result::*; +} +"#, + r#" fn foo() -> Result<(), i64> { let n = 1; let m = fun_name()?; @@ -3416,7 +3520,8 @@ fn $0fun_name() -> Result { let k = foo()?; let m = k + 1; Ok(m) -}"##, +} +"#, ); } @@ -3424,9 +3529,8 @@ fn $0fun_name() -> Result { fn try_option_with_return() { check_assist( extract_function, - r##" -enum Option { None, Some(T) } -use Option::*; + r#" +//- minicore: option fn foo() -> Option<()> { let n = 1; $0let k = foo()?; @@ -3436,10 +3540,9 @@ fn foo() -> Option<()> { let m = k + 1;$0 let h = 1 + m; Some(()) -}"##, - r##" -enum Option { None, Some(T) } -use Option::*; +} +"#, + r#" fn foo() -> Option<()> { let n = 1; let m = fun_name()?; @@ -3454,7 +3557,8 @@ fn $0fun_name() -> Option { } let m = k + 1; Some(m) -}"##, +} +"#, ); } @@ -3462,9 +3566,8 @@ fn $0fun_name() -> Option { fn try_result_with_return() { check_assist( extract_function, - r##" -enum Result { Ok(T), Err(E), } -use Result::*; + r#" +//- minicore: result fn foo() -> Result<(), i64> { let n = 1; $0let k = foo()?; @@ -3474,10 +3577,9 @@ fn foo() -> Result<(), i64> { let m = k + 1;$0 let h = 1 + m; Ok(()) -}"##, - r##" -enum Result { Ok(T), Err(E), } -use Result::*; +} +"#, + r#" fn foo() -> Result<(), i64> { let n = 1; let m = fun_name()?; @@ -3492,7 +3594,8 @@ fn $0fun_name() -> Result { } let m = k + 1; Ok(m) -}"##, +} +"#, ); } @@ -3501,9 +3604,8 @@ fn $0fun_name() -> Result { cov_mark::check!(external_control_flow_try_and_bc); check_assist_not_applicable( extract_function, - r##" -enum Option { None, Some(T) } -use Option::*; + r#" +//- minicore: option fn foo() -> Option<()> { loop { let n = Some(1); @@ -3514,7 +3616,8 @@ fn foo() -> Option<()> { let r = n + k; } Some(()) -}"##, +} +"#, ); } @@ -3523,9 +3626,8 @@ fn foo() -> Option<()> { cov_mark::check!(external_control_flow_try_and_return_non_err); check_assist_not_applicable( extract_function, - r##" -enum Result { Ok(T), Err(E), } -use Result::*; + r#" +//- minicore: result fn foo() -> Result<(), i64> { let n = 1; $0let k = foo()?; @@ -3535,7 +3637,8 @@ fn foo() -> Result<(), i64> { let m = k + 1;$0 let h = 1 + m; Ok(()) -}"##, +} +"#, ); } @@ -3543,7 +3646,7 @@ fn foo() -> Result<(), i64> { fn param_usage_in_macro() { check_assist( extract_function, - r" + r#" macro_rules! m { ($val:expr) => { $val }; } @@ -3552,8 +3655,9 @@ fn foo() { let n = 1; $0let k = n * m!(n);$0 let m = k + 1; -}", - r" +} +"#, + r#" macro_rules! m { ($val:expr) => { $val }; } @@ -3567,7 +3671,8 @@ fn foo() { fn $0fun_name(n: i32) -> i32 { let k = n * m!(n); k -}", +} +"#, ); } @@ -3575,7 +3680,8 @@ fn $0fun_name(n: i32) -> i32 { fn extract_with_await() { check_assist( extract_function, - r#"fn main() { + r#" +fn main() { $0some_function().await;$0 } @@ -3603,7 +3709,8 @@ async fn some_function() { fn extract_with_await_in_args() { check_assist( extract_function, - r#"fn main() { + r#" +fn main() { $0function_call("a", some_function().await);$0 } -- cgit v1.2.3