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; 1]>)
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; 1], {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_closure_unify() {
1038 let id = if f { a } else { b };
1044 16..106 '{ ...23); }': ()
1045 26..27 'a': |i32| -> i32
1046 30..35 '|x| x': |i32| -> i32
1049 45..46 'b': |i32| -> i32
1050 49..54 '|x| x': |i32| -> i32
1053 64..66 'id': |i32| -> i32
1054 69..90 'if f {... { b }': |i32| -> i32
1056 74..79 '{ a }': |i32| -> i32
1057 76..77 'a': |i32| -> i32
1058 85..90 '{ b }': |i32| -> i32
1059 87..88 'b': |i32| -> i32
1060 96..98 'id': |i32| -> i32
1061 96..103 'id(123)': i32
1068 fn infer_if_match_with_return() {
1082 let _x3 = match true {
1088 let _x4 = match true {
1094 9..322 '{ ... }; }': ()
1096 25..79 'if tru... }': i32
1098 33..50 '{ ... }': i32
1100 56..79 '{ ... }': i32
1103 95..148 'if tru... }': i32
1104 98..102 'true': bool
1105 103..120 '{ ... }': i32
1107 126..148 '{ ... }': !
1108 136..142 'return': !
1110 164..246 'match ... }': i32
1111 170..174 'true': bool
1112 185..189 'true': bool
1113 185..189 'true': bool
1116 209..240 '{ ... }': i32
1117 223..229 'return': !
1119 262..319 'match ... }': i32
1120 268..272 'true': bool
1121 283..287 'true': bool
1122 283..287 'true': bool
1125 307..313 'return': !
1131 fn infer_inherent_method() {
1137 fn foo(self, x: u32) -> i32 {}
1142 pub fn bar(&self, x: u64) -> i64 {}
1160 153..201 '{ ...(1); }': ()
1162 159..167 'a.foo(1)': i32
1164 173..184 '(&a).bar(1)': i64
1169 190..198 'a.bar(1)': i64
1176 fn infer_inherent_method_str() {
1181 fn foo(&self) -> i32 {}
1191 68..88 '{ ...o(); }': ()
1192 74..79 '"foo"': &str
1193 74..85 '"foo".foo()': i32
1202 fn test(x: &str, y: isize) {
1203 let a: (u32, &str) = (1, "a");
1214 27..169 '{ ...d"); }': ()
1215 37..38 'a': (u32, &str)
1216 54..62 '(1, "a")': (u32, &str)
1219 72..73 'b': ((u32, &str), &str)
1220 76..82 '(a, x)': ((u32, &str), &str)
1221 77..78 'a': (u32, &str)
1223 92..93 'c': (isize, &str)
1224 96..102 '(y, x)': (isize, &str)
1227 112..113 'd': ((isize, &str), &str)
1228 116..122 '(c, x)': ((isize, &str), &str)
1229 117..118 'c': (isize, &str)
1231 132..133 'e': (i32, &str)
1232 136..144 '(1, "e")': (i32, &str)
1234 140..143 '"e"': &str
1235 154..155 'f': ((i32, &str), &str)
1236 158..166 '(e, "d")': ((i32, &str), &str)
1237 159..160 'e': (i32, &str)
1238 162..165 '"d"': &str
1247 fn test(x: &str, y: isize) {
1252 let d = [y, 1, 2, 3];
1253 let d = [1, y, 2, 3];
1262 let x: [u8; 0] = [];
1268 27..292 '{ ... []; }': ()
1269 37..38 'a': [&str; 1]
1270 41..44 '[x]': [&str; 1]
1272 54..55 'b': [[&str; 1]; 2]
1273 58..64 '[a, a]': [[&str; 1]; 2]
1274 59..60 'a': [&str; 1]
1275 62..63 'a': [&str; 1]
1276 74..75 'c': [[[&str; 1]; 2]; 2]
1277 78..84 '[b, b]': [[[&str; 1]; 2]; 2]
1278 79..80 'b': [[&str; 1]; 2]
1279 82..83 'b': [[&str; 1]; 2]
1280 95..96 'd': [isize; 4]
1281 99..111 '[y, 1, 2, 3]': [isize; 4]
1286 121..122 'd': [isize; 4]
1287 125..137 '[1, y, 2, 3]': [isize; 4]
1292 147..148 'e': [isize; 1]
1293 151..154 '[y]': [isize; 1]
1295 164..165 'f': [[isize; 4]; 2]
1296 168..174 '[d, d]': [[isize; 4]; 2]
1297 169..170 'd': [isize; 4]
1298 172..173 'd': [isize; 4]
1299 184..185 'g': [[isize; 1]; 2]
1300 188..194 '[e, e]': [[isize; 1]; 2]
1301 189..190 'e': [isize; 1]
1302 192..193 'e': [isize; 1]
1303 205..206 'h': [i32; 2]
1304 209..215 '[1, 2]': [i32; 2]
1307 225..226 'i': [&str; 2]
1308 229..239 '["a", "b"]': [&str; 2]
1309 230..233 '"a"': &str
1310 235..238 '"b"': &str
1311 250..251 'b': [[&str; 1]; 2]
1312 254..264 '[a, ["b"]]': [[&str; 1]; 2]
1313 255..256 'a': [&str; 1]
1314 258..263 '["b"]': [&str; 1]
1315 259..262 '"b"': &str
1316 274..275 'x': [u8; 0]
1317 287..289 '[]': [u8; 0]
1323 fn infer_struct_generics() {
1330 fn test(a1: A<u32>, i: i32) {
1332 let a2 = A { x: i };
1334 let a3 = A::<i128> { x: 1 };
1341 55..146 '{ ...3.x; }': ()
1345 80..90 'A { x: i }': A<i32>
1349 110..112 'a3': A<i128>
1350 115..133 'A::<i1...x: 1 }': A<i128>
1352 139..141 'a3': A<i128>
1353 139..143 'a3.x': i128
1359 fn infer_tuple_struct_generics() {
1363 enum Option<T> { Some(T), None }
1372 let x: Option<i64> = None;
1376 75..183 '{ ...one; }': ()
1377 81..82 'A': A<i32>(i32) -> A<i32>
1378 81..86 'A(42)': A<i32>
1380 92..93 'A': A<u128>(u128) -> A<u128>
1381 92..101 'A(42u128)': A<u128>
1382 94..100 '42u128': u128
1383 107..111 'Some': Some<&str>(&str) -> Option<&str>
1384 107..116 'Some("x")': Option<&str>
1385 112..115 '"x"': &str
1386 122..134 'Option::Some': Some<&str>(&str) -> Option<&str>
1387 122..139 'Option...e("x")': Option<&str>
1388 135..138 '"x"': &str
1389 145..149 'None': Option<{unknown}>
1390 159..160 'x': Option<i64>
1391 176..180 'None': Option<i64>
1397 fn infer_function_generics() {
1400 fn id<T>(t: T) -> T { t }
1412 37..97 '{ ...(1); }': ()
1413 43..45 'id': fn id<u32>(u32) -> u32
1414 43..51 'id(1u32)': u32
1416 57..67 'id::<i128>': fn id<i128>(i128) -> i128
1417 57..70 'id::<i128>(1)': i128
1420 89..91 'id': fn id<u64>(u64) -> u64
1428 fn infer_impl_generics_basic() {
1435 impl<Y, X> A<X, Y> {
1442 fn z<T>(self, t: T) -> (X, Y, T) {
1448 let a = A { x: 1u64, y: 1i64 };
1456 73..77 'self': A<X, Y>
1457 84..106 '{ ... }': X
1458 94..98 'self': A<X, Y>
1460 116..120 'self': A<X, Y>
1461 127..149 '{ ... }': Y
1462 137..141 'self': A<X, Y>
1463 137..143 'self.y': Y
1464 162..166 'self': A<X, Y>
1466 187..222 '{ ... }': (X, Y, T)
1467 197..216 '(self.....y, t)': (X, Y, T)
1468 198..202 'self': A<X, Y>
1469 198..204 'self.x': X
1470 206..210 'self': A<X, Y>
1471 206..212 'self.y': Y
1473 244..341 '{ ...(1); }': ()
1474 254..255 'a': A<u64, i64>
1475 258..280 'A { x:...1i64 }': A<u64, i64>
1476 265..269 '1u64': u64
1477 274..278 '1i64': i64
1478 286..287 'a': A<u64, i64>
1479 286..291 'a.x()': u64
1480 297..298 'a': A<u64, i64>
1481 297..302 'a.y()': i64
1482 308..309 'a': A<u64, i64>
1483 308..318 'a.z(1i128)': (u64, i64, i128)
1484 312..317 '1i128': i128
1485 324..325 'a': A<u64, i64>
1486 324..338 'a.z::<u128>(1)': (u64, i64, u128)
1493 fn infer_impl_generics_with_autoderef() {
1501 fn as_ref(&self) -> Option<&T> {}
1503 fn test(o: Option<u32>) {
1509 77..81 'self': &Option<T>
1511 110..111 'o': Option<u32>
1512 126..164 '{ ...f(); }': ()
1513 132..145 '(&o).as_ref()': Option<&u32>
1514 133..135 '&o': &Option<u32>
1515 134..135 'o': Option<u32>
1516 151..152 'o': Option<u32>
1517 151..161 'o.as_ref()': Option<&u32>
1523 fn infer_generic_chain() {
1534 fn id<T>(t: T) -> T { t }
1539 let a = A { x: id(y) };
1546 52..56 'self': A<T2>
1547 64..86 '{ ... }': T2
1548 74..78 'self': A<T2>
1553 134..254 '{ ....x() }': i128
1557 163..165 'id': fn id<i128>(i128) -> i128
1558 163..168 'id(x)': i128
1560 178..179 'a': A<i128>
1561 182..196 'A { x: id(y) }': A<i128>
1562 189..191 'id': fn id<i128>(i128) -> i128
1563 189..194 'id(y)': i128
1566 210..212 'id': fn id<i128>(i128) -> i128
1567 210..217 'id(a.x)': i128
1568 213..214 'a': A<i128>
1569 213..216 'a.x': i128
1570 227..228 'b': A<i128>
1571 231..241 'A { x: z }': A<i128>
1573 247..248 'b': A<i128>
1574 247..252 'b.x()': i128
1580 fn infer_associated_const() {
1601 impl Trait for TraitTest {
1606 let x = Struct::FOO;
1608 let z = TraitTest::ID;
1615 228..306 '{ ...:ID; }': ()
1617 242..253 'Struct::FOO': u32
1619 267..276 'Enum::BAR': u32
1621 290..303 'TraitTest::ID': u32
1627 fn infer_type_alias() {
1630 struct A<X, Y> { x: X, y: Y }
1631 type Foo = A<u32, i128>;
1632 type Bar<T> = A<T, u128>;
1633 type Baz<U, V> = A<V, U>;
1634 fn test(x: Foo, y: Bar<&str>, z: Baz<i8, u8>) {
1644 115..116 'x': A<u32, i128>
1645 123..124 'y': A<&str, u128>
1646 137..138 'z': A<u8, i8>
1647 153..210 '{ ...z.y; }': ()
1648 159..160 'x': A<u32, i128>
1650 168..169 'x': A<u32, i128>
1651 168..171 'x.y': i128
1652 177..178 'y': A<&str, u128>
1653 177..180 'y.x': &str
1654 186..187 'y': A<&str, u128>
1655 186..189 'y.y': u128
1656 195..196 'z': A<u8, i8>
1658 204..205 'z': A<u8, i8>
1665 fn recursive_type_alias() {
1674 58..59 'x': {unknown}
1681 fn infer_type_param() {
1684 fn id<T>(x: T) -> T {
1688 fn clone<T>(x: &T) -> T {
1695 let x: bool = clone(z);
1707 77..157 '{ ...(1); }': ()
1710 102..104 'id': fn id<u32>(u32) -> u32
1711 102..107 'id(y)': u32
1714 127..132 'clone': fn clone<bool>(&bool) -> bool
1715 127..135 'clone(z)': bool
1717 141..151 'id::<i128>': fn id<i128>(i128) -> i128
1718 141..154 'id::<i128>(1)': i128
1729 impl Foo { const ASSOC_CONST: u32 = 0; }
1730 const GLOBAL_CONST: u32 = 101;
1732 const LOCAL_CONST: u32 = 99;
1733 let x = LOCAL_CONST;
1734 let z = GLOBAL_CONST;
1735 let id = Foo::ASSOC_CONST;
1741 94..212 '{ ...NST; }': ()
1743 141..152 'LOCAL_CONST': u32
1745 166..178 'GLOBAL_CONST': u32
1747 193..209 'Foo::A..._CONST': u32
1757 static GLOBAL_STATIC: u32 = 101;
1758 static mut GLOBAL_STATIC_MUT: u32 = 101;
1760 static LOCAL_STATIC: u32 = 99;
1761 static mut LOCAL_STATIC_MUT: u32 = 99;
1762 let x = LOCAL_STATIC;
1763 let y = LOCAL_STATIC_MUT;
1764 let z = GLOBAL_STATIC;
1765 let w = GLOBAL_STATIC_MUT;
1771 84..279 '{ ...MUT; }': ()
1773 176..188 'LOCAL_STATIC': u32
1775 202..218 'LOCAL_...IC_MUT': u32
1777 232..245 'GLOBAL_STATIC': u32
1779 259..276 'GLOBAL...IC_MUT': u32
1787 fn shadowing_primitive() {
1793 impl i32 { fn foo(&self) -> Foo { Foo } }
1804 fn shadowing_primitive_with_inner_items() {
1810 impl i32 { fn foo(&self) -> Foo { Foo } }
1822 fn not_shadowing_primitive_by_module() {
1830 fn foo() -> &'static str { "" }
1840 fn not_shadowing_module_by_primitive() {
1848 fn foo() -> &'static str { "" }
1857 // This test is actually testing the shadowing behavior within hir_def. It
1858 // lives here because the testing infrastructure in hir_def isn't currently
1859 // capable of asserting the necessary conditions.
1861 fn should_be_shadowing_imports() {
1865 pub fn foo() -> i8 {0}
1866 pub struct foo { a: i8 }
1868 mod b { pub fn foo () -> u8 {0} }
1869 mod c { pub struct foo { a: u8 } }
1871 pub use super::a::*;
1872 pub use super::c::foo;
1873 pub use super::b::foo;
1886 fn closure_return() {
1890 let x = || -> usize { return 1; };
1894 16..58 '{ ...; }; }': ()
1895 26..27 'x': || -> usize
1896 30..55 '|| -> ...n 1; }': || -> usize
1897 42..55 '{ return 1; }': usize
1898 44..52 'return 1': !
1905 fn closure_return_unit() {
1909 let x = || { return; };
1913 16..47 '{ ...; }; }': ()
1914 26..27 'x': || -> ()
1915 30..44 '|| { return; }': || -> ()
1916 33..44 '{ return; }': ()
1923 fn closure_return_inferred() {
1927 let x = || { "test" };
1931 16..46 '{ ..." }; }': ()
1932 26..27 'x': || -> &str
1933 30..43 '|| { "test" }': || -> &str
1934 33..43 '{ "test" }': &str
1935 35..41 '"test"': &str
1941 fn fn_pointer_return() {
1949 let vtable = Vtable { method: || {} };
1950 let m = vtable.method;
1954 47..120 '{ ...hod; }': ()
1955 57..63 'vtable': Vtable
1956 66..90 'Vtable...| {} }': Vtable
1957 83..88 '|| {}': || -> ()
1960 104..110 'vtable': Vtable
1961 104..117 'vtable.method': fn()
1967 fn effects_smoke_test() {
1971 let x = unsafe { 92 };
1972 let y = async { async { () }.await };
1974 let w = const { 92 };
1978 #[prelude_import] use future::*;
1981 #[lang = "future_trait"]
1982 pub trait Future { type Output; }
1986 16..162 '{ ...2 }; }': ()
1988 30..43 'unsafe { 92 }': i32
1989 37..43 '{ 92 }': i32
1991 53..54 'y': impl Future<Output = ()>
1992 57..85 'async ...wait }': impl Future<Output = ()>
1993 63..85 '{ asyn...wait }': ()
1994 65..77 'async { () }': impl Future<Output = ()>
1995 65..83 'async ....await': ()
1998 95..96 'z': {unknown}
1999 99..109 'try { () }': {unknown}
2000 103..109 '{ () }': ()
2003 123..135 'const { 92 }': i32
2004 129..135 '{ 92 }': i32
2007 153..159 '{ 92 }': i32
2014 fn infer_generic_from_later_assignment() {
2017 enum Option<T> { Some(T), None }
2028 59..129 '{ ... } }': ()
2029 69..76 'mut end': Option<bool>
2030 79..83 'None': Option<bool>
2031 89..127 'loop {... }': !
2032 94..127 '{ ... }': ()
2033 104..107 'end': Option<bool>
2034 104..120 'end = ...(true)': ()
2035 110..114 'Some': Some<bool>(bool) -> Option<bool>
2036 110..120 'Some(true)': Option<bool>
2037 115..119 'true': bool
2043 fn infer_loop_break_with_val() {
2046 enum Option<T> { Some(T), None }
2060 59..168 '{ ... }; }': ()
2061 69..70 'x': Option<bool>
2062 73..165 'loop {... }': Option<bool>
2063 78..165 '{ ... }': ()
2064 88..132 'if fal... }': ()
2065 91..96 'false': bool
2066 97..132 '{ ... }': ()
2067 111..121 'break None': !
2068 117..121 'None': Option<bool>
2069 142..158 'break ...(true)': !
2070 148..152 'Some': Some<bool>(bool) -> Option<bool>
2071 148..158 'Some(true)': Option<bool>
2072 153..157 'true': bool
2078 fn infer_loop_break_without_val() {
2081 enum Option<T> { Some(T), None }
2093 59..136 '{ ... }; }': ()
2095 73..133 'loop {... }': ()
2096 78..133 '{ ... }': ()
2097 88..127 'if fal... }': ()
2098 91..96 'false': bool
2099 97..127 '{ ... }': ()
2106 fn infer_labelled_break_with_val() {
2110 let _x = || 'outer: loop {
2111 let inner = 'inner: loop {
2112 let i = Default::default();
2113 if (break 'outer i) {
2114 loop { break 'inner 5i8; };
2125 9..335 '{ ... }; }': ()
2126 19..21 '_x': || -> bool
2127 24..332 '|| 'ou... }': || -> bool
2128 27..332 ''outer... }': bool
2129 40..332 '{ ... }': ()
2131 62..300 ''inner... }': i8
2132 75..300 '{ ... }': ()
2134 97..113 'Defaul...efault': {unknown}
2135 97..115 'Defaul...ault()': bool
2136 129..269 'if (br... }': ()
2137 133..147 'break 'outer i': !
2139 149..208 '{ ... }': ()
2140 167..193 'loop {...5i8; }': !
2141 172..193 '{ brea...5i8; }': ()
2142 174..190 'break ...er 5i8': !
2144 214..269 'if tru... }': ()
2145 217..221 'true': bool
2146 222..269 '{ ... }': ()
2147 240..254 'break 'inner 6': !
2149 282..289 'break 7': !
2151 310..325 'break inner < 8': !
2152 316..321 'inner': i8
2153 316..325 'inner < 8': bool
2160 fn infer_labelled_block_break_with_val() {
2163 fn default<T>() -> T { loop {} }
2166 let inner = 'inner: {
2168 if (break 'outer i) {
2173 break 'inner 'innermost: { 0 };
2176 break 'outer inner < 8;
2181 21..32 '{ loop {} }': T
2184 42..381 '{ ... }; }': ()
2186 65..378 '{ ... }': bool
2188 95..339 '{ ... }': i8
2190 117..124 'default': fn default<bool>() -> bool
2191 117..126 'default()': bool
2192 140..270 'if (br... }': ()
2193 144..158 'break 'outer i': !
2195 160..209 '{ ... }': ()
2196 178..194 'break ...er 5i8': !
2198 215..270 'if tru... }': ()
2199 218..222 'true': bool
2200 223..270 '{ ... }': ()
2201 241..255 'break 'inner 6': !
2203 283..313 'break ... { 0 }': !
2204 308..313 '{ 0 }': i8
2207 349..371 'break ...er < 8': !
2208 362..367 'inner': i8
2209 362..371 'inner < 8': bool
2216 fn generic_default() {
2219 struct Thing<T = ()> { t: T }
2220 enum OtherThing<T = ()> {
2225 fn test(t1: Thing, t2: OtherThing, t3: Thing<i32>, t4: OtherThing<i32>) {
2229 OtherThing::One { t } => { t; },
2230 OtherThing::Two(t) => { t; },
2233 OtherThing::One { t } => { t; },
2234 OtherThing::Two(t) => { t; },
2239 97..99 't1': Thing<()>
2240 108..110 't2': OtherThing<()>
2241 124..126 't3': Thing<i32>
2242 140..142 't4': OtherThing<i32>
2243 161..384 '{ ... } }': ()
2244 167..169 't1': Thing<()>
2246 177..179 't3': Thing<i32>
2247 177..181 't3.t': i32
2248 187..282 'match ... }': ()
2249 193..195 't2': OtherThing<()>
2250 206..227 'OtherT... { t }': OtherThing<()>
2252 231..237 '{ t; }': ()
2254 247..265 'OtherT...Two(t)': OtherThing<()>
2256 269..275 '{ t; }': ()
2258 287..382 'match ... }': ()
2259 293..295 't4': OtherThing<i32>
2260 306..327 'OtherT... { t }': OtherThing<i32>
2262 331..337 '{ t; }': ()
2264 347..365 'OtherT...Two(t)': OtherThing<i32>
2266 369..375 '{ t; }': ()
2273 fn generic_default_in_struct_literal() {
2276 struct Thing<T = ()> { t: T }
2277 enum OtherThing<T = ()> {
2283 let x = Thing { t: loop {} };
2284 let y = Thing { t: () };
2285 let z = Thing { t: 1i32 };
2286 if let Thing { t } = z {
2290 let a = OtherThing::One { t: 1i32 };
2291 let b = OtherThing::Two(1i32);
2295 99..319 '{ ...32); }': ()
2296 109..110 'x': Thing<!>
2297 113..133 'Thing ...p {} }': Thing<!>
2298 124..131 'loop {}': !
2300 143..144 'y': Thing<()>
2301 147..162 'Thing { t: () }': Thing<()>
2303 172..173 'z': Thing<i32>
2304 176..193 'Thing ...1i32 }': Thing<i32>
2305 187..191 '1i32': i32
2306 199..240 'if let... }': ()
2307 206..217 'Thing { t }': Thing<i32>
2309 220..221 'z': Thing<i32>
2310 222..240 '{ ... }': ()
2312 250..251 'a': OtherThing<i32>
2313 254..281 'OtherT...1i32 }': OtherThing<i32>
2314 275..279 '1i32': i32
2315 291..292 'b': OtherThing<i32>
2316 295..310 'OtherThing::Two': Two<i32>(i32) -> OtherThing<i32>
2317 295..316 'OtherT...(1i32)': OtherThing<i32>
2318 311..315 '1i32': i32
2324 fn generic_default_depending_on_other_type_arg() {
2325 // FIXME: the {unknown} is a bug
2328 struct Thing<T = u128, F = fn() -> T> { t: T }
2330 fn test(t1: Thing<u32>, t2: Thing) {
2333 Thing::<_> { t: 1u32 };
2337 56..58 't1': Thing<u32, fn() -> u32>
2338 72..74 't2': Thing<u128, fn() -> u128>
2339 83..130 '{ ...2 }; }': ()
2340 89..91 't1': Thing<u32, fn() -> u32>
2341 97..99 't2': Thing<u128, fn() -> u128>
2342 105..127 'Thing:...1u32 }': Thing<u32, fn() -> {unknown}>
2343 121..125 '1u32': u32
2349 fn generic_default_depending_on_other_type_arg_forward() {
2350 // the {unknown} here is intentional, as defaults are not allowed to
2351 // refer to type parameters coming later
2354 struct Thing<F = fn() -> T, T = u128> { t: T }
2356 fn test(t1: Thing) {
2361 56..58 't1': Thing<fn() -> {unknown}, u128>
2362 67..78 '{ t1; }': ()
2363 73..75 't1': Thing<fn() -> {unknown}, u128>
2369 fn infer_operator_overload() {
2370 cov_mark::check!(infer_expr_inner_binary_operator_overload);
2374 struct V2([f32; 2]);
2377 pub trait Add<Rhs = Self> {
2378 /// The resulting type after applying the `+` operator.
2381 /// Performs the `+` operation.
2383 fn add(self, rhs: Rhs) -> Self::Output;
2386 impl Add<V2> for V2 {
2389 fn add(self, rhs: V2) -> V2 {
2390 let x = self.0[0] + rhs.0[0];
2391 let y = self.0[1] + rhs.0[1];
2397 let va = V2([0.0, 1.0]);
2398 let vb = V2([0.0, 1.0]);
2405 207..211 'self': Self
2409 320..422 '{ ... }': V2
2412 338..344 'self.0': [f32; 2]
2413 338..347 'self.0[0]': {unknown}
2414 338..358 'self.0...s.0[0]': f32
2417 350..355 'rhs.0': [f32; 2]
2418 350..358 'rhs.0[0]': {unknown}
2422 376..382 'self.0': [f32; 2]
2423 376..385 'self.0[1]': {unknown}
2424 376..396 'self.0...s.0[1]': f32
2427 388..393 'rhs.0': [f32; 2]
2428 388..396 'rhs.0[1]': {unknown}
2430 406..408 'V2': V2([f32; 2]) -> V2
2431 406..416 'V2([x, y])': V2
2432 409..415 '[x, y]': [f32; 2]
2435 436..519 '{ ... vb; }': ()
2437 451..453 'V2': V2([f32; 2]) -> V2
2438 451..465 'V2([0.0, 1.0])': V2
2439 454..464 '[0.0, 1.0]': [f32; 2]
2443 480..482 'V2': V2([f32; 2]) -> V2
2444 480..494 'V2([0.0, 1.0])': V2
2445 483..493 '[0.0, 1.0]': [f32; 2]
2450 509..516 'va + vb': V2
2457 fn infer_const_params() {
2460 fn foo<const FOO: usize>() {
2465 27..49 '{ ...FOO; }': ()
2473 fn infer_inner_type() {
2477 struct S { field: u32 }
2478 let s = S { field: 0 };
2483 9..89 '{ ...eld; }': ()
2485 51..65 'S { field: 0 }': S
2489 79..86 's.field': u32
2495 fn infer_nested_inner_type() {
2500 let s = S { field: 0 };
2503 struct S { field: u32 }
2507 9..109 '{ ...32 } }': ()
2508 15..79 '{ ... }': ()
2510 33..47 'S { field: 0 }': S
2514 65..72 's.field': u32
2520 fn inner_use_enum_rename() {
2537 34..123 '{ ... } }': ()
2539 71..78 'R::Info': Request
2540 84..121 'match ... }': ()
2542 102..109 'R::Info': Request
2556 pub trait Unsize<T: ?Sized> {}
2558 #[lang = "coerce_unsized"]
2559 pub trait CoerceUnsized<T> {}
2561 pub unsafe trait Allocator {}
2564 unsafe impl Allocator for Global {}
2566 #[lang = "owned_box"]
2568 pub struct Box<T: ?Sized, A: Allocator = Global>;
2570 impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<Box<U, A>> for Box<T, A> {}
2572 pub struct Vec<T, A: Allocator = Global> {}
2577 #[lang = "slice_alloc"]
2579 pub fn into_vec<A: Allocator>(self: Box<Self, A>) -> Vec<T, A> {
2585 let vec = <[_]>::into_vec(box [1i32]);
2589 569..573 'self': Box<[T], A>
2590 602..634 '{ ... }': Vec<T, A>
2591 612..628 'unimpl...ted!()': Vec<T, A>
2592 648..694 '{ ...2]); }': ()
2593 658..661 'vec': Vec<i32, Global>
2594 664..679 '<[_]>::into_vec': fn into_vec<i32, Global>(Box<[i32], Global>) -> Vec<i32, Global>
2595 664..691 '<[_]>:...1i32])': Vec<i32, Global>
2596 680..690 'box [1i32]': Box<[i32; 1], Global>
2597 684..690 '[1i32]': [i32; 1]
2598 685..689 '1i32': i32
2604 fn cfgd_out_assoc_items() {
2623 fn infer_type_alias_variant() {
2634 Qux::Bar(bar) => (),
2635 Qux::Baz { baz } => (),
2640 72..166 '{ ... } }': ()
2641 78..164 'match ... }': ()
2642 84..92 'Foo::Bar': Bar(i32) -> Foo
2643 84..95 'Foo::Bar(3)': Foo
2645 106..119 'Qux::Bar(bar)': Foo
2648 135..151 'Qux::B... baz }': Foo