aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-05-28 16:07:39 +0100
committerAleksey Kladov <[email protected]>2019-05-28 16:07:39 +0100
commitc8bcfe6a05d82e151d459bcd2bd8a7b2742f7a66 (patch)
tree407e3ec2b7b4a88634e85c113d5e219cc413535a /crates/ra_hir/src/ty
parent2e3f5af9d49db5732405050e6c5442cb6eeef965 (diff)
fix syntax errors in tests
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r--crates/ra_hir/src/ty/tests.rs240
1 files changed, 128 insertions, 112 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index cd24faba5..da9aeec6d 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -59,7 +59,7 @@ fn test() {
59 let b: usize = 1; 59 let b: usize = 1;
60 let c = b; 60 let c = b;
61} 61}
62}"#), 62"#),
63 @r###" 63 @r###"
64[11; 71) '{ ...= b; }': () 64[11; 71) '{ ...= b; }': ()
65[21; 22) 'a': isize 65[21; 22) 'a': isize
@@ -85,7 +85,7 @@ fn test() {
85 a(); 85 a();
86 b::c(); 86 b::c();
87} 87}
88}"#), 88"#),
89 @r###" 89 @r###"
90[15; 20) '{ 1 }': u32 90[15; 20) '{ 1 }': u32
91[17; 18) '1': u32 91[17; 18) '1': u32
@@ -1004,7 +1004,7 @@ fn infer_tuple_struct_generics() {
1004 assert_snapshot_matches!( 1004 assert_snapshot_matches!(
1005 infer(r#" 1005 infer(r#"
1006struct A<T>(T); 1006struct A<T>(T);
1007enum Option<T> { Some(T), None }; 1007enum Option<T> { Some(T), None }
1008use Option::*; 1008use Option::*;
1009 1009
1010fn test() { 1010fn test() {
@@ -1017,22 +1017,24 @@ fn test() {
1017} 1017}
1018"#), 1018"#),
1019 @r###" 1019 @r###"
1020[77; 185) '{ ...one; }': () 1020
1021[83; 84) 'A': A<i32>(T) -> A<T> 1021 ⋮[76; 184) '{ ...one; }': ()
1022[83; 88) 'A(42)': A<i32> 1022 ⋮[82; 83) 'A': A<i32>(T) -> A<T>
1023[85; 87) '42': i32 1023 ⋮[82; 87) 'A(42)': A<i32>
1024[94; 95) 'A': A<u128>(T) -> A<T> 1024 ⋮[84; 86) '42': i32
1025[94; 103) 'A(42u128)': A<u128> 1025 ⋮[93; 94) 'A': A<u128>(T) -> A<T>
1026[96; 102) '42u128': u128 1026 ⋮[93; 102) 'A(42u128)': A<u128>
1027[109; 113) 'Some': Some<&str>(T) -> Option<T> 1027 ⋮[95; 101) '42u128': u128
1028[109; 118) 'Some("x")': Option<&str> 1028 ⋮[108; 112) 'Some': Some<&str>(T) -> Option<T>
1029[114; 117) '"x"': &str 1029 ⋮[108; 117) 'Some("x")': Option<&str>
1030[124; 136) 'Option::Some': Some<&str>(T) -> Option<T> 1030 ⋮[113; 116) '"x"': &str
1031[124; 141) 'Option...e("x")': Option<&str> 1031 ⋮[123; 135) 'Option::Some': Some<&str>(T) -> Option<T>
1032[137; 140) '"x"': &str 1032 ⋮[123; 140) 'Option...e("x")': Option<&str>
1033[147; 151) 'None': Option<{unknown}> 1033 ⋮[136; 139) '"x"': &str
1034[161; 162) 'x': Option<i64> 1034 ⋮[146; 150) 'None': Option<{unknown}>
1035[178; 182) 'None': Option<i64>"### 1035 ⋮[160; 161) 'x': Option<i64>
1036 ⋮[177; 181) 'None': Option<i64>
1037 "###
1036 ); 1038 );
1037} 1039}
1038 1040
@@ -1268,7 +1270,7 @@ impl Struct {
1268 const FOO: u32 = 1; 1270 const FOO: u32 = 1;
1269} 1271}
1270 1272
1271enum Enum; 1273enum Enum {}
1272 1274
1273impl Enum { 1275impl Enum {
1274 const BAR: u32 = 2; 1276 const BAR: u32 = 2;
@@ -1291,16 +1293,18 @@ fn test() {
1291} 1293}
1292"#), 1294"#),
1293 @r###" 1295 @r###"
1294[52; 53) '1': u32 1296
1295[103; 104) '2': u32 1297 ⋮[52; 53) '1': u32
1296[211; 212) '5': u32 1298 ⋮[105; 106) '2': u32
1297[227; 305) '{ ...:ID; }': () 1299 ⋮[213; 214) '5': u32
1298[237; 238) 'x': u32 1300 ⋮[229; 307) '{ ...:ID; }': ()
1299[241; 252) 'Struct::FOO': u32 1301 ⋮[239; 240) 'x': u32
1300[262; 263) 'y': u32 1302 ⋮[243; 254) 'Struct::FOO': u32
1301[266; 275) 'Enum::BAR': u32 1303 ⋮[264; 265) 'y': u32
1302[285; 286) 'z': {unknown} 1304 ⋮[268; 277) 'Enum::BAR': u32
1303[289; 302) 'TraitTest::ID': {unknown}"### 1305 ⋮[287; 288) 'z': {unknown}
1306 ⋮[291; 304) 'TraitTest::ID': {unknown}
1307 "###
1304 ); 1308 );
1305} 1309}
1306 1310
@@ -1308,7 +1312,7 @@ fn test() {
1308fn infer_associated_method_struct() { 1312fn infer_associated_method_struct() {
1309 assert_snapshot_matches!( 1313 assert_snapshot_matches!(
1310 infer(r#" 1314 infer(r#"
1311struct A { x: u32 }; 1315struct A { x: u32 }
1312 1316
1313impl A { 1317impl A {
1314 fn new() -> A { 1318 fn new() -> A {
@@ -1321,15 +1325,17 @@ fn test() {
1321} 1325}
1322"#), 1326"#),
1323 @r###" 1327 @r###"
1324[50; 76) '{ ... }': A 1328
1325[60; 70) 'A { x: 0 }': A 1329 ⋮[49; 75) '{ ... }': A
1326[67; 68) '0': u32 1330 ⋮[59; 69) 'A { x: 0 }': A
1327[89; 123) '{ ...a.x; }': () 1331 ⋮[66; 67) '0': u32
1328[99; 100) 'a': A 1332 ⋮[88; 122) '{ ...a.x; }': ()
1329[103; 109) 'A::new': fn new() -> A 1333 ⋮[98; 99) 'a': A
1330[103; 111) 'A::new()': A 1334 ⋮[102; 108) 'A::new': fn new() -> A
1331[117; 118) 'a': A 1335 ⋮[102; 110) 'A::new()': A
1332[117; 120) 'a.x': u32"### 1336 ⋮[116; 117) 'a': A
1337 ⋮[116; 119) 'a.x': u32
1338 "###
1333 ); 1339 );
1334} 1340}
1335 1341
@@ -1337,7 +1343,7 @@ fn test() {
1337fn infer_associated_method_enum() { 1343fn infer_associated_method_enum() {
1338 assert_snapshot_matches!( 1344 assert_snapshot_matches!(
1339 infer(r#" 1345 infer(r#"
1340enum A { B, C }; 1346enum A { B, C }
1341 1347
1342impl A { 1348impl A {
1343 pub fn b() -> A { 1349 pub fn b() -> A {
@@ -1355,19 +1361,21 @@ fn test() {
1355} 1361}
1356"#), 1362"#),
1357 @r###" 1363 @r###"
1358[48; 68) '{ ... }': A 1364
1359[58; 62) 'A::B': A 1365 ⋮[47; 67) '{ ... }': A
1360[89; 109) '{ ... }': A 1366 ⋮[57; 61) 'A::B': A
1361[99; 103) 'A::C': A 1367 ⋮[88; 108) '{ ... }': A
1362[122; 179) '{ ... c; }': () 1368 ⋮[98; 102) 'A::C': A
1363[132; 133) 'a': A 1369 ⋮[121; 178) '{ ... c; }': ()
1364[136; 140) 'A::b': fn b() -> A 1370 ⋮[131; 132) 'a': A
1365[136; 142) 'A::b()': A 1371 ⋮[135; 139) 'A::b': fn b() -> A
1366[148; 149) 'a': A 1372 ⋮[135; 141) 'A::b()': A
1367[159; 160) 'c': A 1373 ⋮[147; 148) 'a': A
1368[163; 167) 'A::c': fn c() -> A 1374 ⋮[158; 159) 'c': A
1369[163; 169) 'A::c()': A 1375 ⋮[162; 166) 'A::c': fn c() -> A
1370[175; 176) 'c': A"### 1376 ⋮[162; 168) 'A::c()': A
1377 ⋮[174; 175) 'c': A
1378 "###
1371 ); 1379 );
1372} 1380}
1373 1381
@@ -1540,7 +1548,7 @@ fn test() {
1540fn infer_type_alias() { 1548fn infer_type_alias() {
1541 assert_snapshot_matches!( 1549 assert_snapshot_matches!(
1542 infer(r#" 1550 infer(r#"
1543struct A<X, Y> { x: X, y: Y }; 1551struct A<X, Y> { x: X, y: Y }
1544type Foo = A<u32, i128>; 1552type Foo = A<u32, i128>;
1545type Bar<T> = A<T, u128>; 1553type Bar<T> = A<T, u128>;
1546type Baz<U, V> = A<V, U>; 1554type Baz<U, V> = A<V, U>;
@@ -1554,22 +1562,24 @@ fn test(x: Foo, y: Bar<&str>, z: Baz<i8, u8>) {
1554} 1562}
1555"#), 1563"#),
1556 @r###" 1564 @r###"
1557[117; 118) 'x': A<u32, i128> 1565
1558[125; 126) 'y': A<&str, u128> 1566 ⋮[116; 117) 'x': A<u32, i128>
1559[139; 140) 'z': A<u8, i8> 1567 ⋮[124; 125) 'y': A<&str, u128>
1560[155; 212) '{ ...z.y; }': () 1568 ⋮[138; 139) 'z': A<u8, i8>
1561[161; 162) 'x': A<u32, i128> 1569 ⋮[154; 211) '{ ...z.y; }': ()
1562[161; 164) 'x.x': u32 1570 ⋮[160; 161) 'x': A<u32, i128>
1563[170; 171) 'x': A<u32, i128> 1571 ⋮[160; 163) 'x.x': u32
1564[170; 173) 'x.y': i128 1572 ⋮[169; 170) 'x': A<u32, i128>
1565[179; 180) 'y': A<&str, u128> 1573 ⋮[169; 172) 'x.y': i128
1566[179; 182) 'y.x': &str 1574 ⋮[178; 179) 'y': A<&str, u128>
1567[188; 189) 'y': A<&str, u128> 1575 ⋮[178; 181) 'y.x': &str
1568[188; 191) 'y.y': u128 1576 ⋮[187; 188) 'y': A<&str, u128>
1569[197; 198) 'z': A<u8, i8> 1577 ⋮[187; 190) 'y.y': u128
1570[197; 200) 'z.x': u8 1578 ⋮[196; 197) 'z': A<u8, i8>
1571[206; 207) 'z': A<u8, i8> 1579 ⋮[196; 199) 'z.x': u8
1572[206; 209) 'z.y': i8"### 1580 ⋮[205; 206) 'z': A<u8, i8>
1581 ⋮[205; 208) 'z.y': i8
1582 "###
1573 ) 1583 )
1574} 1584}
1575 1585
@@ -1578,7 +1588,7 @@ fn test(x: Foo, y: Bar<&str>, z: Baz<i8, u8>) {
1578fn recursive_type_alias() { 1588fn recursive_type_alias() {
1579 assert_snapshot_matches!( 1589 assert_snapshot_matches!(
1580 infer(r#" 1590 infer(r#"
1581struct A<X> {}; 1591struct A<X> {}
1582type Foo = Foo; 1592type Foo = Foo;
1583type Bar = A<Bar>; 1593type Bar = A<Bar>;
1584fn test(x: Foo) {} 1594fn test(x: Foo) {}
@@ -1795,18 +1805,21 @@ fn infer_std_crash_3() {
1795 assert_snapshot_matches!( 1805 assert_snapshot_matches!(
1796 infer(r#" 1806 infer(r#"
1797pub fn compute() { 1807pub fn compute() {
1798 match _ { 1808 match nope!() {
1799 SizeSkeleton::Pointer { non_zero: true, tail } => {} 1809 SizeSkeleton::Pointer { non_zero: true, tail } => {}
1800 } 1810 }
1801} 1811}
1802"#), 1812"#),
1803 @r###" 1813 @r###"
1804[18; 102) '{ ... } }': () 1814
1805[24; 100) 'match ... }': () 1815 ⋮[18; 108) '{ ... } }': ()
1806[42; 88) 'SizeSk...tail }': {unknown} 1816 ⋮[24; 106) 'match ... }': ()
1807[76; 80) 'true': {unknown} 1817 ⋮[30; 37) 'nope!()': {unknown}
1808[82; 86) 'tail': {unknown} 1818 ⋮[48; 94) 'SizeSk...tail }': {unknown}
1809[92; 94) '{}': ()"### 1819 ⋮[82; 86) 'true': {unknown}
1820 ⋮[88; 92) 'tail': {unknown}
1821 ⋮[98; 100) '{}': ()
1822 "###
1810 ); 1823 );
1811} 1824}
1812 1825
@@ -1817,20 +1830,21 @@ fn infer_std_crash_4() {
1817 infer(r#" 1830 infer(r#"
1818pub fn primitive_type() { 1831pub fn primitive_type() {
1819 match *self { 1832 match *self {
1820 BorrowedRef { type_: box Primitive(p), ..} => {}, 1833 BorrowedRef { type_: Primitive(p), ..} => {},
1821 } 1834 }
1822} 1835}
1823"#), 1836"#),
1824 @r###" 1837 @r###"
1825[25; 110) '{ ... } }': () 1838
1826[31; 108) 'match ... }': () 1839 ⋮[25; 106) '{ ... } }': ()
1827[37; 42) '*self': {unknown} 1840 ⋮[31; 104) 'match ... }': ()
1828[38; 42) 'self': {unknown} 1841 ⋮[37; 42) '*self': {unknown}
1829[53; 95) 'Borrow...), ..}': {unknown} 1842 ⋮[38; 42) 'self': {unknown}
1830[74; 77) 'box': {unknown} 1843 ⋮[53; 91) 'Borrow...), ..}': {unknown}
1831[78; 87) 'Primitive': {unknown} 1844 ⋮[74; 86) 'Primitive(p)': {unknown}
1832[88; 89) 'p': {unknown} 1845 ⋮[84; 85) 'p': {unknown}
1833[99; 101) '{}': ()"### 1846 ⋮[95; 97) '{}': ()
1847 "###
1834 ); 1848 );
1835} 1849}
1836 1850
@@ -2304,8 +2318,8 @@ trait Into<T> {
2304 fn into(self) -> T; 2318 fn into(self) -> T;
2305} 2319}
2306struct S; 2320struct S;
2307impl Into<u32> for S; 2321impl Into<u32> for S {}
2308impl Into<u64> for S; 2322impl Into<u64> for S {}
2309fn test() { 2323fn test() {
2310 let x: u32 = S.into(); 2324 let x: u32 = S.into();
2311 let y: u64 = S.into(); 2325 let y: u64 = S.into();
@@ -2313,18 +2327,20 @@ fn test() {
2313} 2327}
2314"#), 2328"#),
2315 @r###" 2329 @r###"
2316[29; 33) 'self': Self 2330
2317[107; 198) '{ ...(S); }': () 2331 ⋮[29; 33) 'self': Self
2318[117; 118) 'x': u32 2332 ⋮[111; 202) '{ ...(S); }': ()
2319[126; 127) 'S': S 2333 ⋮[121; 122) 'x': u32
2320[126; 134) 'S.into()': u32 2334 ⋮[130; 131) 'S': S
2321[144; 145) 'y': u64 2335 ⋮[130; 138) 'S.into()': u32
2322[153; 154) 'S': S 2336 ⋮[148; 149) 'y': u64
2323[153; 161) 'S.into()': u64 2337 ⋮[157; 158) 'S': S
2324[171; 172) 'z': {unknown} 2338 ⋮[157; 165) 'S.into()': u64
2325[175; 192) 'Into::...::into': {unknown} 2339 ⋮[175; 176) 'z': {unknown}
2326[175; 195) 'Into::...nto(S)': {unknown} 2340 ⋮[179; 196) 'Into::...::into': {unknown}
2327[193; 194) 'S': S"### 2341 ⋮[179; 199) 'Into::...nto(S)': {unknown}
2342 ⋮[197; 198) 'S': S
2343 "###
2328 ); 2344 );
2329} 2345}
2330 2346
@@ -2617,7 +2633,7 @@ fn method_resolution_where_clause_1() {
2617trait Clone {} 2633trait Clone {}
2618trait Trait { fn foo(self) -> u128; } 2634trait Trait { fn foo(self) -> u128; }
2619struct S; 2635struct S;
2620impl Clone for S {}; 2636impl Clone for S {}
2621impl<T> Trait for T where T: Clone {} 2637impl<T> Trait for T where T: Clone {}
2622fn test() { S.foo()<|>; } 2638fn test() { S.foo()<|>; }
2623"#, 2639"#,
@@ -2634,7 +2650,7 @@ trait Into<T> { fn into(self) -> T; }
2634trait From<T> { fn from(other: T) -> Self; } 2650trait From<T> { fn from(other: T) -> Self; }
2635struct S1; 2651struct S1;
2636struct S2; 2652struct S2;
2637impl From<S2> for S1 {}; 2653impl From<S2> for S1 {}
2638impl<T, U> Into<U> for T where U: From<T> {} 2654impl<T, U> Into<U> for T where U: From<T> {}
2639fn test() { S2.into()<|>; } 2655fn test() { S2.into()<|>; }
2640"#, 2656"#,
@@ -2651,7 +2667,7 @@ trait Into<T> { fn into(self) -> T; }
2651trait From<T> { fn from(other: T) -> Self; } 2667trait From<T> { fn from(other: T) -> Self; }
2652struct S1; 2668struct S1;
2653struct S2; 2669struct S2;
2654impl From<S2> for S1 {}; 2670impl From<S2> for S1 {}
2655impl<T, U: From<T>> Into<U> for T {} 2671impl<T, U: From<T>> Into<U> for T {}
2656fn test() { S2.into()<|>; } 2672fn test() { S2.into()<|>; }
2657"#, 2673"#,
@@ -2680,8 +2696,8 @@ fn method_resolution_slow() {
2680//- /main.rs 2696//- /main.rs
2681trait SendX {} 2697trait SendX {}
2682 2698
2683struct S1; impl SendX for S1; 2699struct S1; impl SendX for S1 {}
2684struct S2; impl SendX for S2; 2700struct S2; impl SendX for S2 {}
2685struct U1; 2701struct U1;
2686 2702
2687trait Trait { fn method(self); } 2703trait Trait { fn method(self); }
@@ -2702,7 +2718,7 @@ fn test() { (S {}).method()<|>; }
2702} 2718}
2703 2719
2704fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { 2720fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String {
2705 let file = db.parse(pos.file_id); 2721 let file = db.parse(pos.file_id).ok().unwrap();
2706 let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap(); 2722 let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap();
2707 let analyzer = SourceAnalyzer::new(db, pos.file_id, expr.syntax(), Some(pos.offset)); 2723 let analyzer = SourceAnalyzer::new(db, pos.file_id, expr.syntax(), Some(pos.offset));
2708 let ty = analyzer.type_of(db, expr).unwrap(); 2724 let ty = analyzer.type_of(db, expr).unwrap();
@@ -2716,7 +2732,7 @@ fn type_at(content: &str) -> String {
2716 2732
2717fn infer(content: &str) -> String { 2733fn infer(content: &str) -> String {
2718 let (db, _, file_id) = MockDatabase::with_single_file(content); 2734 let (db, _, file_id) = MockDatabase::with_single_file(content);
2719 let source_file = db.parse(file_id); 2735 let source_file = db.parse(file_id).ok().unwrap();
2720 2736
2721 let mut acc = String::new(); 2737 let mut acc = String::new();
2722 acc.push_str("\n"); 2738 acc.push_str("\n");
@@ -2794,7 +2810,7 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
2794 ", 2810 ",
2795 ); 2811 );
2796 { 2812 {
2797 let file = db.parse(pos.file_id); 2813 let file = db.parse(pos.file_id).ok().unwrap();
2798 let node = 2814 let node =
2799 algo::find_token_at_offset(file.syntax(), pos.offset).right_biased().unwrap().parent(); 2815 algo::find_token_at_offset(file.syntax(), pos.offset).right_biased().unwrap().parent();
2800 let events = db.log_executed(|| { 2816 let events = db.log_executed(|| {
@@ -2815,7 +2831,7 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
2815 db.query_mut(ra_db::FileTextQuery).set(pos.file_id, Arc::new(new_text)); 2831 db.query_mut(ra_db::FileTextQuery).set(pos.file_id, Arc::new(new_text));
2816 2832
2817 { 2833 {
2818 let file = db.parse(pos.file_id); 2834 let file = db.parse(pos.file_id).ok().unwrap();
2819 let node = 2835 let node =
2820 algo::find_token_at_offset(file.syntax(), pos.offset).right_biased().unwrap().parent(); 2836 algo::find_token_at_offset(file.syntax(), pos.offset).right_biased().unwrap().parent();
2821 let events = db.log_executed(|| { 2837 let events = db.log_executed(|| {