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() {
495 let c = br#"x"\"yb"#;
499 18..478 '{ ... }': ()
503 86..93 '"hello"': &str
504 107..115 'b"bytes"': &[u8; 5]
509 200..205 'false': bool
510 219..223 'true': bool
511 237..333 'r#" ... "#': &str
512 347..357 'br#"yolo"#': &[u8; 4]
513 375..376 'a': &[u8; 4]
514 379..403 'b"a\x2... c"': &[u8; 4]
515 421..422 'b': &[u8; 4]
516 425..433 'br"g\ h"': &[u8; 4]
517 451..452 'c': &[u8; 6]
518 455..467 'br#"x"\"yb"#': &[u8; 6]
524 fn infer_unary_op() {
529 fn test(x: SomeType) {
549 39..271 '{ ...lo"; }': ()
564 145..152 '!!!true': bool
565 146..152 '!!true': bool
566 147..152 '!true': bool
567 148..152 'true': bool
572 183..189 '!10u32': u32
573 184..189 '10u32': u32
577 211..216 '-3.14': f64
581 230..232 '-x': {unknown}
582 231..232 'x': SomeType
583 238..240 '!x': {unknown}
584 239..240 'x': SomeType
585 246..254 '-"hello"': {unknown}
586 247..254 '"hello"': &str
587 260..268 '!"hello"': {unknown}
588 261..268 '"hello"': &str
594 fn infer_backwards() {
597 fn takes_u32(x: u32) {}
599 struct S { i32_field: i32 }
601 fn test() -> &mut &f64 {
602 let a = unknown_function();
604 let b = unknown_function();
606 let c = unknown_function();
613 77..230 '{ ...t &c }': &mut &f64
615 91..107 'unknow...nction': {unknown}
616 91..109 'unknow...tion()': u32
617 115..124 'takes_u32': fn takes_u32(u32)
618 115..127 'takes_u32(a)': ()
621 141..157 'unknow...nction': {unknown}
622 141..159 'unknow...tion()': i32
623 165..183 'S { i3...d: b }': S
626 197..213 'unknow...nction': {unknown}
627 197..215 'unknow...tion()': f64
628 221..228 '&mut &c': &mut &f64
645 fn test2(self: &Self) {
661 87..108 '{ ... }': ()
663 132..152 '{ ... }': S
665 176..199 '{ ... }': S
666 186..193 'Self {}': S
672 fn infer_self_as_path() {
700 86..107 '{ ... }': ()
702 134..158 '{ ... }': ()
703 144..148 'Self': S2(isize) -> S2
704 144..151 'Self(1)': S2
706 184..230 '{ ... }': ()
707 194..202 'Self::V1': E
708 212..220 'Self::V2': V2(u32) -> E
709 212..223 'Self::V2(1)': E
716 fn infer_binary_op() {
719 fn f(x: bool) -> i32 {
725 let y = true || false;
728 let minus_forty: isize = -40isize;
729 let h = minus_forty <= CONST_2;
730 let c = f(z || y) + 5;
732 let g = minus_forty ^= i;
734 let ten_is_eleven = ten == some_num;
741 21..33 '{ 0i32 }': i32
743 53..369 '{ ... < 3 }': bool
746 67..73 'a && b': bool
750 87..100 'true || false': bool
751 95..100 'false': bool
754 114..120 'x == y': bool
758 134..140 'x != y': bool
760 150..161 'minus_forty': isize
761 171..179 '-40isize': isize
762 172..179 '40isize': isize
764 193..204 'minus_forty': isize
765 193..215 'minus_...ONST_2': bool
766 208..215 'CONST_2': isize
768 229..230 'f': fn f(bool) -> i32
769 229..238 'f(z || y)': i32
770 229..242 'f(z || y) + 5': i32
772 231..237 'z || y': bool
775 252..253 'd': {unknown}
776 256..257 'b': {unknown}
778 271..282 'minus_forty': isize
779 271..287 'minus_...y ^= i': ()
781 297..300 'ten': usize
783 322..335 'ten_is_eleven': bool
784 338..341 'ten': usize
785 338..353 'ten == some_num': bool
786 345..353 'some_num': usize
787 360..363 'ten': usize
788 360..367 'ten < 3': bool
795 fn infer_shift_op() {
804 10..47 '{ ...5u8; }': ()
806 16..27 '1u32 << 5u8': u32
809 33..44 '1u32 >> 5u8': u32
816 fn infer_field_autoderef() {
833 let a5 = &mut &&mut &&mut a;
837 fn test2(a1: *const A, a2: *mut A) {
844 49..212 '{ ...5.b; }': ()
854 112..114 'a3': &mut A
855 117..123 '&mut a': &mut A
857 129..131 'a3': &mut A
859 143..145 'a4': &&&&&&&A
860 148..156 '&&&&&&&a': &&&&&&&A
861 149..156 '&&&&&&a': &&&&&&A
862 150..156 '&&&&&a': &&&&&A
863 151..156 '&&&&a': &&&&A
864 152..156 '&&&a': &&&A
868 162..164 'a4': &&&&&&&A
870 176..178 'a5': &mut &&mut &&mut A
871 181..199 '&mut &...&mut a': &mut &&mut &&mut A
872 186..199 '&&mut &&mut a': &&mut &&mut A
873 187..199 '&mut &&mut a': &mut &&mut A
874 192..199 '&&mut a': &&mut A
875 193..199 '&mut a': &mut A
877 205..207 'a5': &mut &&mut &&mut A
879 223..225 'a1': *const A
880 237..239 'a2': *mut A
881 249..272 '{ ...2.b; }': ()
882 255..257 'a1': *const A
884 265..267 'a2': *mut A
891 fn infer_argument_autoderef() {
897 fn deref(&self) -> &Self::Target;
903 fn foo(&self) -> &T {
910 impl<T> Deref for B<T> {
912 fn deref(&self) -> &Self::Target {
918 let t = A::foo(&&B(B(A(42))));
923 138..142 'self': &A<T>
924 150..173 '{ ... }': &T
925 160..167 '&self.0': &T
926 161..165 'self': &A<T>
928 254..258 'self': &B<T>
929 277..300 '{ ... }': &T
930 287..294 '&self.0': &T
931 288..292 'self': &B<T>
933 314..352 '{ ...))); }': ()
935 328..334 'A::foo': fn foo<i32>(&A<i32>) -> &i32
936 328..349 'A::foo...42))))': &i32
937 335..348 '&&B(B(A(42)))': &&B<B<A<i32>>>
938 336..348 '&B(B(A(42)))': &B<B<A<i32>>>
939 337..338 'B': B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>>
940 337..348 'B(B(A(42)))': B<B<A<i32>>>
941 339..340 'B': B<A<i32>>(A<i32>) -> B<A<i32>>
942 339..347 'B(A(42))': B<A<i32>>
943 341..342 'A': A<i32>(i32) -> A<i32>
944 341..346 'A(42)': A<i32>
951 fn infer_method_argument_autoderef() {
957 fn deref(&self) -> &Self::Target;
963 fn foo(&self, x: &A<T>) -> &T {
970 impl<T> Deref for B<T> {
972 fn deref(&self) -> &Self::Target {
978 let t = A(0 as *mut _).foo(&&B(B(a)));
983 143..147 'self': &A<T>
985 165..186 '{ ... }': &T
989 177..180 'x.0': *mut T
990 267..271 'self': &B<T>
991 290..313 '{ ... }': &T
992 300..307 '&self.0': &T
993 301..305 'self': &B<T>
996 336..382 '{ ...))); }': ()
998 350..351 'A': A<i32>(*mut i32) -> A<i32>
999 350..364 'A(0 as *mut _)': A<i32>
1000 350..379 'A(0 as...B(a)))': &i32
1002 352..363 '0 as *mut _': *mut i32
1003 369..378 '&&B(B(a))': &&B<B<A<i32>>>
1004 370..378 '&B(B(a))': &B<B<A<i32>>>
1005 371..372 'B': B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>>
1006 371..378 'B(B(a))': B<B<A<i32>>>
1007 373..374 'B': B<A<i32>>(A<i32>) -> B<A<i32>>
1008 373..377 'B(a)': B<A<i32>>
1009 375..376 'a': A<i32>
1015 fn infer_in_elseif() {
1018 struct Foo { field: i32 }
1029 44..108 '{ ... } }': ()
1030 50..106 'if tru... }': ()
1033 72..106 'if fal... }': i32
1034 75..80 'false': bool
1035 81..106 '{ ... }': i32
1037 91..100 'foo.field': i32
1043 fn infer_if_match_with_return() {
1057 let _x3 = match true {
1063 let _x4 = match true {
1069 9..322 '{ ... }; }': ()
1071 25..79 'if tru... }': i32
1073 33..50 '{ ... }': i32
1075 56..79 '{ ... }': i32
1078 95..148 'if tru... }': i32
1079 98..102 'true': bool
1080 103..120 '{ ... }': i32
1082 126..148 '{ ... }': !
1083 136..142 'return': !
1085 164..246 'match ... }': i32
1086 170..174 'true': bool
1087 185..189 'true': bool
1088 185..189 'true': bool
1091 209..240 '{ ... }': i32
1092 223..229 'return': !
1094 262..319 'match ... }': i32
1095 268..272 'true': bool
1096 283..287 'true': bool
1097 283..287 'true': bool
1100 307..313 'return': !
1106 fn infer_inherent_method() {
1112 fn foo(self, x: u32) -> i32 {}
1117 pub fn bar(&self, x: u64) -> i64 {}
1135 153..201 '{ ...(1); }': ()
1137 159..167 'a.foo(1)': i32
1139 173..184 '(&a).bar(1)': i64
1144 190..198 'a.bar(1)': i64
1151 fn infer_inherent_method_str() {
1156 fn foo(&self) -> i32 {}
1166 68..88 '{ ...o(); }': ()
1167 74..79 '"foo"': &str
1168 74..85 '"foo".foo()': i32
1177 fn test(x: &str, y: isize) {
1178 let a: (u32, &str) = (1, "a");
1189 27..169 '{ ...d"); }': ()
1190 37..38 'a': (u32, &str)
1191 54..62 '(1, "a")': (u32, &str)
1194 72..73 'b': ((u32, &str), &str)
1195 76..82 '(a, x)': ((u32, &str), &str)
1196 77..78 'a': (u32, &str)
1198 92..93 'c': (isize, &str)
1199 96..102 '(y, x)': (isize, &str)
1202 112..113 'd': ((isize, &str), &str)
1203 116..122 '(c, x)': ((isize, &str), &str)
1204 117..118 'c': (isize, &str)
1206 132..133 'e': (i32, &str)
1207 136..144 '(1, "e")': (i32, &str)
1209 140..143 '"e"': &str
1210 154..155 'f': ((i32, &str), &str)
1211 158..166 '(e, "d")': ((i32, &str), &str)
1212 159..160 'e': (i32, &str)
1213 162..165 '"d"': &str
1222 fn test(x: &str, y: isize) {
1227 let d = [y, 1, 2, 3];
1228 let d = [1, y, 2, 3];
1237 let x: [u8; 0] = [];
1238 // FIXME: requires const evaluation/taking type from rhs somehow
1239 let y: [u8; 2+2] = [1,2,3,4];
1245 27..395 '{ ...,4]; }': ()
1246 37..38 'a': [&str; 1]
1247 41..44 '[x]': [&str; 1]
1249 54..55 'b': [[&str; 1]; 2]
1250 58..64 '[a, a]': [[&str; 1]; 2]
1251 59..60 'a': [&str; 1]
1252 62..63 'a': [&str; 1]
1253 74..75 'c': [[[&str; 1]; 2]; 2]
1254 78..84 '[b, b]': [[[&str; 1]; 2]; 2]
1255 79..80 'b': [[&str; 1]; 2]
1256 82..83 'b': [[&str; 1]; 2]
1257 95..96 'd': [isize; 4]
1258 99..111 '[y, 1, 2, 3]': [isize; 4]
1263 121..122 'd': [isize; 4]
1264 125..137 '[1, y, 2, 3]': [isize; 4]
1269 147..148 'e': [isize; 1]
1270 151..154 '[y]': [isize; 1]
1272 164..165 'f': [[isize; 4]; 2]
1273 168..174 '[d, d]': [[isize; 4]; 2]
1274 169..170 'd': [isize; 4]
1275 172..173 'd': [isize; 4]
1276 184..185 'g': [[isize; 1]; 2]
1277 188..194 '[e, e]': [[isize; 1]; 2]
1278 189..190 'e': [isize; 1]
1279 192..193 'e': [isize; 1]
1280 205..206 'h': [i32; 2]
1281 209..215 '[1, 2]': [i32; 2]
1284 225..226 'i': [&str; 2]
1285 229..239 '["a", "b"]': [&str; 2]
1286 230..233 '"a"': &str
1287 235..238 '"b"': &str
1288 250..251 'b': [[&str; 1]; 2]
1289 254..264 '[a, ["b"]]': [[&str; 1]; 2]
1290 255..256 'a': [&str; 1]
1291 258..263 '["b"]': [&str; 1]
1292 259..262 '"b"': &str
1293 274..275 'x': [u8; 0]
1294 287..289 '[]': [u8; 0]
1295 368..369 'y': [u8; _]
1296 383..392 '[1,2,3,4]': [u8; 4]
1306 fn infer_struct_generics() {
1313 fn test(a1: A<u32>, i: i32) {
1315 let a2 = A { x: i };
1317 let a3 = A::<i128> { x: 1 };
1324 55..146 '{ ...3.x; }': ()
1328 80..90 'A { x: i }': A<i32>
1332 110..112 'a3': A<i128>
1333 115..133 'A::<i1...x: 1 }': A<i128>
1335 139..141 'a3': A<i128>
1336 139..143 'a3.x': i128
1342 fn infer_tuple_struct_generics() {
1346 enum Option<T> { Some(T), None }
1355 let x: Option<i64> = None;
1359 75..183 '{ ...one; }': ()
1360 81..82 'A': A<i32>(i32) -> A<i32>
1361 81..86 'A(42)': A<i32>
1363 92..93 'A': A<u128>(u128) -> A<u128>
1364 92..101 'A(42u128)': A<u128>
1365 94..100 '42u128': u128
1366 107..111 'Some': Some<&str>(&str) -> Option<&str>
1367 107..116 'Some("x")': Option<&str>
1368 112..115 '"x"': &str
1369 122..134 'Option::Some': Some<&str>(&str) -> Option<&str>
1370 122..139 'Option...e("x")': Option<&str>
1371 135..138 '"x"': &str
1372 145..149 'None': Option<{unknown}>
1373 159..160 'x': Option<i64>
1374 176..180 'None': Option<i64>
1380 fn infer_function_generics() {
1383 fn id<T>(t: T) -> T { t }
1395 37..97 '{ ...(1); }': ()
1396 43..45 'id': fn id<u32>(u32) -> u32
1397 43..51 'id(1u32)': u32
1399 57..67 'id::<i128>': fn id<i128>(i128) -> i128
1400 57..70 'id::<i128>(1)': i128
1403 89..91 'id': fn id<u64>(u64) -> u64
1411 fn infer_impl_generics_basic() {
1418 impl<Y, X> A<X, Y> {
1425 fn z<T>(self, t: T) -> (X, Y, T) {
1431 let a = A { x: 1u64, y: 1i64 };
1439 73..77 'self': A<X, Y>
1440 84..106 '{ ... }': X
1441 94..98 'self': A<X, Y>
1443 116..120 'self': A<X, Y>
1444 127..149 '{ ... }': Y
1445 137..141 'self': A<X, Y>
1446 137..143 'self.y': Y
1447 162..166 'self': A<X, Y>
1449 187..222 '{ ... }': (X, Y, T)
1450 197..216 '(self.....y, t)': (X, Y, T)
1451 198..202 'self': A<X, Y>
1452 198..204 'self.x': X
1453 206..210 'self': A<X, Y>
1454 206..212 'self.y': Y
1456 244..341 '{ ...(1); }': ()
1457 254..255 'a': A<u64, i64>
1458 258..280 'A { x:...1i64 }': A<u64, i64>
1459 265..269 '1u64': u64
1460 274..278 '1i64': i64
1461 286..287 'a': A<u64, i64>
1462 286..291 'a.x()': u64
1463 297..298 'a': A<u64, i64>
1464 297..302 'a.y()': i64
1465 308..309 'a': A<u64, i64>
1466 308..318 'a.z(1i128)': (u64, i64, i128)
1467 312..317 '1i128': i128
1468 324..325 'a': A<u64, i64>
1469 324..338 'a.z::<u128>(1)': (u64, i64, u128)
1476 fn infer_impl_generics_with_autoderef() {
1484 fn as_ref(&self) -> Option<&T> {}
1486 fn test(o: Option<u32>) {
1492 77..81 'self': &Option<T>
1494 110..111 'o': Option<u32>
1495 126..164 '{ ...f(); }': ()
1496 132..145 '(&o).as_ref()': Option<&u32>
1497 133..135 '&o': &Option<u32>
1498 134..135 'o': Option<u32>
1499 151..152 'o': Option<u32>
1500 151..161 'o.as_ref()': Option<&u32>
1506 fn infer_generic_chain() {
1517 fn id<T>(t: T) -> T { t }
1522 let a = A { x: id(y) };
1529 52..56 'self': A<T2>
1530 64..86 '{ ... }': T2
1531 74..78 'self': A<T2>
1536 134..254 '{ ....x() }': i128
1540 163..165 'id': fn id<i128>(i128) -> i128
1541 163..168 'id(x)': i128
1543 178..179 'a': A<i128>
1544 182..196 'A { x: id(y) }': A<i128>
1545 189..191 'id': fn id<i128>(i128) -> i128
1546 189..194 'id(y)': i128
1549 210..212 'id': fn id<i128>(i128) -> i128
1550 210..217 'id(a.x)': i128
1551 213..214 'a': A<i128>
1552 213..216 'a.x': i128
1553 227..228 'b': A<i128>
1554 231..241 'A { x: z }': A<i128>
1556 247..248 'b': A<i128>
1557 247..252 'b.x()': i128
1563 fn infer_associated_const() {
1584 impl Trait for TraitTest {
1589 let x = Struct::FOO;
1591 let z = TraitTest::ID;
1598 228..306 '{ ...:ID; }': ()
1600 242..253 'Struct::FOO': u32
1602 267..276 'Enum::BAR': u32
1604 290..303 'TraitTest::ID': u32
1610 fn infer_type_alias() {
1613 struct A<X, Y> { x: X, y: Y }
1614 type Foo = A<u32, i128>;
1615 type Bar<T> = A<T, u128>;
1616 type Baz<U, V> = A<V, U>;
1617 fn test(x: Foo, y: Bar<&str>, z: Baz<i8, u8>) {
1627 115..116 'x': A<u32, i128>
1628 123..124 'y': A<&str, u128>
1629 137..138 'z': A<u8, i8>
1630 153..210 '{ ...z.y; }': ()
1631 159..160 'x': A<u32, i128>
1633 168..169 'x': A<u32, i128>
1634 168..171 'x.y': i128
1635 177..178 'y': A<&str, u128>
1636 177..180 'y.x': &str
1637 186..187 'y': A<&str, u128>
1638 186..189 'y.y': u128
1639 195..196 'z': A<u8, i8>
1641 204..205 'z': A<u8, i8>
1648 fn recursive_type_alias() {
1657 58..59 'x': {unknown}
1664 fn infer_type_param() {
1667 fn id<T>(x: T) -> T {
1671 fn clone<T>(x: &T) -> T {
1678 let x: bool = clone(z);
1690 77..157 '{ ...(1); }': ()
1693 102..104 'id': fn id<u32>(u32) -> u32
1694 102..107 'id(y)': u32
1697 127..132 'clone': fn clone<bool>(&bool) -> bool
1698 127..135 'clone(z)': bool
1700 141..151 'id::<i128>': fn id<i128>(i128) -> i128
1701 141..154 'id::<i128>(1)': i128
1712 impl Foo { const ASSOC_CONST: u32 = 0; }
1713 const GLOBAL_CONST: u32 = 101;
1715 const LOCAL_CONST: u32 = 99;
1716 let x = LOCAL_CONST;
1717 let z = GLOBAL_CONST;
1718 let id = Foo::ASSOC_CONST;
1724 94..212 '{ ...NST; }': ()
1726 141..152 'LOCAL_CONST': u32
1728 166..178 'GLOBAL_CONST': u32
1730 193..209 'Foo::A..._CONST': u32
1740 static GLOBAL_STATIC: u32 = 101;
1741 static mut GLOBAL_STATIC_MUT: u32 = 101;
1743 static LOCAL_STATIC: u32 = 99;
1744 static mut LOCAL_STATIC_MUT: u32 = 99;
1745 let x = LOCAL_STATIC;
1746 let y = LOCAL_STATIC_MUT;
1747 let z = GLOBAL_STATIC;
1748 let w = GLOBAL_STATIC_MUT;
1754 84..279 '{ ...MUT; }': ()
1756 176..188 'LOCAL_STATIC': u32
1758 202..218 'LOCAL_...IC_MUT': u32
1760 232..245 'GLOBAL_STATIC': u32
1762 259..276 'GLOBAL...IC_MUT': u32
1770 fn shadowing_primitive() {
1776 impl i32 { fn foo(&self) -> Foo { Foo } }
1787 fn shadowing_primitive_with_inner_items() {
1793 impl i32 { fn foo(&self) -> Foo { Foo } }
1805 fn not_shadowing_primitive_by_module() {
1813 fn foo() -> &'static str { "" }
1823 fn not_shadowing_module_by_primitive() {
1831 fn foo() -> &'static str { "" }
1840 // This test is actually testing the shadowing behavior within hir_def. It
1841 // lives here because the testing infrastructure in hir_def isn't currently
1842 // capable of asserting the necessary conditions.
1844 fn should_be_shadowing_imports() {
1848 pub fn foo() -> i8 {0}
1849 pub struct foo { a: i8 }
1851 mod b { pub fn foo () -> u8 {0} }
1852 mod c { pub struct foo { a: u8 } }
1854 pub use super::a::*;
1855 pub use super::c::foo;
1856 pub use super::b::foo;
1869 fn closure_return() {
1873 let x = || -> usize { return 1; };
1877 16..58 '{ ...; }; }': ()
1878 26..27 'x': || -> usize
1879 30..55 '|| -> ...n 1; }': || -> usize
1880 42..55 '{ return 1; }': usize
1881 44..52 'return 1': !
1888 fn closure_return_unit() {
1892 let x = || { return; };
1896 16..47 '{ ...; }; }': ()
1897 26..27 'x': || -> ()
1898 30..44 '|| { return; }': || -> ()
1899 33..44 '{ return; }': ()
1906 fn closure_return_inferred() {
1910 let x = || { "test" };
1914 16..46 '{ ..." }; }': ()
1915 26..27 'x': || -> &str
1916 30..43 '|| { "test" }': || -> &str
1917 33..43 '{ "test" }': &str
1918 35..41 '"test"': &str
1924 fn fn_pointer_return() {
1932 let vtable = Vtable { method: || {} };
1933 let m = vtable.method;
1937 47..120 '{ ...hod; }': ()
1938 57..63 'vtable': Vtable
1939 66..90 'Vtable...| {} }': Vtable
1940 83..88 '|| {}': || -> ()
1943 104..110 'vtable': Vtable
1944 104..117 'vtable.method': fn()
1950 fn effects_smoke_test() {
1954 let x = unsafe { 92 };
1955 let y = async { async { () }.await };
1957 let w = const { 92 };
1961 #[prelude_import] use future::*;
1964 #[lang = "future_trait"]
1965 pub trait Future { type Output; }
1969 16..162 '{ ...2 }; }': ()
1971 30..43 'unsafe { 92 }': i32
1972 37..43 '{ 92 }': i32
1974 53..54 'y': impl Future<Output = ()>
1975 57..85 'async ...wait }': impl Future<Output = ()>
1976 63..85 '{ asyn...wait }': ()
1977 65..77 'async { () }': impl Future<Output = ()>
1978 65..83 'async ....await': ()
1981 95..96 'z': {unknown}
1982 99..109 'try { () }': {unknown}
1983 103..109 '{ () }': ()
1986 123..135 'const { 92 }': i32
1987 129..135 '{ 92 }': i32
1990 153..159 '{ 92 }': i32
1997 fn infer_generic_from_later_assignment() {
2000 enum Option<T> { Some(T), None }
2011 59..129 '{ ... } }': ()
2012 69..76 'mut end': Option<bool>
2013 79..83 'None': Option<bool>
2014 89..127 'loop {... }': !
2015 94..127 '{ ... }': ()
2016 104..107 'end': Option<bool>
2017 104..120 'end = ...(true)': ()
2018 110..114 'Some': Some<bool>(bool) -> Option<bool>
2019 110..120 'Some(true)': Option<bool>
2020 115..119 'true': bool
2026 fn infer_loop_break_with_val() {
2029 enum Option<T> { Some(T), None }
2043 59..168 '{ ... }; }': ()
2044 69..70 'x': Option<bool>
2045 73..165 'loop {... }': Option<bool>
2046 78..165 '{ ... }': ()
2047 88..132 'if fal... }': ()
2048 91..96 'false': bool
2049 97..132 '{ ... }': ()
2050 111..121 'break None': !
2051 117..121 'None': Option<bool>
2052 142..158 'break ...(true)': !
2053 148..152 'Some': Some<bool>(bool) -> Option<bool>
2054 148..158 'Some(true)': Option<bool>
2055 153..157 'true': bool
2061 fn infer_loop_break_without_val() {
2064 enum Option<T> { Some(T), None }
2076 59..136 '{ ... }; }': ()
2078 73..133 'loop {... }': ()
2079 78..133 '{ ... }': ()
2080 88..127 'if fal... }': ()
2081 91..96 'false': bool
2082 97..127 '{ ... }': ()
2089 fn infer_labelled_break_with_val() {
2093 let _x = || 'outer: loop {
2094 let inner = 'inner: loop {
2095 let i = Default::default();
2096 if (break 'outer i) {
2097 loop { break 'inner 5i8; };
2108 9..335 '{ ... }; }': ()
2109 19..21 '_x': || -> bool
2110 24..332 '|| 'ou... }': || -> bool
2111 27..332 ''outer... }': bool
2112 40..332 '{ ... }': ()
2114 62..300 ''inner... }': i8
2115 75..300 '{ ... }': ()
2117 97..113 'Defaul...efault': {unknown}
2118 97..115 'Defaul...ault()': bool
2119 129..269 'if (br... }': ()
2120 133..147 'break 'outer i': !
2122 149..208 '{ ... }': ()
2123 167..193 'loop {...5i8; }': !
2124 172..193 '{ brea...5i8; }': ()
2125 174..190 'break ...er 5i8': !
2127 214..269 'if tru... }': ()
2128 217..221 'true': bool
2129 222..269 '{ ... }': ()
2130 240..254 'break 'inner 6': !
2132 282..289 'break 7': !
2134 310..325 'break inner < 8': !
2135 316..321 'inner': i8
2136 316..325 'inner < 8': bool
2143 fn infer_labelled_block_break_with_val() {
2146 fn default<T>() -> T { loop {} }
2149 let inner = 'inner: {
2151 if (break 'outer i) {
2156 break 'inner 'innermost: { 0 };
2159 break 'outer inner < 8;
2164 21..32 '{ loop {} }': T
2167 42..381 '{ ... }; }': ()
2169 65..378 '{ ... }': bool
2171 95..339 '{ ... }': i8
2173 117..124 'default': fn default<bool>() -> bool
2174 117..126 'default()': bool
2175 140..270 'if (br... }': ()
2176 144..158 'break 'outer i': !
2178 160..209 '{ ... }': ()
2179 178..194 'break ...er 5i8': !
2181 215..270 'if tru... }': ()
2182 218..222 'true': bool
2183 223..270 '{ ... }': ()
2184 241..255 'break 'inner 6': !
2186 283..313 'break ... { 0 }': !
2187 308..313 '{ 0 }': i8
2190 349..371 'break ...er < 8': !
2191 362..367 'inner': i8
2192 362..371 'inner < 8': bool
2199 fn generic_default() {
2202 struct Thing<T = ()> { t: T }
2203 enum OtherThing<T = ()> {
2208 fn test(t1: Thing, t2: OtherThing, t3: Thing<i32>, t4: OtherThing<i32>) {
2212 OtherThing::One { t } => { t; },
2213 OtherThing::Two(t) => { t; },
2216 OtherThing::One { t } => { t; },
2217 OtherThing::Two(t) => { t; },
2222 97..99 't1': Thing<()>
2223 108..110 't2': OtherThing<()>
2224 124..126 't3': Thing<i32>
2225 140..142 't4': OtherThing<i32>
2226 161..384 '{ ... } }': ()
2227 167..169 't1': Thing<()>
2229 177..179 't3': Thing<i32>
2230 177..181 't3.t': i32
2231 187..282 'match ... }': ()
2232 193..195 't2': OtherThing<()>
2233 206..227 'OtherT... { t }': OtherThing<()>
2235 231..237 '{ t; }': ()
2237 247..265 'OtherT...Two(t)': OtherThing<()>
2239 269..275 '{ t; }': ()
2241 287..382 'match ... }': ()
2242 293..295 't4': OtherThing<i32>
2243 306..327 'OtherT... { t }': OtherThing<i32>
2245 331..337 '{ t; }': ()
2247 347..365 'OtherT...Two(t)': OtherThing<i32>
2249 369..375 '{ t; }': ()
2256 fn generic_default_in_struct_literal() {
2259 struct Thing<T = ()> { t: T }
2260 enum OtherThing<T = ()> {
2266 let x = Thing { t: loop {} };
2267 let y = Thing { t: () };
2268 let z = Thing { t: 1i32 };
2269 if let Thing { t } = z {
2273 let a = OtherThing::One { t: 1i32 };
2274 let b = OtherThing::Two(1i32);
2278 99..319 '{ ...32); }': ()
2279 109..110 'x': Thing<!>
2280 113..133 'Thing ...p {} }': Thing<!>
2281 124..131 'loop {}': !
2283 143..144 'y': Thing<()>
2284 147..162 'Thing { t: () }': Thing<()>
2286 172..173 'z': Thing<i32>
2287 176..193 'Thing ...1i32 }': Thing<i32>
2288 187..191 '1i32': i32
2289 199..240 'if let... }': ()
2290 206..217 'Thing { t }': Thing<i32>
2292 220..221 'z': Thing<i32>
2293 222..240 '{ ... }': ()
2295 250..251 'a': OtherThing<i32>
2296 254..281 'OtherT...1i32 }': OtherThing<i32>
2297 275..279 '1i32': i32
2298 291..292 'b': OtherThing<i32>
2299 295..310 'OtherThing::Two': Two<i32>(i32) -> OtherThing<i32>
2300 295..316 'OtherT...(1i32)': OtherThing<i32>
2301 311..315 '1i32': i32
2307 fn generic_default_depending_on_other_type_arg() {
2308 // FIXME: the {unknown} is a bug
2311 struct Thing<T = u128, F = fn() -> T> { t: T }
2313 fn test(t1: Thing<u32>, t2: Thing) {
2316 Thing::<_> { t: 1u32 };
2320 56..58 't1': Thing<u32, fn() -> u32>
2321 72..74 't2': Thing<u128, fn() -> u128>
2322 83..130 '{ ...2 }; }': ()
2323 89..91 't1': Thing<u32, fn() -> u32>
2324 97..99 't2': Thing<u128, fn() -> u128>
2325 105..127 'Thing:...1u32 }': Thing<u32, fn() -> {unknown}>
2326 121..125 '1u32': u32
2332 fn generic_default_depending_on_other_type_arg_forward() {
2333 // the {unknown} here is intentional, as defaults are not allowed to
2334 // refer to type parameters coming later
2337 struct Thing<F = fn() -> T, T = u128> { t: T }
2339 fn test(t1: Thing) {
2344 56..58 't1': Thing<fn() -> {unknown}, u128>
2345 67..78 '{ t1; }': ()
2346 73..75 't1': Thing<fn() -> {unknown}, u128>
2352 fn infer_operator_overload() {
2353 cov_mark::check!(infer_expr_inner_binary_operator_overload);
2357 struct V2([f32; 2]);
2360 pub trait Add<Rhs = Self> {
2361 /// The resulting type after applying the `+` operator.
2364 /// Performs the `+` operation.
2366 fn add(self, rhs: Rhs) -> Self::Output;
2369 impl Add<V2> for V2 {
2372 fn add(self, rhs: V2) -> V2 {
2373 let x = self.0[0] + rhs.0[0];
2374 let y = self.0[1] + rhs.0[1];
2380 let va = V2([0.0, 1.0]);
2381 let vb = V2([0.0, 1.0]);
2388 207..211 'self': Self
2392 320..422 '{ ... }': V2
2395 338..344 'self.0': [f32; 2]
2396 338..347 'self.0[0]': {unknown}
2397 338..358 'self.0...s.0[0]': f32
2400 350..355 'rhs.0': [f32; 2]
2401 350..358 'rhs.0[0]': {unknown}
2405 376..382 'self.0': [f32; 2]
2406 376..385 'self.0[1]': {unknown}
2407 376..396 'self.0...s.0[1]': f32
2410 388..393 'rhs.0': [f32; 2]
2411 388..396 'rhs.0[1]': {unknown}
2413 406..408 'V2': V2([f32; 2]) -> V2
2414 406..416 'V2([x, y])': V2
2415 409..415 '[x, y]': [f32; 2]
2418 436..519 '{ ... vb; }': ()
2420 451..453 'V2': V2([f32; 2]) -> V2
2421 451..465 'V2([0.0, 1.0])': V2
2422 454..464 '[0.0, 1.0]': [f32; 2]
2426 480..482 'V2': V2([f32; 2]) -> V2
2427 480..494 'V2([0.0, 1.0])': V2
2428 483..493 '[0.0, 1.0]': [f32; 2]
2433 509..516 'va + vb': V2
2440 fn infer_const_params() {
2443 fn foo<const FOO: usize>() {
2448 27..49 '{ ...FOO; }': ()
2456 fn infer_inner_type() {
2460 struct S { field: u32 }
2461 let s = S { field: 0 };
2466 9..89 '{ ...eld; }': ()
2468 51..65 'S { field: 0 }': S
2472 79..86 's.field': u32
2478 fn infer_nested_inner_type() {
2483 let s = S { field: 0 };
2486 struct S { field: u32 }
2490 9..109 '{ ...32 } }': ()
2491 15..79 '{ ... }': ()
2493 33..47 'S { field: 0 }': S
2497 65..72 's.field': u32
2503 fn inner_use_enum_rename() {
2520 34..123 '{ ... } }': ()
2522 71..78 'R::Info': Request
2523 84..121 'match ... }': ()
2525 102..109 'R::Info': Request
2539 pub trait Unsize<T: ?Sized> {}
2541 #[lang = "coerce_unsized"]
2542 pub trait CoerceUnsized<T> {}
2544 pub unsafe trait Allocator {}
2547 unsafe impl Allocator for Global {}
2549 #[lang = "owned_box"]
2551 pub struct Box<T: ?Sized, A: Allocator = Global>;
2553 impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<Box<U, A>> for Box<T, A> {}
2555 pub struct Vec<T, A: Allocator = Global> {}
2560 #[lang = "slice_alloc"]
2562 pub fn into_vec<A: Allocator>(self: Box<Self, A>) -> Vec<T, A> {
2568 let vec = <[_]>::into_vec(box [1i32]);
2572 569..573 'self': Box<[T], A>
2573 602..634 '{ ... }': Vec<T, A>
2574 612..628 'unimpl...ted!()': Vec<T, A>
2575 648..694 '{ ...2]); }': ()
2576 658..661 'vec': Vec<i32, Global>
2577 664..679 '<[_]>::into_vec': fn into_vec<i32, Global>(Box<[i32], Global>) -> Vec<i32, Global>
2578 664..691 '<[_]>:...1i32])': Vec<i32, Global>
2579 680..690 'box [1i32]': Box<[i32; 1], Global>
2580 684..690 '[1i32]': [i32; 1]
2581 685..689 '1i32': i32
2587 fn cfgd_out_assoc_items() {
2606 fn infer_type_alias_variant() {
2617 Qux::Bar(bar) => (),
2618 Qux::Baz { baz } => (),
2623 72..166 '{ ... } }': ()
2624 78..164 'match ... }': ()
2625 84..92 'Foo::Bar': Bar(i32) -> Foo
2626 84..95 'Foo::Bar(3)': Foo
2628 106..119 'Qux::Bar(bar)': Foo
2631 135..151 'Qux::B... baz }': Foo