1 use expect_test::expect;
4 use super::{check_infer, check_types};
10 //- /main.rs crate:main deps:std
13 let t = (x, box x, box &1, box [1]);
15 } //^ (Box<i32>, Box<Box<i32>>, Box<&i32>, Box<[i32; _]>)
18 #[prelude_import] use prelude::*;
23 pub struct Box<T: ?Sized> {
32 fn infer_box_with_allocator() {
35 //- /main.rs crate:main deps:std
38 let t = (x, box x, box &1, box [1]);
40 } //^ (Box<i32, {unknown}>, Box<Box<i32, {unknown}>, {unknown}>, Box<&i32, {unknown}>, Box<[i32; _], {unknown}>)
43 #[prelude_import] use prelude::*;
46 pub struct Box<T: ?Sized, A: Allocator> {
59 enum Nat { Succ(Self), Demo(Nat), Zero }
62 let foo: Nat = Nat::Zero;
63 if let Nat::Succ(x) = foo {
72 fn self_in_struct_lit() {
86 59..72 'Self { x: 1 }': S<u32>
93 fn type_alias_in_struct_lit() {
106 50..70 '{ ...1 }; }': ()
107 56..67 'SS { x: 1 }': S<u32>
117 //- /main.rs crate:main deps:core
126 let t = (a, b, c, d, e, f);
128 } //^ (RangeFull, RangeFrom<i32>, RangeTo<u32>, Range<usize>, RangeToInclusive<i32>, RangeInclusive<char>)
130 //- /core.rs crate:core
131 #[prelude_import] use prelude::*;
135 pub struct Range<Idx> {
139 pub struct RangeFrom<Idx> {
143 pub struct RangeInclusive<Idx> {
148 pub struct RangeTo<Idx> {
151 pub struct RangeToInclusive<Idx> {
160 fn infer_while_let() {
163 enum Option<T> { Some(T), None }
166 let foo: Option<f32> = None;
167 while let Option::Some(x) = foo {
179 fn test(a: u32, b: isize, c: !, d: &str) {
194 41..120 '{ ...f32; }': ()
199 75..81 '1usize': usize
200 87..93 '1isize': isize
201 99..105 '"test"': &str
202 111..117 '1.0f32': f32
221 10..117 '{ ...= e; }': ()
223 24..30 '1isize': isize
256 66..90 '{ ...c(); }': ()
257 72..73 'a': fn a() -> u32
259 81..85 'b::c': fn c() -> u32
266 fn infer_path_type() {
272 fn foo() -> i32 { 1 }
283 59..92 '{ ...o(); }': ()
284 65..71 'S::foo': fn foo() -> i32
285 65..73 'S::foo()': i32
286 79..87 '<S>::foo': fn foo() -> i32
287 79..89 '<S>::foo()': i32
306 let a: A = A { b: B, c: C(1) };
312 71..153 '{ ...a.c; }': ()
314 85..86 'C': C(usize) -> C
319 113..132 'A { b:...C(1) }': A
321 126..127 'C': C(usize) -> C
345 51..89 '{ ...:V2; }': ()
346 57..75 'E::V1 ...d: 1 }': E
363 let u = MyUnion { foo: 0 };
365 let u = MyUnion { bar: 0.0 };
369 unsafe fn baz(u: MyUnion) {
375 57..172 '{ ...); } }': ()
377 71..89 'MyUnio...o: 0 }': MyUnion
379 95..113 'unsafe...(u); }': ()
380 102..113 '{ baz(u); }': ()
381 104..107 'baz': fn baz(MyUnion)
382 104..110 'baz(u)': ()
383 108..109 'u': MyUnion
384 122..123 'u': MyUnion
385 126..146 'MyUnio... 0.0 }': MyUnion
387 152..170 'unsafe...(u); }': ()
388 159..170 '{ baz(u); }': ()
389 161..164 'baz': fn baz(MyUnion)
390 161..167 'baz(u)': ()
391 165..166 'u': MyUnion
392 188..189 'u': MyUnion
393 200..249 '{ ...bar; }': ()
394 210..215 'inner': u32
395 218..219 'u': MyUnion
396 218..223 'u.foo': u32
397 233..238 'inner': f32
398 241..242 'u': MyUnion
399 241..246 'u.bar': f32
408 fn test(a: &u32, b: &mut u32, c: *const u32, d: *mut u32) {
425 30..31 'c': *const u32
427 58..149 '{ ... *d; }': ()
433 87..93 '&mut a': &mut &u32
435 99..100 'b': &mut u32
437 107..108 'b': &mut u32
438 114..116 '&b': &&mut u32
439 115..116 'b': &mut u32
440 122..123 'c': *const u32
442 130..131 'c': *const u32
443 137..138 'd': *mut u32
445 145..146 'd': *mut u32
461 16..53 '{ ...t a; }': ()
462 22..32 '&raw mut a': *mut i32
464 38..50 '&raw const a': *const i32
471 fn infer_literals() {
495 10..216 '{ ...o"#; }': ()
499 46..53 '"hello"': &str
500 59..67 'b"bytes"': &[u8; _]
505 112..117 'false': bool
506 123..127 'true': bool
507 133..197 'r#" ... "#': &str
508 203..213 'br#"yolo"#': &[u8; _]
514 fn infer_unary_op() {
519 fn test(x: SomeType) {
539 39..271 '{ ...lo"; }': ()
554 145..152 '!!!true': bool
555 146..152 '!!true': bool
556 147..152 '!true': bool
557 148..152 'true': bool
562 183..189 '!10u32': u32
563 184..189 '10u32': u32
567 211..216 '-3.14': f64
571 230..232 '-x': {unknown}
572 231..232 'x': SomeType
573 238..240 '!x': {unknown}
574 239..240 'x': SomeType
575 246..254 '-"hello"': {unknown}
576 247..254 '"hello"': &str
577 260..268 '!"hello"': {unknown}
578 261..268 '"hello"': &str
584 fn infer_backwards() {
587 fn takes_u32(x: u32) {}
589 struct S { i32_field: i32 }
591 fn test() -> &mut &f64 {
592 let a = unknown_function();
594 let b = unknown_function();
596 let c = unknown_function();
603 77..230 '{ ...t &c }': &mut &f64
605 91..107 'unknow...nction': {unknown}
606 91..109 'unknow...tion()': u32
607 115..124 'takes_u32': fn takes_u32(u32)
608 115..127 'takes_u32(a)': ()
611 141..157 'unknow...nction': {unknown}
612 141..159 'unknow...tion()': i32
613 165..183 'S { i3...d: b }': S
616 197..213 'unknow...nction': {unknown}
617 197..215 'unknow...tion()': f64
618 221..228 '&mut &c': &mut &f64
635 fn test2(self: &Self) {
651 87..108 '{ ... }': ()
653 132..152 '{ ... }': S
655 176..199 '{ ... }': S
656 186..193 'Self {}': S
662 fn infer_self_as_path() {
690 86..107 '{ ... }': ()
692 134..158 '{ ... }': ()
693 144..148 'Self': S2(isize) -> S2
694 144..151 'Self(1)': S2
696 184..230 '{ ... }': ()
697 194..202 'Self::V1': E
698 212..220 'Self::V2': V2(u32) -> E
699 212..223 'Self::V2(1)': E
706 fn infer_binary_op() {
709 fn f(x: bool) -> i32 {
715 let y = true || false;
718 let minus_forty: isize = -40isize;
719 let h = minus_forty <= CONST_2;
720 let c = f(z || y) + 5;
722 let g = minus_forty ^= i;
724 let ten_is_eleven = ten == some_num;
731 21..33 '{ 0i32 }': i32
733 53..369 '{ ... < 3 }': bool
736 67..73 'a && b': bool
740 87..100 'true || false': bool
741 95..100 'false': bool
744 114..120 'x == y': bool
748 134..140 'x != y': bool
750 150..161 'minus_forty': isize
751 171..179 '-40isize': isize
752 172..179 '40isize': isize
754 193..204 'minus_forty': isize
755 193..215 'minus_...ONST_2': bool
756 208..215 'CONST_2': isize
758 229..230 'f': fn f(bool) -> i32
759 229..238 'f(z || y)': i32
760 229..242 'f(z || y) + 5': i32
762 231..237 'z || y': bool
765 252..253 'd': {unknown}
766 256..257 'b': {unknown}
768 271..282 'minus_forty': isize
769 271..287 'minus_...y ^= i': ()
771 297..300 'ten': usize
773 322..335 'ten_is_eleven': bool
774 338..341 'ten': usize
775 338..353 'ten == some_num': bool
776 345..353 'some_num': usize
777 360..363 'ten': usize
778 360..367 'ten < 3': bool
785 fn infer_shift_op() {
794 10..47 '{ ...5u8; }': ()
796 16..27 '1u32 << 5u8': u32
799 33..44 '1u32 >> 5u8': u32
806 fn infer_field_autoderef() {
823 let a5 = &mut &&mut &&mut a;
827 fn test2(a1: *const A, a2: *mut A) {
834 49..212 '{ ...5.b; }': ()
844 112..114 'a3': &mut A
845 117..123 '&mut a': &mut A
847 129..131 'a3': &mut A
849 143..145 'a4': &&&&&&&A
850 148..156 '&&&&&&&a': &&&&&&&A
851 149..156 '&&&&&&a': &&&&&&A
852 150..156 '&&&&&a': &&&&&A
853 151..156 '&&&&a': &&&&A
854 152..156 '&&&a': &&&A
858 162..164 'a4': &&&&&&&A
860 176..178 'a5': &mut &&mut &&mut A
861 181..199 '&mut &...&mut a': &mut &&mut &&mut A
862 186..199 '&&mut &&mut a': &&mut &&mut A
863 187..199 '&mut &&mut a': &mut &&mut A
864 192..199 '&&mut a': &&mut A
865 193..199 '&mut a': &mut A
867 205..207 'a5': &mut &&mut &&mut A
869 223..225 'a1': *const A
870 237..239 'a2': *mut A
871 249..272 '{ ...2.b; }': ()
872 255..257 'a1': *const A
874 265..267 'a2': *mut A
881 fn infer_argument_autoderef() {
887 fn deref(&self) -> &Self::Target;
893 fn foo(&self) -> &T {
900 impl<T> Deref for B<T> {
902 fn deref(&self) -> &Self::Target {
908 let t = A::foo(&&B(B(A(42))));
913 138..142 'self': &A<T>
914 150..173 '{ ... }': &T
915 160..167 '&self.0': &T
916 161..165 'self': &A<T>
918 254..258 'self': &B<T>
919 277..300 '{ ... }': &T
920 287..294 '&self.0': &T
921 288..292 'self': &B<T>
923 314..352 '{ ...))); }': ()
925 328..334 'A::foo': fn foo<i32>(&A<i32>) -> &i32
926 328..349 'A::foo...42))))': &i32
927 335..348 '&&B(B(A(42)))': &&B<B<A<i32>>>
928 336..348 '&B(B(A(42)))': &B<B<A<i32>>>
929 337..338 'B': B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>>
930 337..348 'B(B(A(42)))': B<B<A<i32>>>
931 339..340 'B': B<A<i32>>(A<i32>) -> B<A<i32>>
932 339..347 'B(A(42))': B<A<i32>>
933 341..342 'A': A<i32>(i32) -> A<i32>
934 341..346 'A(42)': A<i32>
941 fn infer_method_argument_autoderef() {
947 fn deref(&self) -> &Self::Target;
953 fn foo(&self, x: &A<T>) -> &T {
960 impl<T> Deref for B<T> {
962 fn deref(&self) -> &Self::Target {
968 let t = A(0 as *mut _).foo(&&B(B(a)));
973 143..147 'self': &A<T>
975 165..186 '{ ... }': &T
979 177..180 'x.0': *mut T
980 267..271 'self': &B<T>
981 290..313 '{ ... }': &T
982 300..307 '&self.0': &T
983 301..305 'self': &B<T>
986 336..382 '{ ...))); }': ()
988 350..351 'A': A<i32>(*mut i32) -> A<i32>
989 350..364 'A(0 as *mut _)': A<i32>
990 350..379 'A(0 as...B(a)))': &i32
992 352..363 '0 as *mut _': *mut i32
993 369..378 '&&B(B(a))': &&B<B<A<i32>>>
994 370..378 '&B(B(a))': &B<B<A<i32>>>
995 371..372 'B': B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>>
996 371..378 'B(B(a))': B<B<A<i32>>>
997 373..374 'B': B<A<i32>>(A<i32>) -> B<A<i32>>
998 373..377 'B(a)': B<A<i32>>
1005 fn infer_in_elseif() {
1008 struct Foo { field: i32 }
1019 44..108 '{ ... } }': ()
1020 50..106 'if tru... }': ()
1023 72..106 'if fal... }': i32
1024 75..80 'false': bool
1025 81..106 '{ ... }': i32
1027 91..100 'foo.field': i32
1033 fn infer_if_match_with_return() {
1047 let _x3 = match true {
1053 let _x4 = match true {
1059 9..322 '{ ... }; }': ()
1061 25..79 'if tru... }': i32
1063 33..50 '{ ... }': i32
1065 56..79 '{ ... }': i32
1068 95..148 'if tru... }': i32
1069 98..102 'true': bool
1070 103..120 '{ ... }': i32
1072 126..148 '{ ... }': !
1073 136..142 'return': !
1075 164..246 'match ... }': i32
1076 170..174 'true': bool
1077 185..189 'true': bool
1078 185..189 'true': bool
1081 209..240 '{ ... }': i32
1082 223..229 'return': !
1084 262..319 'match ... }': i32
1085 268..272 'true': bool
1086 283..287 'true': bool
1087 283..287 'true': bool
1090 307..313 'return': !
1096 fn infer_inherent_method() {
1102 fn foo(self, x: u32) -> i32 {}
1107 fn bar(&self, x: u64) -> i64 {}
1125 149..197 '{ ...(1); }': ()
1127 155..163 'a.foo(1)': i32
1129 169..180 '(&a).bar(1)': i64
1134 186..194 'a.bar(1)': i64
1141 fn infer_inherent_method_str() {
1146 fn foo(&self) -> i32 {}
1156 68..88 '{ ...o(); }': ()
1157 74..79 '"foo"': &str
1158 74..85 '"foo".foo()': i32
1167 fn test(x: &str, y: isize) {
1168 let a: (u32, &str) = (1, "a");
1179 27..169 '{ ...d"); }': ()
1180 37..38 'a': (u32, &str)
1181 54..62 '(1, "a")': (u32, &str)
1184 72..73 'b': ((u32, &str), &str)
1185 76..82 '(a, x)': ((u32, &str), &str)
1186 77..78 'a': (u32, &str)
1188 92..93 'c': (isize, &str)
1189 96..102 '(y, x)': (isize, &str)
1192 112..113 'd': ((isize, &str), &str)
1193 116..122 '(c, x)': ((isize, &str), &str)
1194 117..118 'c': (isize, &str)
1196 132..133 'e': (i32, &str)
1197 136..144 '(1, "e")': (i32, &str)
1199 140..143 '"e"': &str
1200 154..155 'f': ((i32, &str), &str)
1201 158..166 '(e, "d")': ((i32, &str), &str)
1202 159..160 'e': (i32, &str)
1203 162..165 '"d"': &str
1212 fn test(x: &str, y: isize) {
1217 let d = [y, 1, 2, 3];
1218 let d = [1, y, 2, 3];
1227 let x: [u8; 0] = [];
1233 27..292 '{ ... []; }': ()
1234 37..38 'a': [&str; _]
1235 41..44 '[x]': [&str; _]
1237 54..55 'b': [[&str; _]; _]
1238 58..64 '[a, a]': [[&str; _]; _]
1239 59..60 'a': [&str; _]
1240 62..63 'a': [&str; _]
1241 74..75 'c': [[[&str; _]; _]; _]
1242 78..84 '[b, b]': [[[&str; _]; _]; _]
1243 79..80 'b': [[&str; _]; _]
1244 82..83 'b': [[&str; _]; _]
1245 95..96 'd': [isize; _]
1246 99..111 '[y, 1, 2, 3]': [isize; _]
1251 121..122 'd': [isize; _]
1252 125..137 '[1, y, 2, 3]': [isize; _]
1257 147..148 'e': [isize; _]
1258 151..154 '[y]': [isize; _]
1260 164..165 'f': [[isize; _]; _]
1261 168..174 '[d, d]': [[isize; _]; _]
1262 169..170 'd': [isize; _]
1263 172..173 'd': [isize; _]
1264 184..185 'g': [[isize; _]; _]
1265 188..194 '[e, e]': [[isize; _]; _]
1266 189..190 'e': [isize; _]
1267 192..193 'e': [isize; _]
1268 205..206 'h': [i32; _]
1269 209..215 '[1, 2]': [i32; _]
1272 225..226 'i': [&str; _]
1273 229..239 '["a", "b"]': [&str; _]
1274 230..233 '"a"': &str
1275 235..238 '"b"': &str
1276 250..251 'b': [[&str; _]; _]
1277 254..264 '[a, ["b"]]': [[&str; _]; _]
1278 255..256 'a': [&str; _]
1279 258..263 '["b"]': [&str; _]
1280 259..262 '"b"': &str
1281 274..275 'x': [u8; _]
1282 287..289 '[]': [u8; _]
1288 fn infer_struct_generics() {
1295 fn test(a1: A<u32>, i: i32) {
1297 let a2 = A { x: i };
1299 let a3 = A::<i128> { x: 1 };
1306 55..146 '{ ...3.x; }': ()
1310 80..90 'A { x: i }': A<i32>
1314 110..112 'a3': A<i128>
1315 115..133 'A::<i1...x: 1 }': A<i128>
1317 139..141 'a3': A<i128>
1318 139..143 'a3.x': i128
1324 fn infer_tuple_struct_generics() {
1328 enum Option<T> { Some(T), None }
1337 let x: Option<i64> = None;
1341 75..183 '{ ...one; }': ()
1342 81..82 'A': A<i32>(i32) -> A<i32>
1343 81..86 'A(42)': A<i32>
1345 92..93 'A': A<u128>(u128) -> A<u128>
1346 92..101 'A(42u128)': A<u128>
1347 94..100 '42u128': u128
1348 107..111 'Some': Some<&str>(&str) -> Option<&str>
1349 107..116 'Some("x")': Option<&str>
1350 112..115 '"x"': &str
1351 122..134 'Option::Some': Some<&str>(&str) -> Option<&str>
1352 122..139 'Option...e("x")': Option<&str>
1353 135..138 '"x"': &str
1354 145..149 'None': Option<{unknown}>
1355 159..160 'x': Option<i64>
1356 176..180 'None': Option<i64>
1362 fn infer_function_generics() {
1365 fn id<T>(t: T) -> T { t }
1377 37..97 '{ ...(1); }': ()
1378 43..45 'id': fn id<u32>(u32) -> u32
1379 43..51 'id(1u32)': u32
1381 57..67 'id::<i128>': fn id<i128>(i128) -> i128
1382 57..70 'id::<i128>(1)': i128
1385 89..91 'id': fn id<u64>(u64) -> u64
1393 fn infer_impl_generics_basic() {
1400 impl<Y, X> A<X, Y> {
1407 fn z<T>(self, t: T) -> (X, Y, T) {
1413 let a = A { x: 1u64, y: 1i64 };
1421 73..77 'self': A<X, Y>
1422 84..106 '{ ... }': X
1423 94..98 'self': A<X, Y>
1425 116..120 'self': A<X, Y>
1426 127..149 '{ ... }': Y
1427 137..141 'self': A<X, Y>
1428 137..143 'self.y': Y
1429 162..166 'self': A<X, Y>
1431 187..222 '{ ... }': (X, Y, T)
1432 197..216 '(self.....y, t)': (X, Y, T)
1433 198..202 'self': A<X, Y>
1434 198..204 'self.x': X
1435 206..210 'self': A<X, Y>
1436 206..212 'self.y': Y
1438 244..341 '{ ...(1); }': ()
1439 254..255 'a': A<u64, i64>
1440 258..280 'A { x:...1i64 }': A<u64, i64>
1441 265..269 '1u64': u64
1442 274..278 '1i64': i64
1443 286..287 'a': A<u64, i64>
1444 286..291 'a.x()': u64
1445 297..298 'a': A<u64, i64>
1446 297..302 'a.y()': i64
1447 308..309 'a': A<u64, i64>
1448 308..318 'a.z(1i128)': (u64, i64, i128)
1449 312..317 '1i128': i128
1450 324..325 'a': A<u64, i64>
1451 324..338 'a.z::<u128>(1)': (u64, i64, u128)
1458 fn infer_impl_generics_with_autoderef() {
1466 fn as_ref(&self) -> Option<&T> {}
1468 fn test(o: Option<u32>) {
1474 77..81 'self': &Option<T>
1476 110..111 'o': Option<u32>
1477 126..164 '{ ...f(); }': ()
1478 132..145 '(&o).as_ref()': Option<&u32>
1479 133..135 '&o': &Option<u32>
1480 134..135 'o': Option<u32>
1481 151..152 'o': Option<u32>
1482 151..161 'o.as_ref()': Option<&u32>
1488 fn infer_generic_chain() {
1499 fn id<T>(t: T) -> T { t }
1504 let a = A { x: id(y) };
1511 52..56 'self': A<T2>
1512 64..86 '{ ... }': T2
1513 74..78 'self': A<T2>
1518 134..254 '{ ....x() }': i128
1522 163..165 'id': fn id<i128>(i128) -> i128
1523 163..168 'id(x)': i128
1525 178..179 'a': A<i128>
1526 182..196 'A { x: id(y) }': A<i128>
1527 189..191 'id': fn id<i128>(i128) -> i128
1528 189..194 'id(y)': i128
1531 210..212 'id': fn id<i128>(i128) -> i128
1532 210..217 'id(a.x)': i128
1533 213..214 'a': A<i128>
1534 213..216 'a.x': i128
1535 227..228 'b': A<i128>
1536 231..241 'A { x: z }': A<i128>
1538 247..248 'b': A<i128>
1539 247..252 'b.x()': i128
1545 fn infer_associated_const() {
1566 impl Trait for TraitTest {
1571 let x = Struct::FOO;
1573 let z = TraitTest::ID;
1580 228..306 '{ ...:ID; }': ()
1582 242..253 'Struct::FOO': u32
1584 267..276 'Enum::BAR': u32
1586 290..303 'TraitTest::ID': u32
1592 fn infer_type_alias() {
1595 struct A<X, Y> { x: X, y: Y }
1596 type Foo = A<u32, i128>;
1597 type Bar<T> = A<T, u128>;
1598 type Baz<U, V> = A<V, U>;
1599 fn test(x: Foo, y: Bar<&str>, z: Baz<i8, u8>) {
1609 115..116 'x': A<u32, i128>
1610 123..124 'y': A<&str, u128>
1611 137..138 'z': A<u8, i8>
1612 153..210 '{ ...z.y; }': ()
1613 159..160 'x': A<u32, i128>
1615 168..169 'x': A<u32, i128>
1616 168..171 'x.y': i128
1617 177..178 'y': A<&str, u128>
1618 177..180 'y.x': &str
1619 186..187 'y': A<&str, u128>
1620 186..189 'y.y': u128
1621 195..196 'z': A<u8, i8>
1623 204..205 'z': A<u8, i8>
1630 fn recursive_type_alias() {
1639 58..59 'x': {unknown}
1646 fn infer_type_param() {
1649 fn id<T>(x: T) -> T {
1653 fn clone<T>(x: &T) -> T {
1660 let x: bool = clone(z);
1672 77..157 '{ ...(1); }': ()
1675 102..104 'id': fn id<u32>(u32) -> u32
1676 102..107 'id(y)': u32
1679 127..132 'clone': fn clone<bool>(&bool) -> bool
1680 127..135 'clone(z)': bool
1682 141..151 'id::<i128>': fn id<i128>(i128) -> i128
1683 141..154 'id::<i128>(1)': i128
1694 impl Foo { const ASSOC_CONST: u32 = 0; }
1695 const GLOBAL_CONST: u32 = 101;
1697 const LOCAL_CONST: u32 = 99;
1698 let x = LOCAL_CONST;
1699 let z = GLOBAL_CONST;
1700 let id = Foo::ASSOC_CONST;
1706 94..212 '{ ...NST; }': ()
1708 141..152 'LOCAL_CONST': u32
1710 166..178 'GLOBAL_CONST': u32
1712 193..209 'Foo::A..._CONST': u32
1722 static GLOBAL_STATIC: u32 = 101;
1723 static mut GLOBAL_STATIC_MUT: u32 = 101;
1725 static LOCAL_STATIC: u32 = 99;
1726 static mut LOCAL_STATIC_MUT: u32 = 99;
1727 let x = LOCAL_STATIC;
1728 let y = LOCAL_STATIC_MUT;
1729 let z = GLOBAL_STATIC;
1730 let w = GLOBAL_STATIC_MUT;
1736 84..279 '{ ...MUT; }': ()
1738 176..188 'LOCAL_STATIC': u32
1740 202..218 'LOCAL_...IC_MUT': u32
1742 232..245 'GLOBAL_STATIC': u32
1744 259..276 'GLOBAL...IC_MUT': u32
1752 fn shadowing_primitive() {
1758 impl i32 { fn foo(&self) -> Foo { Foo } }
1769 fn not_shadowing_primitive_by_module() {
1777 fn foo() -> &'static str { "" }
1787 fn not_shadowing_module_by_primitive() {
1795 fn foo() -> &'static str { "" }
1804 // This test is actually testing the shadowing behavior within hir_def. It
1805 // lives here because the testing infrastructure in hir_def isn't currently
1806 // capable of asserting the necessary conditions.
1808 fn should_be_shadowing_imports() {
1812 pub fn foo() -> i8 {0}
1813 pub struct foo { a: i8 }
1815 mod b { pub fn foo () -> u8 {0} }
1816 mod c { pub struct foo { a: u8 } }
1818 pub use super::a::*;
1819 pub use super::c::foo;
1820 pub use super::b::foo;
1833 fn closure_return() {
1837 let x = || -> usize { return 1; };
1841 16..58 '{ ...; }; }': ()
1842 26..27 'x': || -> usize
1843 30..55 '|| -> ...n 1; }': || -> usize
1844 42..55 '{ return 1; }': usize
1845 44..52 'return 1': !
1852 fn closure_return_unit() {
1856 let x = || { return; };
1860 16..47 '{ ...; }; }': ()
1861 26..27 'x': || -> ()
1862 30..44 '|| { return; }': || -> ()
1863 33..44 '{ return; }': ()
1870 fn closure_return_inferred() {
1874 let x = || { "test" };
1878 16..46 '{ ..." }; }': ()
1879 26..27 'x': || -> &str
1880 30..43 '|| { "test" }': || -> &str
1881 33..43 '{ "test" }': &str
1882 35..41 '"test"': &str
1888 fn fn_pointer_return() {
1896 let vtable = Vtable { method: || {} };
1897 let m = vtable.method;
1901 47..120 '{ ...hod; }': ()
1902 57..63 'vtable': Vtable
1903 66..90 'Vtable...| {} }': Vtable
1904 83..88 '|| {}': || -> ()
1907 104..110 'vtable': Vtable
1908 104..117 'vtable.method': fn()
1914 fn effects_smoke_test() {
1918 let x = unsafe { 92 };
1919 let y = async { async { () }.await };
1921 let w = const { 92 };
1925 #[prelude_import] use future::*;
1928 #[lang = "future_trait"]
1929 pub trait Future { type Output; }
1933 16..162 '{ ...2 }; }': ()
1935 30..43 'unsafe { 92 }': i32
1936 37..43 '{ 92 }': i32
1938 53..54 'y': impl Future<Output = ()>
1939 57..85 'async ...wait }': impl Future<Output = ()>
1940 63..85 '{ asyn...wait }': ()
1941 65..77 'async { () }': impl Future<Output = ()>
1942 65..83 'async ....await': ()
1945 95..96 'z': {unknown}
1946 99..109 'try { () }': {unknown}
1947 103..109 '{ () }': ()
1950 123..135 'const { 92 }': i32
1951 129..135 '{ 92 }': i32
1954 153..159 '{ 92 }': i32
1961 fn infer_generic_from_later_assignment() {
1964 enum Option<T> { Some(T), None }
1975 59..129 '{ ... } }': ()
1976 69..76 'mut end': Option<bool>
1977 79..83 'None': Option<bool>
1978 89..127 'loop {... }': !
1979 94..127 '{ ... }': ()
1980 104..107 'end': Option<bool>
1981 104..120 'end = ...(true)': ()
1982 110..114 'Some': Some<bool>(bool) -> Option<bool>
1983 110..120 'Some(true)': Option<bool>
1984 115..119 'true': bool
1990 fn infer_loop_break_with_val() {
1993 enum Option<T> { Some(T), None }
2007 59..168 '{ ... }; }': ()
2008 69..70 'x': Option<bool>
2009 73..165 'loop {... }': Option<bool>
2010 78..165 '{ ... }': ()
2011 88..132 'if fal... }': ()
2012 91..96 'false': bool
2013 97..132 '{ ... }': ()
2014 111..121 'break None': !
2015 117..121 'None': Option<bool>
2016 142..158 'break ...(true)': !
2017 148..152 'Some': Some<bool>(bool) -> Option<bool>
2018 148..158 'Some(true)': Option<bool>
2019 153..157 'true': bool
2025 fn infer_loop_break_without_val() {
2028 enum Option<T> { Some(T), None }
2040 59..136 '{ ... }; }': ()
2042 73..133 'loop {... }': ()
2043 78..133 '{ ... }': ()
2044 88..127 'if fal... }': ()
2045 91..96 'false': bool
2046 97..127 '{ ... }': ()
2053 fn infer_labelled_break_with_val() {
2057 let _x = || 'outer: loop {
2058 let inner = 'inner: loop {
2059 let i = Default::default();
2060 if (break 'outer i) {
2061 loop { break 'inner 5i8; };
2072 9..335 '{ ... }; }': ()
2073 19..21 '_x': || -> bool
2074 24..332 '|| 'ou... }': || -> bool
2075 27..332 ''outer... }': bool
2076 40..332 '{ ... }': ()
2078 62..300 ''inner... }': i8
2079 75..300 '{ ... }': ()
2081 97..113 'Defaul...efault': {unknown}
2082 97..115 'Defaul...ault()': bool
2083 129..269 'if (br... }': ()
2084 133..147 'break 'outer i': !
2086 149..208 '{ ... }': ()
2087 167..193 'loop {...5i8; }': !
2088 172..193 '{ brea...5i8; }': ()
2089 174..190 'break ...er 5i8': !
2091 214..269 'if tru... }': ()
2092 217..221 'true': bool
2093 222..269 '{ ... }': ()
2094 240..254 'break 'inner 6': !
2096 282..289 'break 7': !
2098 310..325 'break inner < 8': !
2099 316..321 'inner': i8
2100 316..325 'inner < 8': bool
2107 fn infer_labelled_block_break_with_val() {
2110 fn default<T>() -> T { loop {} }
2113 let inner = 'inner: {
2115 if (break 'outer i) {
2120 break 'inner 'innermost: { 0 };
2123 break 'outer inner < 8;
2128 21..32 '{ loop {} }': T
2131 42..381 '{ ... }; }': ()
2133 65..378 '{ ... }': bool
2135 95..339 '{ ... }': i8
2137 117..124 'default': fn default<bool>() -> bool
2138 117..126 'default()': bool
2139 140..270 'if (br... }': ()
2140 144..158 'break 'outer i': !
2142 160..209 '{ ... }': ()
2143 178..194 'break ...er 5i8': !
2145 215..270 'if tru... }': ()
2146 218..222 'true': bool
2147 223..270 '{ ... }': ()
2148 241..255 'break 'inner 6': !
2150 283..313 'break ... { 0 }': !
2151 308..313 '{ 0 }': i8
2154 349..371 'break ...er < 8': !
2155 362..367 'inner': i8
2156 362..371 'inner < 8': bool
2163 fn generic_default() {
2166 struct Thing<T = ()> { t: T }
2167 enum OtherThing<T = ()> {
2172 fn test(t1: Thing, t2: OtherThing, t3: Thing<i32>, t4: OtherThing<i32>) {
2176 OtherThing::One { t } => { t; },
2177 OtherThing::Two(t) => { t; },
2180 OtherThing::One { t } => { t; },
2181 OtherThing::Two(t) => { t; },
2186 97..99 't1': Thing<()>
2187 108..110 't2': OtherThing<()>
2188 124..126 't3': Thing<i32>
2189 140..142 't4': OtherThing<i32>
2190 161..384 '{ ... } }': ()
2191 167..169 't1': Thing<()>
2193 177..179 't3': Thing<i32>
2194 177..181 't3.t': i32
2195 187..282 'match ... }': ()
2196 193..195 't2': OtherThing<()>
2197 206..227 'OtherT... { t }': OtherThing<()>
2199 231..237 '{ t; }': ()
2201 247..265 'OtherT...Two(t)': OtherThing<()>
2203 269..275 '{ t; }': ()
2205 287..382 'match ... }': ()
2206 293..295 't4': OtherThing<i32>
2207 306..327 'OtherT... { t }': OtherThing<i32>
2209 331..337 '{ t; }': ()
2211 347..365 'OtherT...Two(t)': OtherThing<i32>
2213 369..375 '{ t; }': ()
2220 fn generic_default_in_struct_literal() {
2223 struct Thing<T = ()> { t: T }
2224 enum OtherThing<T = ()> {
2230 let x = Thing { t: loop {} };
2231 let y = Thing { t: () };
2232 let z = Thing { t: 1i32 };
2233 if let Thing { t } = z {
2237 let a = OtherThing::One { t: 1i32 };
2238 let b = OtherThing::Two(1i32);
2242 99..319 '{ ...32); }': ()
2243 109..110 'x': Thing<!>
2244 113..133 'Thing ...p {} }': Thing<!>
2245 124..131 'loop {}': !
2247 143..144 'y': Thing<()>
2248 147..162 'Thing { t: () }': Thing<()>
2250 172..173 'z': Thing<i32>
2251 176..193 'Thing ...1i32 }': Thing<i32>
2252 187..191 '1i32': i32
2253 199..240 'if let... }': ()
2254 206..217 'Thing { t }': Thing<i32>
2256 220..221 'z': Thing<i32>
2257 222..240 '{ ... }': ()
2259 250..251 'a': OtherThing<i32>
2260 254..281 'OtherT...1i32 }': OtherThing<i32>
2261 275..279 '1i32': i32
2262 291..292 'b': OtherThing<i32>
2263 295..310 'OtherThing::Two': Two<i32>(i32) -> OtherThing<i32>
2264 295..316 'OtherT...(1i32)': OtherThing<i32>
2265 311..315 '1i32': i32
2271 fn generic_default_depending_on_other_type_arg() {
2272 // FIXME: the {unknown} is a bug
2275 struct Thing<T = u128, F = fn() -> T> { t: T }
2277 fn test(t1: Thing<u32>, t2: Thing) {
2280 Thing::<_> { t: 1u32 };
2284 56..58 't1': Thing<u32, fn() -> u32>
2285 72..74 't2': Thing<u128, fn() -> u128>
2286 83..130 '{ ...2 }; }': ()
2287 89..91 't1': Thing<u32, fn() -> u32>
2288 97..99 't2': Thing<u128, fn() -> u128>
2289 105..127 'Thing:...1u32 }': Thing<u32, fn() -> {unknown}>
2290 121..125 '1u32': u32
2296 fn generic_default_depending_on_other_type_arg_forward() {
2297 // the {unknown} here is intentional, as defaults are not allowed to
2298 // refer to type parameters coming later
2301 struct Thing<F = fn() -> T, T = u128> { t: T }
2303 fn test(t1: Thing) {
2308 56..58 't1': Thing<fn() -> {unknown}, u128>
2309 67..78 '{ t1; }': ()
2310 73..75 't1': Thing<fn() -> {unknown}, u128>
2316 fn infer_operator_overload() {
2317 mark::check!(infer_expr_inner_binary_operator_overload);
2321 struct V2([f32; 2]);
2324 pub trait Add<Rhs = Self> {
2325 /// The resulting type after applying the `+` operator.
2328 /// Performs the `+` operation.
2330 fn add(self, rhs: Rhs) -> Self::Output;
2333 impl Add<V2> for V2 {
2336 fn add(self, rhs: V2) -> V2 {
2337 let x = self.0[0] + rhs.0[0];
2338 let y = self.0[1] + rhs.0[1];
2344 let va = V2([0.0, 1.0]);
2345 let vb = V2([0.0, 1.0]);
2352 207..211 'self': Self
2356 320..422 '{ ... }': V2
2359 338..344 'self.0': [f32; _]
2360 338..347 'self.0[0]': {unknown}
2361 338..358 'self.0...s.0[0]': f32
2364 350..355 'rhs.0': [f32; _]
2365 350..358 'rhs.0[0]': {unknown}
2369 376..382 'self.0': [f32; _]
2370 376..385 'self.0[1]': {unknown}
2371 376..396 'self.0...s.0[1]': f32
2374 388..393 'rhs.0': [f32; _]
2375 388..396 'rhs.0[1]': {unknown}
2377 406..408 'V2': V2([f32; _]) -> V2
2378 406..416 'V2([x, y])': V2
2379 409..415 '[x, y]': [f32; _]
2382 436..519 '{ ... vb; }': ()
2384 451..453 'V2': V2([f32; _]) -> V2
2385 451..465 'V2([0.0, 1.0])': V2
2386 454..464 '[0.0, 1.0]': [f32; _]
2390 480..482 'V2': V2([f32; _]) -> V2
2391 480..494 'V2([0.0, 1.0])': V2
2392 483..493 '[0.0, 1.0]': [f32; _]
2397 509..516 'va + vb': V2
2404 fn infer_const_params() {
2407 fn foo<const FOO: usize>() {
2412 27..49 '{ ...FOO; }': ()