1 use expect_test::expect;
3 use super::{check_infer, check_types};
9 //- /main.rs crate:main deps:std
12 let t = (x, box x, box &1, box [1]);
14 } //^ (Box<i32>, Box<Box<i32>>, Box<&i32>, Box<[i32; _]>)
17 #[prelude_import] use prelude::*;
22 pub struct Box<T: ?Sized> {
31 fn infer_box_with_allocator() {
34 //- /main.rs crate:main deps:std
37 let t = (x, box x, box &1, box [1]);
39 } //^ (Box<i32, {unknown}>, Box<Box<i32, {unknown}>, {unknown}>, Box<&i32, {unknown}>, Box<[i32; _], {unknown}>)
42 #[prelude_import] use prelude::*;
45 pub struct Box<T: ?Sized, A: Allocator> {
58 enum Nat { Succ(Self), Demo(Nat), Zero }
61 let foo: Nat = Nat::Zero;
62 if let Nat::Succ(x) = foo {
71 fn self_in_struct_lit() {
85 59..72 'Self { x: 1 }': S<u32>
92 fn type_alias_in_struct_lit() {
105 50..70 '{ ...1 }; }': ()
106 56..67 'SS { x: 1 }': S<u32>
116 //- /main.rs crate:main deps:core
125 let t = (a, b, c, d, e, f);
127 } //^ (RangeFull, RangeFrom<i32>, RangeTo<u32>, Range<usize>, RangeToInclusive<i32>, RangeInclusive<char>)
129 //- /core.rs crate:core
130 #[prelude_import] use prelude::*;
134 pub struct Range<Idx> {
138 pub struct RangeFrom<Idx> {
142 pub struct RangeInclusive<Idx> {
147 pub struct RangeTo<Idx> {
150 pub struct RangeToInclusive<Idx> {
159 fn infer_while_let() {
162 enum Option<T> { Some(T), None }
165 let foo: Option<f32> = None;
166 while let Option::Some(x) = foo {
178 fn test(a: u32, b: isize, c: !, d: &str) {
193 41..120 '{ ...f32; }': ()
198 75..81 '1usize': usize
199 87..93 '1isize': isize
200 99..105 '"test"': &str
201 111..117 '1.0f32': f32
220 10..117 '{ ...= e; }': ()
222 24..30 '1isize': isize
255 66..90 '{ ...c(); }': ()
256 72..73 'a': fn a() -> u32
258 81..85 'b::c': fn c() -> u32
265 fn infer_path_type() {
271 fn foo() -> i32 { 1 }
282 59..92 '{ ...o(); }': ()
283 65..71 'S::foo': fn foo() -> i32
284 65..73 'S::foo()': i32
285 79..87 '<S>::foo': fn foo() -> i32
286 79..89 '<S>::foo()': i32
305 let a: A = A { b: B, c: C(1) };
311 71..153 '{ ...a.c; }': ()
313 85..86 'C': C(usize) -> C
318 113..132 'A { b:...C(1) }': A
320 126..127 'C': C(usize) -> C
344 51..89 '{ ...:V2; }': ()
345 57..75 'E::V1 ...d: 1 }': E
362 let u = MyUnion { foo: 0 };
364 let u = MyUnion { bar: 0.0 };
368 unsafe fn baz(u: MyUnion) {
374 57..172 '{ ...); } }': ()
376 71..89 'MyUnio...o: 0 }': MyUnion
378 95..113 'unsafe...(u); }': ()
379 102..113 '{ baz(u); }': ()
380 104..107 'baz': fn baz(MyUnion)
381 104..110 'baz(u)': ()
382 108..109 'u': MyUnion
383 122..123 'u': MyUnion
384 126..146 'MyUnio... 0.0 }': MyUnion
386 152..170 'unsafe...(u); }': ()
387 159..170 '{ baz(u); }': ()
388 161..164 'baz': fn baz(MyUnion)
389 161..167 'baz(u)': ()
390 165..166 'u': MyUnion
391 188..189 'u': MyUnion
392 200..249 '{ ...bar; }': ()
393 210..215 'inner': u32
394 218..219 'u': MyUnion
395 218..223 'u.foo': u32
396 233..238 'inner': f32
397 241..242 'u': MyUnion
398 241..246 'u.bar': f32
407 fn test(a: &u32, b: &mut u32, c: *const u32, d: *mut u32) {
424 30..31 'c': *const u32
426 58..149 '{ ... *d; }': ()
432 87..93 '&mut a': &mut &u32
434 99..100 'b': &mut u32
436 107..108 'b': &mut u32
437 114..116 '&b': &&mut u32
438 115..116 'b': &mut u32
439 122..123 'c': *const u32
441 130..131 'c': *const u32
442 137..138 'd': *mut u32
444 145..146 'd': *mut u32
460 16..53 '{ ...t a; }': ()
461 22..32 '&raw mut a': *mut i32
463 38..50 '&raw const a': *const i32
470 fn infer_literals() {
494 10..216 '{ ...o"#; }': ()
498 46..53 '"hello"': &str
499 59..67 'b"bytes"': &[u8; _]
504 112..117 'false': bool
505 123..127 'true': bool
506 133..197 'r#" ... "#': &str
507 203..213 'br#"yolo"#': &[u8; _]
513 fn infer_unary_op() {
518 fn test(x: SomeType) {
538 39..271 '{ ...lo"; }': ()
553 145..152 '!!!true': bool
554 146..152 '!!true': bool
555 147..152 '!true': bool
556 148..152 'true': bool
561 183..189 '!10u32': u32
562 184..189 '10u32': u32
566 211..216 '-3.14': f64
570 230..232 '-x': {unknown}
571 231..232 'x': SomeType
572 238..240 '!x': {unknown}
573 239..240 'x': SomeType
574 246..254 '-"hello"': {unknown}
575 247..254 '"hello"': &str
576 260..268 '!"hello"': {unknown}
577 261..268 '"hello"': &str
583 fn infer_backwards() {
586 fn takes_u32(x: u32) {}
588 struct S { i32_field: i32 }
590 fn test() -> &mut &f64 {
591 let a = unknown_function();
593 let b = unknown_function();
595 let c = unknown_function();
602 77..230 '{ ...t &c }': &mut &f64
604 91..107 'unknow...nction': {unknown}
605 91..109 'unknow...tion()': u32
606 115..124 'takes_u32': fn takes_u32(u32)
607 115..127 'takes_u32(a)': ()
610 141..157 'unknow...nction': {unknown}
611 141..159 'unknow...tion()': i32
612 165..183 'S { i3...d: b }': S
615 197..213 'unknow...nction': {unknown}
616 197..215 'unknow...tion()': f64
617 221..228 '&mut &c': &mut &f64
634 fn test2(self: &Self) {
650 87..108 '{ ... }': ()
652 132..152 '{ ... }': S
654 176..199 '{ ... }': S
655 186..193 'Self {}': S
661 fn infer_self_as_path() {
689 86..107 '{ ... }': ()
691 134..158 '{ ... }': ()
692 144..148 'Self': S2(isize) -> S2
693 144..151 'Self(1)': S2
695 184..230 '{ ... }': ()
696 194..202 'Self::V1': E
697 212..220 'Self::V2': V2(u32) -> E
698 212..223 'Self::V2(1)': E
705 fn infer_binary_op() {
708 fn f(x: bool) -> i32 {
714 let y = true || false;
717 let minus_forty: isize = -40isize;
718 let h = minus_forty <= CONST_2;
719 let c = f(z || y) + 5;
721 let g = minus_forty ^= i;
723 let ten_is_eleven = ten == some_num;
730 21..33 '{ 0i32 }': i32
732 53..369 '{ ... < 3 }': bool
735 67..73 'a && b': bool
739 87..100 'true || false': bool
740 95..100 'false': bool
743 114..120 'x == y': bool
747 134..140 'x != y': bool
749 150..161 'minus_forty': isize
750 171..179 '-40isize': isize
751 172..179 '40isize': isize
753 193..204 'minus_forty': isize
754 193..215 'minus_...ONST_2': bool
755 208..215 'CONST_2': isize
757 229..230 'f': fn f(bool) -> i32
758 229..238 'f(z || y)': i32
759 229..242 'f(z || y) + 5': i32
761 231..237 'z || y': bool
764 252..253 'd': {unknown}
765 256..257 'b': {unknown}
767 271..282 'minus_forty': isize
768 271..287 'minus_...y ^= i': ()
770 297..300 'ten': usize
772 322..335 'ten_is_eleven': bool
773 338..341 'ten': usize
774 338..353 'ten == some_num': bool
775 345..353 'some_num': usize
776 360..363 'ten': usize
777 360..367 'ten < 3': bool
784 fn infer_shift_op() {
793 10..47 '{ ...5u8; }': ()
795 16..27 '1u32 << 5u8': u32
798 33..44 '1u32 >> 5u8': u32
805 fn infer_field_autoderef() {
822 let a5 = &mut &&mut &&mut a;
826 fn test2(a1: *const A, a2: *mut A) {
833 49..212 '{ ...5.b; }': ()
843 112..114 'a3': &mut A
844 117..123 '&mut a': &mut A
846 129..131 'a3': &mut A
848 143..145 'a4': &&&&&&&A
849 148..156 '&&&&&&&a': &&&&&&&A
850 149..156 '&&&&&&a': &&&&&&A
851 150..156 '&&&&&a': &&&&&A
852 151..156 '&&&&a': &&&&A
853 152..156 '&&&a': &&&A
857 162..164 'a4': &&&&&&&A
859 176..178 'a5': &mut &&mut &&mut A
860 181..199 '&mut &...&mut a': &mut &&mut &&mut A
861 186..199 '&&mut &&mut a': &&mut &&mut A
862 187..199 '&mut &&mut a': &mut &&mut A
863 192..199 '&&mut a': &&mut A
864 193..199 '&mut a': &mut A
866 205..207 'a5': &mut &&mut &&mut A
868 223..225 'a1': *const A
869 237..239 'a2': *mut A
870 249..272 '{ ...2.b; }': ()
871 255..257 'a1': *const A
873 265..267 'a2': *mut A
880 fn infer_argument_autoderef() {
886 fn deref(&self) -> &Self::Target;
892 fn foo(&self) -> &T {
899 impl<T> Deref for B<T> {
901 fn deref(&self) -> &Self::Target {
907 let t = A::foo(&&B(B(A(42))));
912 138..142 'self': &A<T>
913 150..173 '{ ... }': &T
914 160..167 '&self.0': &T
915 161..165 'self': &A<T>
917 254..258 'self': &B<T>
918 277..300 '{ ... }': &T
919 287..294 '&self.0': &T
920 288..292 'self': &B<T>
922 314..352 '{ ...))); }': ()
924 328..334 'A::foo': fn foo<i32>(&A<i32>) -> &i32
925 328..349 'A::foo...42))))': &i32
926 335..348 '&&B(B(A(42)))': &&B<B<A<i32>>>
927 336..348 '&B(B(A(42)))': &B<B<A<i32>>>
928 337..338 'B': B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>>
929 337..348 'B(B(A(42)))': B<B<A<i32>>>
930 339..340 'B': B<A<i32>>(A<i32>) -> B<A<i32>>
931 339..347 'B(A(42))': B<A<i32>>
932 341..342 'A': A<i32>(i32) -> A<i32>
933 341..346 'A(42)': A<i32>
940 fn infer_method_argument_autoderef() {
946 fn deref(&self) -> &Self::Target;
952 fn foo(&self, x: &A<T>) -> &T {
959 impl<T> Deref for B<T> {
961 fn deref(&self) -> &Self::Target {
967 let t = A(0 as *mut _).foo(&&B(B(a)));
972 143..147 'self': &A<T>
974 165..186 '{ ... }': &T
978 177..180 'x.0': *mut T
979 267..271 'self': &B<T>
980 290..313 '{ ... }': &T
981 300..307 '&self.0': &T
982 301..305 'self': &B<T>
985 336..382 '{ ...))); }': ()
987 350..351 'A': A<i32>(*mut i32) -> A<i32>
988 350..364 'A(0 as *mut _)': A<i32>
989 350..379 'A(0 as...B(a)))': &i32
991 352..363 '0 as *mut _': *mut i32
992 369..378 '&&B(B(a))': &&B<B<A<i32>>>
993 370..378 '&B(B(a))': &B<B<A<i32>>>
994 371..372 'B': B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>>
995 371..378 'B(B(a))': B<B<A<i32>>>
996 373..374 'B': B<A<i32>>(A<i32>) -> B<A<i32>>
997 373..377 'B(a)': B<A<i32>>
1004 fn infer_in_elseif() {
1007 struct Foo { field: i32 }
1018 44..108 '{ ... } }': ()
1019 50..106 'if tru... }': ()
1022 72..106 'if fal... }': i32
1023 75..80 'false': bool
1024 81..106 '{ ... }': i32
1026 91..100 'foo.field': i32
1032 fn infer_if_match_with_return() {
1046 let _x3 = match true {
1052 let _x4 = match true {
1058 9..322 '{ ... }; }': ()
1060 25..79 'if tru... }': i32
1062 33..50 '{ ... }': i32
1064 56..79 '{ ... }': i32
1067 95..148 'if tru... }': i32
1068 98..102 'true': bool
1069 103..120 '{ ... }': i32
1071 126..148 '{ ... }': !
1072 136..142 'return': !
1074 164..246 'match ... }': i32
1075 170..174 'true': bool
1076 185..189 'true': bool
1077 185..189 'true': bool
1080 209..240 '{ ... }': i32
1081 223..229 'return': !
1083 262..319 'match ... }': i32
1084 268..272 'true': bool
1085 283..287 'true': bool
1086 283..287 'true': bool
1089 307..313 'return': !
1095 fn infer_inherent_method() {
1101 fn foo(self, x: u32) -> i32 {}
1106 pub fn bar(&self, x: u64) -> i64 {}
1124 153..201 '{ ...(1); }': ()
1126 159..167 'a.foo(1)': i32
1128 173..184 '(&a).bar(1)': i64
1133 190..198 'a.bar(1)': i64
1140 fn infer_inherent_method_str() {
1145 fn foo(&self) -> i32 {}
1155 68..88 '{ ...o(); }': ()
1156 74..79 '"foo"': &str
1157 74..85 '"foo".foo()': i32
1166 fn test(x: &str, y: isize) {
1167 let a: (u32, &str) = (1, "a");
1178 27..169 '{ ...d"); }': ()
1179 37..38 'a': (u32, &str)
1180 54..62 '(1, "a")': (u32, &str)
1183 72..73 'b': ((u32, &str), &str)
1184 76..82 '(a, x)': ((u32, &str), &str)
1185 77..78 'a': (u32, &str)
1187 92..93 'c': (isize, &str)
1188 96..102 '(y, x)': (isize, &str)
1191 112..113 'd': ((isize, &str), &str)
1192 116..122 '(c, x)': ((isize, &str), &str)
1193 117..118 'c': (isize, &str)
1195 132..133 'e': (i32, &str)
1196 136..144 '(1, "e")': (i32, &str)
1198 140..143 '"e"': &str
1199 154..155 'f': ((i32, &str), &str)
1200 158..166 '(e, "d")': ((i32, &str), &str)
1201 159..160 'e': (i32, &str)
1202 162..165 '"d"': &str
1211 fn test(x: &str, y: isize) {
1216 let d = [y, 1, 2, 3];
1217 let d = [1, y, 2, 3];
1226 let x: [u8; 0] = [];
1232 27..292 '{ ... []; }': ()
1233 37..38 'a': [&str; _]
1234 41..44 '[x]': [&str; _]
1236 54..55 'b': [[&str; _]; _]
1237 58..64 '[a, a]': [[&str; _]; _]
1238 59..60 'a': [&str; _]
1239 62..63 'a': [&str; _]
1240 74..75 'c': [[[&str; _]; _]; _]
1241 78..84 '[b, b]': [[[&str; _]; _]; _]
1242 79..80 'b': [[&str; _]; _]
1243 82..83 'b': [[&str; _]; _]
1244 95..96 'd': [isize; _]
1245 99..111 '[y, 1, 2, 3]': [isize; _]
1250 121..122 'd': [isize; _]
1251 125..137 '[1, y, 2, 3]': [isize; _]
1256 147..148 'e': [isize; _]
1257 151..154 '[y]': [isize; _]
1259 164..165 'f': [[isize; _]; _]
1260 168..174 '[d, d]': [[isize; _]; _]
1261 169..170 'd': [isize; _]
1262 172..173 'd': [isize; _]
1263 184..185 'g': [[isize; _]; _]
1264 188..194 '[e, e]': [[isize; _]; _]
1265 189..190 'e': [isize; _]
1266 192..193 'e': [isize; _]
1267 205..206 'h': [i32; _]
1268 209..215 '[1, 2]': [i32; _]
1271 225..226 'i': [&str; _]
1272 229..239 '["a", "b"]': [&str; _]
1273 230..233 '"a"': &str
1274 235..238 '"b"': &str
1275 250..251 'b': [[&str; _]; _]
1276 254..264 '[a, ["b"]]': [[&str; _]; _]
1277 255..256 'a': [&str; _]
1278 258..263 '["b"]': [&str; _]
1279 259..262 '"b"': &str
1280 274..275 'x': [u8; _]
1281 287..289 '[]': [u8; _]
1287 fn infer_struct_generics() {
1294 fn test(a1: A<u32>, i: i32) {
1296 let a2 = A { x: i };
1298 let a3 = A::<i128> { x: 1 };
1305 55..146 '{ ...3.x; }': ()
1309 80..90 'A { x: i }': A<i32>
1313 110..112 'a3': A<i128>
1314 115..133 'A::<i1...x: 1 }': A<i128>
1316 139..141 'a3': A<i128>
1317 139..143 'a3.x': i128
1323 fn infer_tuple_struct_generics() {
1327 enum Option<T> { Some(T), None }
1336 let x: Option<i64> = None;
1340 75..183 '{ ...one; }': ()
1341 81..82 'A': A<i32>(i32) -> A<i32>
1342 81..86 'A(42)': A<i32>
1344 92..93 'A': A<u128>(u128) -> A<u128>
1345 92..101 'A(42u128)': A<u128>
1346 94..100 '42u128': u128
1347 107..111 'Some': Some<&str>(&str) -> Option<&str>
1348 107..116 'Some("x")': Option<&str>
1349 112..115 '"x"': &str
1350 122..134 'Option::Some': Some<&str>(&str) -> Option<&str>
1351 122..139 'Option...e("x")': Option<&str>
1352 135..138 '"x"': &str
1353 145..149 'None': Option<{unknown}>
1354 159..160 'x': Option<i64>
1355 176..180 'None': Option<i64>
1361 fn infer_function_generics() {
1364 fn id<T>(t: T) -> T { t }
1376 37..97 '{ ...(1); }': ()
1377 43..45 'id': fn id<u32>(u32) -> u32
1378 43..51 'id(1u32)': u32
1380 57..67 'id::<i128>': fn id<i128>(i128) -> i128
1381 57..70 'id::<i128>(1)': i128
1384 89..91 'id': fn id<u64>(u64) -> u64
1392 fn infer_impl_generics_basic() {
1399 impl<Y, X> A<X, Y> {
1406 fn z<T>(self, t: T) -> (X, Y, T) {
1412 let a = A { x: 1u64, y: 1i64 };
1420 73..77 'self': A<X, Y>
1421 84..106 '{ ... }': X
1422 94..98 'self': A<X, Y>
1424 116..120 'self': A<X, Y>
1425 127..149 '{ ... }': Y
1426 137..141 'self': A<X, Y>
1427 137..143 'self.y': Y
1428 162..166 'self': A<X, Y>
1430 187..222 '{ ... }': (X, Y, T)
1431 197..216 '(self.....y, t)': (X, Y, T)
1432 198..202 'self': A<X, Y>
1433 198..204 'self.x': X
1434 206..210 'self': A<X, Y>
1435 206..212 'self.y': Y
1437 244..341 '{ ...(1); }': ()
1438 254..255 'a': A<u64, i64>
1439 258..280 'A { x:...1i64 }': A<u64, i64>
1440 265..269 '1u64': u64
1441 274..278 '1i64': i64
1442 286..287 'a': A<u64, i64>
1443 286..291 'a.x()': u64
1444 297..298 'a': A<u64, i64>
1445 297..302 'a.y()': i64
1446 308..309 'a': A<u64, i64>
1447 308..318 'a.z(1i128)': (u64, i64, i128)
1448 312..317 '1i128': i128
1449 324..325 'a': A<u64, i64>
1450 324..338 'a.z::<u128>(1)': (u64, i64, u128)
1457 fn infer_impl_generics_with_autoderef() {
1465 fn as_ref(&self) -> Option<&T> {}
1467 fn test(o: Option<u32>) {
1473 77..81 'self': &Option<T>
1475 110..111 'o': Option<u32>
1476 126..164 '{ ...f(); }': ()
1477 132..145 '(&o).as_ref()': Option<&u32>
1478 133..135 '&o': &Option<u32>
1479 134..135 'o': Option<u32>
1480 151..152 'o': Option<u32>
1481 151..161 'o.as_ref()': Option<&u32>
1487 fn infer_generic_chain() {
1498 fn id<T>(t: T) -> T { t }
1503 let a = A { x: id(y) };
1510 52..56 'self': A<T2>
1511 64..86 '{ ... }': T2
1512 74..78 'self': A<T2>
1517 134..254 '{ ....x() }': i128
1521 163..165 'id': fn id<i128>(i128) -> i128
1522 163..168 'id(x)': i128
1524 178..179 'a': A<i128>
1525 182..196 'A { x: id(y) }': A<i128>
1526 189..191 'id': fn id<i128>(i128) -> i128
1527 189..194 'id(y)': i128
1530 210..212 'id': fn id<i128>(i128) -> i128
1531 210..217 'id(a.x)': i128
1532 213..214 'a': A<i128>
1533 213..216 'a.x': i128
1534 227..228 'b': A<i128>
1535 231..241 'A { x: z }': A<i128>
1537 247..248 'b': A<i128>
1538 247..252 'b.x()': i128
1544 fn infer_associated_const() {
1565 impl Trait for TraitTest {
1570 let x = Struct::FOO;
1572 let z = TraitTest::ID;
1579 228..306 '{ ...:ID; }': ()
1581 242..253 'Struct::FOO': u32
1583 267..276 'Enum::BAR': u32
1585 290..303 'TraitTest::ID': u32
1591 fn infer_type_alias() {
1594 struct A<X, Y> { x: X, y: Y }
1595 type Foo = A<u32, i128>;
1596 type Bar<T> = A<T, u128>;
1597 type Baz<U, V> = A<V, U>;
1598 fn test(x: Foo, y: Bar<&str>, z: Baz<i8, u8>) {
1608 115..116 'x': A<u32, i128>
1609 123..124 'y': A<&str, u128>
1610 137..138 'z': A<u8, i8>
1611 153..210 '{ ...z.y; }': ()
1612 159..160 'x': A<u32, i128>
1614 168..169 'x': A<u32, i128>
1615 168..171 'x.y': i128
1616 177..178 'y': A<&str, u128>
1617 177..180 'y.x': &str
1618 186..187 'y': A<&str, u128>
1619 186..189 'y.y': u128
1620 195..196 'z': A<u8, i8>
1622 204..205 'z': A<u8, i8>
1629 fn recursive_type_alias() {
1638 58..59 'x': {unknown}
1645 fn infer_type_param() {
1648 fn id<T>(x: T) -> T {
1652 fn clone<T>(x: &T) -> T {
1659 let x: bool = clone(z);
1671 77..157 '{ ...(1); }': ()
1674 102..104 'id': fn id<u32>(u32) -> u32
1675 102..107 'id(y)': u32
1678 127..132 'clone': fn clone<bool>(&bool) -> bool
1679 127..135 'clone(z)': bool
1681 141..151 'id::<i128>': fn id<i128>(i128) -> i128
1682 141..154 'id::<i128>(1)': i128
1693 impl Foo { const ASSOC_CONST: u32 = 0; }
1694 const GLOBAL_CONST: u32 = 101;
1696 const LOCAL_CONST: u32 = 99;
1697 let x = LOCAL_CONST;
1698 let z = GLOBAL_CONST;
1699 let id = Foo::ASSOC_CONST;
1705 94..212 '{ ...NST; }': ()
1707 141..152 'LOCAL_CONST': u32
1709 166..178 'GLOBAL_CONST': u32
1711 193..209 'Foo::A..._CONST': u32
1721 static GLOBAL_STATIC: u32 = 101;
1722 static mut GLOBAL_STATIC_MUT: u32 = 101;
1724 static LOCAL_STATIC: u32 = 99;
1725 static mut LOCAL_STATIC_MUT: u32 = 99;
1726 let x = LOCAL_STATIC;
1727 let y = LOCAL_STATIC_MUT;
1728 let z = GLOBAL_STATIC;
1729 let w = GLOBAL_STATIC_MUT;
1735 84..279 '{ ...MUT; }': ()
1737 176..188 'LOCAL_STATIC': u32
1739 202..218 'LOCAL_...IC_MUT': u32
1741 232..245 'GLOBAL_STATIC': u32
1743 259..276 'GLOBAL...IC_MUT': u32
1751 fn shadowing_primitive() {
1757 impl i32 { fn foo(&self) -> Foo { Foo } }
1768 fn not_shadowing_primitive_by_module() {
1776 fn foo() -> &'static str { "" }
1786 fn not_shadowing_module_by_primitive() {
1794 fn foo() -> &'static str { "" }
1803 // This test is actually testing the shadowing behavior within hir_def. It
1804 // lives here because the testing infrastructure in hir_def isn't currently
1805 // capable of asserting the necessary conditions.
1807 fn should_be_shadowing_imports() {
1811 pub fn foo() -> i8 {0}
1812 pub struct foo { a: i8 }
1814 mod b { pub fn foo () -> u8 {0} }
1815 mod c { pub struct foo { a: u8 } }
1817 pub use super::a::*;
1818 pub use super::c::foo;
1819 pub use super::b::foo;
1832 fn closure_return() {
1836 let x = || -> usize { return 1; };
1840 16..58 '{ ...; }; }': ()
1841 26..27 'x': || -> usize
1842 30..55 '|| -> ...n 1; }': || -> usize
1843 42..55 '{ return 1; }': usize
1844 44..52 'return 1': !
1851 fn closure_return_unit() {
1855 let x = || { return; };
1859 16..47 '{ ...; }; }': ()
1860 26..27 'x': || -> ()
1861 30..44 '|| { return; }': || -> ()
1862 33..44 '{ return; }': ()
1869 fn closure_return_inferred() {
1873 let x = || { "test" };
1877 16..46 '{ ..." }; }': ()
1878 26..27 'x': || -> &str
1879 30..43 '|| { "test" }': || -> &str
1880 33..43 '{ "test" }': &str
1881 35..41 '"test"': &str
1887 fn fn_pointer_return() {
1895 let vtable = Vtable { method: || {} };
1896 let m = vtable.method;
1900 47..120 '{ ...hod; }': ()
1901 57..63 'vtable': Vtable
1902 66..90 'Vtable...| {} }': Vtable
1903 83..88 '|| {}': || -> ()
1906 104..110 'vtable': Vtable
1907 104..117 'vtable.method': fn()
1913 fn effects_smoke_test() {
1917 let x = unsafe { 92 };
1918 let y = async { async { () }.await };
1920 let w = const { 92 };
1924 #[prelude_import] use future::*;
1927 #[lang = "future_trait"]
1928 pub trait Future { type Output; }
1932 16..162 '{ ...2 }; }': ()
1934 30..43 'unsafe { 92 }': i32
1935 37..43 '{ 92 }': i32
1937 53..54 'y': impl Future<Output = ()>
1938 57..85 'async ...wait }': impl Future<Output = ()>
1939 63..85 '{ asyn...wait }': ()
1940 65..77 'async { () }': impl Future<Output = ()>
1941 65..83 'async ....await': ()
1944 95..96 'z': {unknown}
1945 99..109 'try { () }': {unknown}
1946 103..109 '{ () }': ()
1949 123..135 'const { 92 }': i32
1950 129..135 '{ 92 }': i32
1953 153..159 '{ 92 }': i32
1960 fn infer_generic_from_later_assignment() {
1963 enum Option<T> { Some(T), None }
1974 59..129 '{ ... } }': ()
1975 69..76 'mut end': Option<bool>
1976 79..83 'None': Option<bool>
1977 89..127 'loop {... }': !
1978 94..127 '{ ... }': ()
1979 104..107 'end': Option<bool>
1980 104..120 'end = ...(true)': ()
1981 110..114 'Some': Some<bool>(bool) -> Option<bool>
1982 110..120 'Some(true)': Option<bool>
1983 115..119 'true': bool
1989 fn infer_loop_break_with_val() {
1992 enum Option<T> { Some(T), None }
2006 59..168 '{ ... }; }': ()
2007 69..70 'x': Option<bool>
2008 73..165 'loop {... }': Option<bool>
2009 78..165 '{ ... }': ()
2010 88..132 'if fal... }': ()
2011 91..96 'false': bool
2012 97..132 '{ ... }': ()
2013 111..121 'break None': !
2014 117..121 'None': Option<bool>
2015 142..158 'break ...(true)': !
2016 148..152 'Some': Some<bool>(bool) -> Option<bool>
2017 148..158 'Some(true)': Option<bool>
2018 153..157 'true': bool
2024 fn infer_loop_break_without_val() {
2027 enum Option<T> { Some(T), None }
2039 59..136 '{ ... }; }': ()
2041 73..133 'loop {... }': ()
2042 78..133 '{ ... }': ()
2043 88..127 'if fal... }': ()
2044 91..96 'false': bool
2045 97..127 '{ ... }': ()
2052 fn infer_labelled_break_with_val() {
2056 let _x = || 'outer: loop {
2057 let inner = 'inner: loop {
2058 let i = Default::default();
2059 if (break 'outer i) {
2060 loop { break 'inner 5i8; };
2071 9..335 '{ ... }; }': ()
2072 19..21 '_x': || -> bool
2073 24..332 '|| 'ou... }': || -> bool
2074 27..332 ''outer... }': bool
2075 40..332 '{ ... }': ()
2077 62..300 ''inner... }': i8
2078 75..300 '{ ... }': ()
2080 97..113 'Defaul...efault': {unknown}
2081 97..115 'Defaul...ault()': bool
2082 129..269 'if (br... }': ()
2083 133..147 'break 'outer i': !
2085 149..208 '{ ... }': ()
2086 167..193 'loop {...5i8; }': !
2087 172..193 '{ brea...5i8; }': ()
2088 174..190 'break ...er 5i8': !
2090 214..269 'if tru... }': ()
2091 217..221 'true': bool
2092 222..269 '{ ... }': ()
2093 240..254 'break 'inner 6': !
2095 282..289 'break 7': !
2097 310..325 'break inner < 8': !
2098 316..321 'inner': i8
2099 316..325 'inner < 8': bool
2106 fn infer_labelled_block_break_with_val() {
2109 fn default<T>() -> T { loop {} }
2112 let inner = 'inner: {
2114 if (break 'outer i) {
2119 break 'inner 'innermost: { 0 };
2122 break 'outer inner < 8;
2127 21..32 '{ loop {} }': T
2130 42..381 '{ ... }; }': ()
2132 65..378 '{ ... }': bool
2134 95..339 '{ ... }': i8
2136 117..124 'default': fn default<bool>() -> bool
2137 117..126 'default()': bool
2138 140..270 'if (br... }': ()
2139 144..158 'break 'outer i': !
2141 160..209 '{ ... }': ()
2142 178..194 'break ...er 5i8': !
2144 215..270 'if tru... }': ()
2145 218..222 'true': bool
2146 223..270 '{ ... }': ()
2147 241..255 'break 'inner 6': !
2149 283..313 'break ... { 0 }': !
2150 308..313 '{ 0 }': i8
2153 349..371 'break ...er < 8': !
2154 362..367 'inner': i8
2155 362..371 'inner < 8': bool
2162 fn generic_default() {
2165 struct Thing<T = ()> { t: T }
2166 enum OtherThing<T = ()> {
2171 fn test(t1: Thing, t2: OtherThing, t3: Thing<i32>, t4: OtherThing<i32>) {
2175 OtherThing::One { t } => { t; },
2176 OtherThing::Two(t) => { t; },
2179 OtherThing::One { t } => { t; },
2180 OtherThing::Two(t) => { t; },
2185 97..99 't1': Thing<()>
2186 108..110 't2': OtherThing<()>
2187 124..126 't3': Thing<i32>
2188 140..142 't4': OtherThing<i32>
2189 161..384 '{ ... } }': ()
2190 167..169 't1': Thing<()>
2192 177..179 't3': Thing<i32>
2193 177..181 't3.t': i32
2194 187..282 'match ... }': ()
2195 193..195 't2': OtherThing<()>
2196 206..227 'OtherT... { t }': OtherThing<()>
2198 231..237 '{ t; }': ()
2200 247..265 'OtherT...Two(t)': OtherThing<()>
2202 269..275 '{ t; }': ()
2204 287..382 'match ... }': ()
2205 293..295 't4': OtherThing<i32>
2206 306..327 'OtherT... { t }': OtherThing<i32>
2208 331..337 '{ t; }': ()
2210 347..365 'OtherT...Two(t)': OtherThing<i32>
2212 369..375 '{ t; }': ()
2219 fn generic_default_in_struct_literal() {
2222 struct Thing<T = ()> { t: T }
2223 enum OtherThing<T = ()> {
2229 let x = Thing { t: loop {} };
2230 let y = Thing { t: () };
2231 let z = Thing { t: 1i32 };
2232 if let Thing { t } = z {
2236 let a = OtherThing::One { t: 1i32 };
2237 let b = OtherThing::Two(1i32);
2241 99..319 '{ ...32); }': ()
2242 109..110 'x': Thing<!>
2243 113..133 'Thing ...p {} }': Thing<!>
2244 124..131 'loop {}': !
2246 143..144 'y': Thing<()>
2247 147..162 'Thing { t: () }': Thing<()>
2249 172..173 'z': Thing<i32>
2250 176..193 'Thing ...1i32 }': Thing<i32>
2251 187..191 '1i32': i32
2252 199..240 'if let... }': ()
2253 206..217 'Thing { t }': Thing<i32>
2255 220..221 'z': Thing<i32>
2256 222..240 '{ ... }': ()
2258 250..251 'a': OtherThing<i32>
2259 254..281 'OtherT...1i32 }': OtherThing<i32>
2260 275..279 '1i32': i32
2261 291..292 'b': OtherThing<i32>
2262 295..310 'OtherThing::Two': Two<i32>(i32) -> OtherThing<i32>
2263 295..316 'OtherT...(1i32)': OtherThing<i32>
2264 311..315 '1i32': i32
2270 fn generic_default_depending_on_other_type_arg() {
2271 // FIXME: the {unknown} is a bug
2274 struct Thing<T = u128, F = fn() -> T> { t: T }
2276 fn test(t1: Thing<u32>, t2: Thing) {
2279 Thing::<_> { t: 1u32 };
2283 56..58 't1': Thing<u32, fn() -> u32>
2284 72..74 't2': Thing<u128, fn() -> u128>
2285 83..130 '{ ...2 }; }': ()
2286 89..91 't1': Thing<u32, fn() -> u32>
2287 97..99 't2': Thing<u128, fn() -> u128>
2288 105..127 'Thing:...1u32 }': Thing<u32, fn() -> {unknown}>
2289 121..125 '1u32': u32
2295 fn generic_default_depending_on_other_type_arg_forward() {
2296 // the {unknown} here is intentional, as defaults are not allowed to
2297 // refer to type parameters coming later
2300 struct Thing<F = fn() -> T, T = u128> { t: T }
2302 fn test(t1: Thing) {
2307 56..58 't1': Thing<fn() -> {unknown}, u128>
2308 67..78 '{ t1; }': ()
2309 73..75 't1': Thing<fn() -> {unknown}, u128>
2315 fn infer_operator_overload() {
2316 cov_mark::check!(infer_expr_inner_binary_operator_overload);
2320 struct V2([f32; 2]);
2323 pub trait Add<Rhs = Self> {
2324 /// The resulting type after applying the `+` operator.
2327 /// Performs the `+` operation.
2329 fn add(self, rhs: Rhs) -> Self::Output;
2332 impl Add<V2> for V2 {
2335 fn add(self, rhs: V2) -> V2 {
2336 let x = self.0[0] + rhs.0[0];
2337 let y = self.0[1] + rhs.0[1];
2343 let va = V2([0.0, 1.0]);
2344 let vb = V2([0.0, 1.0]);
2351 207..211 'self': Self
2355 320..422 '{ ... }': V2
2358 338..344 'self.0': [f32; _]
2359 338..347 'self.0[0]': {unknown}
2360 338..358 'self.0...s.0[0]': f32
2363 350..355 'rhs.0': [f32; _]
2364 350..358 'rhs.0[0]': {unknown}
2368 376..382 'self.0': [f32; _]
2369 376..385 'self.0[1]': {unknown}
2370 376..396 'self.0...s.0[1]': f32
2373 388..393 'rhs.0': [f32; _]
2374 388..396 'rhs.0[1]': {unknown}
2376 406..408 'V2': V2([f32; _]) -> V2
2377 406..416 'V2([x, y])': V2
2378 409..415 '[x, y]': [f32; _]
2381 436..519 '{ ... vb; }': ()
2383 451..453 'V2': V2([f32; _]) -> V2
2384 451..465 'V2([0.0, 1.0])': V2
2385 454..464 '[0.0, 1.0]': [f32; _]
2389 480..482 'V2': V2([f32; _]) -> V2
2390 480..494 'V2([0.0, 1.0])': V2
2391 483..493 '[0.0, 1.0]': [f32; _]
2396 509..516 'va + vb': V2
2403 fn infer_const_params() {
2406 fn foo<const FOO: usize>() {
2411 27..49 '{ ...FOO; }': ()
2419 fn infer_inner_type() {
2423 struct S { field: u32 }
2424 let s = S { field: 0 };
2429 9..89 '{ ...eld; }': ()
2431 51..65 'S { field: 0 }': S
2435 79..86 's.field': u32
2441 fn infer_nested_inner_type() {
2446 let s = S { field: 0 };
2449 struct S { field: u32 }
2453 9..109 '{ ...32 } }': ()
2454 15..79 '{ ... }': ()
2456 33..47 'S { field: 0 }': S
2460 65..72 's.field': u32
2466 fn inner_use_enum_rename() {
2483 34..123 '{ ... } }': ()
2485 71..78 'R::Info': Request
2486 84..121 'match ... }': ()
2488 102..109 'R::Info': Request
2502 pub trait Unsize<T: ?Sized> {}
2504 #[lang = "coerce_unsized"]
2505 pub trait CoerceUnsized<T> {}
2507 pub unsafe trait Allocator {}
2510 unsafe impl Allocator for Global {}
2512 #[lang = "owned_box"]
2514 pub struct Box<T: ?Sized, A: Allocator = Global>;
2516 impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<Box<U, A>> for Box<T, A> {}
2518 pub struct Vec<T, A: Allocator = Global> {}
2523 #[lang = "slice_alloc"]
2525 pub fn into_vec<A: Allocator>(self: Box<Self, A>) -> Vec<T, A> {
2531 let vec = <[_]>::into_vec(box [1i32]);
2535 569..573 'self': Box<[T], A>
2536 602..634 '{ ... }': Vec<T, A>
2537 612..628 'unimpl...ted!()': Vec<T, A>
2538 648..694 '{ ...2]); }': ()
2539 658..661 'vec': Vec<i32, Global>
2540 664..679 '<[_]>::into_vec': fn into_vec<i32, Global>(Box<[i32], Global>) -> Vec<i32, Global>
2541 664..691 '<[_]>:...1i32])': Vec<i32, Global>
2542 680..690 'box [1i32]': Box<[i32; _], Global>
2543 684..690 '[1i32]': [i32; _]
2544 685..689 '1i32': i32
2550 fn cfgd_out_assoc_items() {
2569 fn infer_type_alias_variant() {
2580 Qux::Bar(bar) => (),
2581 Qux::Baz { baz } => (),
2586 72..166 '{ ... } }': ()
2587 78..164 'match ... }': ()
2588 84..92 'Foo::Bar': Bar(i32) -> Foo
2589 84..95 'Foo::Bar(3)': Foo
2591 106..119 'Qux::Bar(bar)': Foo
2594 135..151 'Qux::B... baz }': Foo