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() {
955 use core::ops::Deref;
959 fn foo(&self, x: &A<T>) -> &T {
966 impl<T> Deref for B<T> {
968 fn deref(&self) -> &Self::Target {
974 let t = A(0 as *mut _).foo(&&B(B(a)));
980 93..114 '{ ... }': &T
984 105..108 'x.0': *mut T
985 195..199 'self': &B<T>
986 218..241 '{ ... }': &T
987 228..235 '&self.0': &T
988 229..233 'self': &B<T>
991 264..310 '{ ...))); }': ()
993 278..279 'A': A<i32>(*mut i32) -> A<i32>
994 278..292 'A(0 as *mut _)': A<i32>
995 278..307 'A(0 as...B(a)))': &i32
997 280..291 '0 as *mut _': *mut i32
998 297..306 '&&B(B(a))': &&B<B<A<i32>>>
999 298..306 '&B(B(a))': &B<B<A<i32>>>
1000 299..300 'B': B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>>
1001 299..306 'B(B(a))': B<B<A<i32>>>
1002 301..302 'B': B<A<i32>>(A<i32>) -> B<A<i32>>
1003 301..305 'B(a)': B<A<i32>>
1004 303..304 'a': A<i32>
1010 fn infer_in_elseif() {
1013 struct Foo { field: i32 }
1024 44..108 '{ ... } }': ()
1025 50..106 'if tru... }': ()
1028 72..106 'if fal... }': i32
1029 75..80 'false': bool
1030 81..106 '{ ... }': i32
1032 91..100 'foo.field': i32
1038 fn infer_if_match_with_return() {
1052 let _x3 = match true {
1058 let _x4 = match true {
1065 9..322 '{ ... }; }': ()
1067 25..79 'if tru... }': i32
1069 33..50 '{ ... }': i32
1071 56..79 '{ ... }': i32
1074 95..148 'if tru... }': i32
1075 98..102 'true': bool
1076 103..120 '{ ... }': i32
1078 126..148 '{ ... }': !
1079 136..142 'return': !
1081 164..246 'match ... }': i32
1082 170..174 'true': bool
1083 185..189 'true': bool
1084 185..189 'true': bool
1087 209..240 '{ ... }': i32
1088 223..229 'return': !
1090 262..319 'match ... }': i32
1091 268..272 'true': bool
1092 283..287 'true': bool
1093 283..287 'true': bool
1096 307..313 'return': !
1102 fn infer_inherent_method() {
1108 fn foo(self, x: u32) -> i32 {}
1113 pub fn bar(&self, x: u64) -> i64 {}
1131 153..201 '{ ...(1); }': ()
1133 159..167 'a.foo(1)': i32
1135 173..184 '(&a).bar(1)': i64
1140 190..198 'a.bar(1)': i64
1147 fn infer_inherent_method_str() {
1152 fn foo(&self) -> i32 {}
1162 68..88 '{ ...o(); }': ()
1163 74..79 '"foo"': &str
1164 74..85 '"foo".foo()': i32
1173 fn test(x: &str, y: isize) {
1174 let a: (u32, &str) = (1, "a");
1185 27..169 '{ ...d"); }': ()
1186 37..38 'a': (u32, &str)
1187 54..62 '(1, "a")': (u32, &str)
1190 72..73 'b': ((u32, &str), &str)
1191 76..82 '(a, x)': ((u32, &str), &str)
1192 77..78 'a': (u32, &str)
1194 92..93 'c': (isize, &str)
1195 96..102 '(y, x)': (isize, &str)
1198 112..113 'd': ((isize, &str), &str)
1199 116..122 '(c, x)': ((isize, &str), &str)
1200 117..118 'c': (isize, &str)
1202 132..133 'e': (i32, &str)
1203 136..144 '(1, "e")': (i32, &str)
1205 140..143 '"e"': &str
1206 154..155 'f': ((i32, &str), &str)
1207 158..166 '(e, "d")': ((i32, &str), &str)
1208 159..160 'e': (i32, &str)
1209 162..165 '"d"': &str
1218 fn test(x: &str, y: isize) {
1223 let d = [y, 1, 2, 3];
1224 let d = [1, y, 2, 3];
1233 let x: [u8; 0] = [];
1234 // FIXME: requires const evaluation/taking type from rhs somehow
1235 let y: [u8; 2+2] = [1,2,3,4];
1241 27..395 '{ ...,4]; }': ()
1242 37..38 'a': [&str; 1]
1243 41..44 '[x]': [&str; 1]
1245 54..55 'b': [[&str; 1]; 2]
1246 58..64 '[a, a]': [[&str; 1]; 2]
1247 59..60 'a': [&str; 1]
1248 62..63 'a': [&str; 1]
1249 74..75 'c': [[[&str; 1]; 2]; 2]
1250 78..84 '[b, b]': [[[&str; 1]; 2]; 2]
1251 79..80 'b': [[&str; 1]; 2]
1252 82..83 'b': [[&str; 1]; 2]
1253 95..96 'd': [isize; 4]
1254 99..111 '[y, 1, 2, 3]': [isize; 4]
1259 121..122 'd': [isize; 4]
1260 125..137 '[1, y, 2, 3]': [isize; 4]
1265 147..148 'e': [isize; 1]
1266 151..154 '[y]': [isize; 1]
1268 164..165 'f': [[isize; 4]; 2]
1269 168..174 '[d, d]': [[isize; 4]; 2]
1270 169..170 'd': [isize; 4]
1271 172..173 'd': [isize; 4]
1272 184..185 'g': [[isize; 1]; 2]
1273 188..194 '[e, e]': [[isize; 1]; 2]
1274 189..190 'e': [isize; 1]
1275 192..193 'e': [isize; 1]
1276 205..206 'h': [i32; 2]
1277 209..215 '[1, 2]': [i32; 2]
1280 225..226 'i': [&str; 2]
1281 229..239 '["a", "b"]': [&str; 2]
1282 230..233 '"a"': &str
1283 235..238 '"b"': &str
1284 250..251 'b': [[&str; 1]; 2]
1285 254..264 '[a, ["b"]]': [[&str; 1]; 2]
1286 255..256 'a': [&str; 1]
1287 258..263 '["b"]': [&str; 1]
1288 259..262 '"b"': &str
1289 274..275 'x': [u8; 0]
1290 287..289 '[]': [u8; 0]
1291 368..369 'y': [u8; _]
1292 383..392 '[1,2,3,4]': [u8; 4]
1302 fn infer_struct_generics() {
1309 fn test(a1: A<u32>, i: i32) {
1311 let a2 = A { x: i };
1313 let a3 = A::<i128> { x: 1 };
1320 55..146 '{ ...3.x; }': ()
1324 80..90 'A { x: i }': A<i32>
1328 110..112 'a3': A<i128>
1329 115..133 'A::<i1...x: 1 }': A<i128>
1331 139..141 'a3': A<i128>
1332 139..143 'a3.x': i128
1338 fn infer_tuple_struct_generics() {
1342 enum Option<T> { Some(T), None }
1351 let x: Option<i64> = None;
1355 75..183 '{ ...one; }': ()
1356 81..82 'A': A<i32>(i32) -> A<i32>
1357 81..86 'A(42)': A<i32>
1359 92..93 'A': A<u128>(u128) -> A<u128>
1360 92..101 'A(42u128)': A<u128>
1361 94..100 '42u128': u128
1362 107..111 'Some': Some<&str>(&str) -> Option<&str>
1363 107..116 'Some("x")': Option<&str>
1364 112..115 '"x"': &str
1365 122..134 'Option::Some': Some<&str>(&str) -> Option<&str>
1366 122..139 'Option...e("x")': Option<&str>
1367 135..138 '"x"': &str
1368 145..149 'None': Option<{unknown}>
1369 159..160 'x': Option<i64>
1370 176..180 'None': Option<i64>
1376 fn infer_function_generics() {
1379 fn id<T>(t: T) -> T { t }
1391 37..97 '{ ...(1); }': ()
1392 43..45 'id': fn id<u32>(u32) -> u32
1393 43..51 'id(1u32)': u32
1395 57..67 'id::<i128>': fn id<i128>(i128) -> i128
1396 57..70 'id::<i128>(1)': i128
1399 89..91 'id': fn id<u64>(u64) -> u64
1407 fn infer_impl_generics_basic() {
1414 impl<Y, X> A<X, Y> {
1421 fn z<T>(self, t: T) -> (X, Y, T) {
1427 let a = A { x: 1u64, y: 1i64 };
1435 73..77 'self': A<X, Y>
1436 84..106 '{ ... }': X
1437 94..98 'self': A<X, Y>
1439 116..120 'self': A<X, Y>
1440 127..149 '{ ... }': Y
1441 137..141 'self': A<X, Y>
1442 137..143 'self.y': Y
1443 162..166 'self': A<X, Y>
1445 187..222 '{ ... }': (X, Y, T)
1446 197..216 '(self.....y, t)': (X, Y, T)
1447 198..202 'self': A<X, Y>
1448 198..204 'self.x': X
1449 206..210 'self': A<X, Y>
1450 206..212 'self.y': Y
1452 244..341 '{ ...(1); }': ()
1453 254..255 'a': A<u64, i64>
1454 258..280 'A { x:...1i64 }': A<u64, i64>
1455 265..269 '1u64': u64
1456 274..278 '1i64': i64
1457 286..287 'a': A<u64, i64>
1458 286..291 'a.x()': u64
1459 297..298 'a': A<u64, i64>
1460 297..302 'a.y()': i64
1461 308..309 'a': A<u64, i64>
1462 308..318 'a.z(1i128)': (u64, i64, i128)
1463 312..317 '1i128': i128
1464 324..325 'a': A<u64, i64>
1465 324..338 'a.z::<u128>(1)': (u64, i64, u128)
1472 fn infer_impl_generics_with_autoderef() {
1480 fn as_ref(&self) -> Option<&T> {}
1482 fn test(o: Option<u32>) {
1488 77..81 'self': &Option<T>
1490 110..111 'o': Option<u32>
1491 126..164 '{ ...f(); }': ()
1492 132..145 '(&o).as_ref()': Option<&u32>
1493 133..135 '&o': &Option<u32>
1494 134..135 'o': Option<u32>
1495 151..152 'o': Option<u32>
1496 151..161 'o.as_ref()': Option<&u32>
1502 fn infer_generic_chain() {
1513 fn id<T>(t: T) -> T { t }
1518 let a = A { x: id(y) };
1525 52..56 'self': A<T2>
1526 64..86 '{ ... }': T2
1527 74..78 'self': A<T2>
1532 134..254 '{ ....x() }': i128
1536 163..165 'id': fn id<i128>(i128) -> i128
1537 163..168 'id(x)': i128
1539 178..179 'a': A<i128>
1540 182..196 'A { x: id(y) }': A<i128>
1541 189..191 'id': fn id<i128>(i128) -> i128
1542 189..194 'id(y)': i128
1545 210..212 'id': fn id<i128>(i128) -> i128
1546 210..217 'id(a.x)': i128
1547 213..214 'a': A<i128>
1548 213..216 'a.x': i128
1549 227..228 'b': A<i128>
1550 231..241 'A { x: z }': A<i128>
1552 247..248 'b': A<i128>
1553 247..252 'b.x()': i128
1559 fn infer_associated_const() {
1580 impl Trait for TraitTest {
1585 let x = Struct::FOO;
1587 let z = TraitTest::ID;
1594 228..306 '{ ...:ID; }': ()
1596 242..253 'Struct::FOO': u32
1598 267..276 'Enum::BAR': u32
1600 290..303 'TraitTest::ID': u32
1606 fn infer_type_alias() {
1609 struct A<X, Y> { x: X, y: Y }
1610 type Foo = A<u32, i128>;
1611 type Bar<T> = A<T, u128>;
1612 type Baz<U, V> = A<V, U>;
1613 fn test(x: Foo, y: Bar<&str>, z: Baz<i8, u8>) {
1623 115..116 'x': A<u32, i128>
1624 123..124 'y': A<&str, u128>
1625 137..138 'z': A<u8, i8>
1626 153..210 '{ ...z.y; }': ()
1627 159..160 'x': A<u32, i128>
1629 168..169 'x': A<u32, i128>
1630 168..171 'x.y': i128
1631 177..178 'y': A<&str, u128>
1632 177..180 'y.x': &str
1633 186..187 'y': A<&str, u128>
1634 186..189 'y.y': u128
1635 195..196 'z': A<u8, i8>
1637 204..205 'z': A<u8, i8>
1644 fn recursive_type_alias() {
1653 58..59 'x': {unknown}
1660 fn infer_type_param() {
1663 fn id<T>(x: T) -> T {
1667 fn clone<T>(x: &T) -> T {
1674 let x: bool = clone(z);
1686 77..157 '{ ...(1); }': ()
1689 102..104 'id': fn id<u32>(u32) -> u32
1690 102..107 'id(y)': u32
1693 127..132 'clone': fn clone<bool>(&bool) -> bool
1694 127..135 'clone(z)': bool
1696 141..151 'id::<i128>': fn id<i128>(i128) -> i128
1697 141..154 'id::<i128>(1)': i128
1708 impl Foo { const ASSOC_CONST: u32 = 0; }
1709 const GLOBAL_CONST: u32 = 101;
1711 const LOCAL_CONST: u32 = 99;
1712 let x = LOCAL_CONST;
1713 let z = GLOBAL_CONST;
1714 let id = Foo::ASSOC_CONST;
1720 94..212 '{ ...NST; }': ()
1722 141..152 'LOCAL_CONST': u32
1724 166..178 'GLOBAL_CONST': u32
1726 193..209 'Foo::A..._CONST': u32
1736 static GLOBAL_STATIC: u32 = 101;
1737 static mut GLOBAL_STATIC_MUT: u32 = 101;
1739 static LOCAL_STATIC: u32 = 99;
1740 static mut LOCAL_STATIC_MUT: u32 = 99;
1741 let x = LOCAL_STATIC;
1742 let y = LOCAL_STATIC_MUT;
1743 let z = GLOBAL_STATIC;
1744 let w = GLOBAL_STATIC_MUT;
1750 84..279 '{ ...MUT; }': ()
1752 176..188 'LOCAL_STATIC': u32
1754 202..218 'LOCAL_...IC_MUT': u32
1756 232..245 'GLOBAL_STATIC': u32
1758 259..276 'GLOBAL...IC_MUT': u32
1766 fn shadowing_primitive() {
1772 impl i32 { fn foo(&self) -> Foo { Foo } }
1783 fn shadowing_primitive_with_inner_items() {
1789 impl i32 { fn foo(&self) -> Foo { Foo } }
1801 fn not_shadowing_primitive_by_module() {
1809 fn foo() -> &'static str { "" }
1819 fn not_shadowing_module_by_primitive() {
1827 fn foo() -> &'static str { "" }
1836 // This test is actually testing the shadowing behavior within hir_def. It
1837 // lives here because the testing infrastructure in hir_def isn't currently
1838 // capable of asserting the necessary conditions.
1840 fn should_be_shadowing_imports() {
1844 pub fn foo() -> i8 {0}
1845 pub struct foo { a: i8 }
1847 mod b { pub fn foo () -> u8 {0} }
1848 mod c { pub struct foo { a: u8 } }
1850 pub use super::a::*;
1851 pub use super::c::foo;
1852 pub use super::b::foo;
1865 fn closure_return() {
1869 let x = || -> usize { return 1; };
1873 16..58 '{ ...; }; }': ()
1874 26..27 'x': || -> usize
1875 30..55 '|| -> ...n 1; }': || -> usize
1876 42..55 '{ return 1; }': usize
1877 44..52 'return 1': !
1884 fn closure_return_unit() {
1888 let x = || { return; };
1892 16..47 '{ ...; }; }': ()
1893 26..27 'x': || -> ()
1894 30..44 '|| { return; }': || -> ()
1895 33..44 '{ return; }': ()
1902 fn closure_return_inferred() {
1906 let x = || { "test" };
1910 16..46 '{ ..." }; }': ()
1911 26..27 'x': || -> &str
1912 30..43 '|| { "test" }': || -> &str
1913 33..43 '{ "test" }': &str
1914 35..41 '"test"': &str
1920 fn fn_pointer_return() {
1928 let vtable = Vtable { method: || {} };
1929 let m = vtable.method;
1933 47..120 '{ ...hod; }': ()
1934 57..63 'vtable': Vtable
1935 66..90 'Vtable...| {} }': Vtable
1936 83..88 '|| {}': || -> ()
1939 104..110 'vtable': Vtable
1940 104..117 'vtable.method': fn()
1946 fn effects_smoke_test() {
1950 let x = unsafe { 92 };
1951 let y = async { async { () }.await };
1953 let w = const { 92 };
1957 #[prelude_import] use future::*;
1960 #[lang = "future_trait"]
1961 pub trait Future { type Output; }
1965 16..162 '{ ...2 }; }': ()
1967 30..43 'unsafe { 92 }': i32
1968 37..43 '{ 92 }': i32
1970 53..54 'y': impl Future<Output = ()>
1971 57..85 'async ...wait }': impl Future<Output = ()>
1972 63..85 '{ asyn...wait }': ()
1973 65..77 'async { () }': impl Future<Output = ()>
1974 65..83 'async ....await': ()
1977 95..96 'z': {unknown}
1978 99..109 'try { () }': {unknown}
1979 103..109 '{ () }': ()
1982 123..135 'const { 92 }': i32
1983 129..135 '{ 92 }': i32
1986 153..159 '{ 92 }': i32
1993 fn infer_generic_from_later_assignment() {
1996 enum Option<T> { Some(T), None }
2007 59..129 '{ ... } }': ()
2008 69..76 'mut end': Option<bool>
2009 79..83 'None': Option<bool>
2010 89..127 'loop {... }': !
2011 94..127 '{ ... }': ()
2012 104..107 'end': Option<bool>
2013 104..120 'end = ...(true)': ()
2014 110..114 'Some': Some<bool>(bool) -> Option<bool>
2015 110..120 'Some(true)': Option<bool>
2016 115..119 'true': bool
2022 fn infer_loop_break_with_val() {
2025 enum Option<T> { Some(T), None }
2039 59..168 '{ ... }; }': ()
2040 69..70 'x': Option<bool>
2041 73..165 'loop {... }': Option<bool>
2042 78..165 '{ ... }': ()
2043 88..132 'if fal... }': ()
2044 91..96 'false': bool
2045 97..132 '{ ... }': ()
2046 111..121 'break None': !
2047 117..121 'None': Option<bool>
2048 142..158 'break ...(true)': !
2049 148..152 'Some': Some<bool>(bool) -> Option<bool>
2050 148..158 'Some(true)': Option<bool>
2051 153..157 'true': bool
2057 fn infer_loop_break_without_val() {
2060 enum Option<T> { Some(T), None }
2072 59..136 '{ ... }; }': ()
2074 73..133 'loop {... }': ()
2075 78..133 '{ ... }': ()
2076 88..127 'if fal... }': ()
2077 91..96 'false': bool
2078 97..127 '{ ... }': ()
2085 fn infer_labelled_break_with_val() {
2089 let _x = || 'outer: loop {
2090 let inner = 'inner: loop {
2091 let i = Default::default();
2092 if (break 'outer i) {
2093 loop { break 'inner 5i8; };
2104 9..335 '{ ... }; }': ()
2105 19..21 '_x': || -> bool
2106 24..332 '|| 'ou... }': || -> bool
2107 27..332 ''outer... }': bool
2108 40..332 '{ ... }': ()
2110 62..300 ''inner... }': i8
2111 75..300 '{ ... }': ()
2113 97..113 'Defaul...efault': {unknown}
2114 97..115 'Defaul...ault()': bool
2115 129..269 'if (br... }': ()
2116 133..147 'break 'outer i': !
2118 149..208 '{ ... }': ()
2119 167..193 'loop {...5i8; }': !
2120 172..193 '{ brea...5i8; }': ()
2121 174..190 'break ...er 5i8': !
2123 214..269 'if tru... }': ()
2124 217..221 'true': bool
2125 222..269 '{ ... }': ()
2126 240..254 'break 'inner 6': !
2128 282..289 'break 7': !
2130 310..325 'break inner < 8': !
2131 316..321 'inner': i8
2132 316..325 'inner < 8': bool
2139 fn infer_labelled_block_break_with_val() {
2142 fn default<T>() -> T { loop {} }
2145 let inner = 'inner: {
2147 if (break 'outer i) {
2152 break 'inner 'innermost: { 0 };
2155 break 'outer inner < 8;
2160 21..32 '{ loop {} }': T
2163 42..381 '{ ... }; }': ()
2165 65..378 '{ ... }': bool
2167 95..339 '{ ... }': i8
2169 117..124 'default': fn default<bool>() -> bool
2170 117..126 'default()': bool
2171 140..270 'if (br... }': ()
2172 144..158 'break 'outer i': !
2174 160..209 '{ ... }': ()
2175 178..194 'break ...er 5i8': !
2177 215..270 'if tru... }': ()
2178 218..222 'true': bool
2179 223..270 '{ ... }': ()
2180 241..255 'break 'inner 6': !
2182 283..313 'break ... { 0 }': !
2183 308..313 '{ 0 }': i8
2186 349..371 'break ...er < 8': !
2187 362..367 'inner': i8
2188 362..371 'inner < 8': bool
2195 fn generic_default() {
2198 struct Thing<T = ()> { t: T }
2199 enum OtherThing<T = ()> {
2204 fn test(t1: Thing, t2: OtherThing, t3: Thing<i32>, t4: OtherThing<i32>) {
2208 OtherThing::One { t } => { t; },
2209 OtherThing::Two(t) => { t; },
2212 OtherThing::One { t } => { t; },
2213 OtherThing::Two(t) => { t; },
2218 97..99 't1': Thing<()>
2219 108..110 't2': OtherThing<()>
2220 124..126 't3': Thing<i32>
2221 140..142 't4': OtherThing<i32>
2222 161..384 '{ ... } }': ()
2223 167..169 't1': Thing<()>
2225 177..179 't3': Thing<i32>
2226 177..181 't3.t': i32
2227 187..282 'match ... }': ()
2228 193..195 't2': OtherThing<()>
2229 206..227 'OtherT... { t }': OtherThing<()>
2231 231..237 '{ t; }': ()
2233 247..265 'OtherT...Two(t)': OtherThing<()>
2235 269..275 '{ t; }': ()
2237 287..382 'match ... }': ()
2238 293..295 't4': OtherThing<i32>
2239 306..327 'OtherT... { t }': OtherThing<i32>
2241 331..337 '{ t; }': ()
2243 347..365 'OtherT...Two(t)': OtherThing<i32>
2245 369..375 '{ t; }': ()
2252 fn generic_default_in_struct_literal() {
2255 struct Thing<T = ()> { t: T }
2256 enum OtherThing<T = ()> {
2262 let x = Thing { t: loop {} };
2263 let y = Thing { t: () };
2264 let z = Thing { t: 1i32 };
2265 if let Thing { t } = z {
2269 let a = OtherThing::One { t: 1i32 };
2270 let b = OtherThing::Two(1i32);
2274 99..319 '{ ...32); }': ()
2275 109..110 'x': Thing<!>
2276 113..133 'Thing ...p {} }': Thing<!>
2277 124..131 'loop {}': !
2279 143..144 'y': Thing<()>
2280 147..162 'Thing { t: () }': Thing<()>
2282 172..173 'z': Thing<i32>
2283 176..193 'Thing ...1i32 }': Thing<i32>
2284 187..191 '1i32': i32
2285 199..240 'if let... }': ()
2286 206..217 'Thing { t }': Thing<i32>
2288 220..221 'z': Thing<i32>
2289 222..240 '{ ... }': ()
2291 250..251 'a': OtherThing<i32>
2292 254..281 'OtherT...1i32 }': OtherThing<i32>
2293 275..279 '1i32': i32
2294 291..292 'b': OtherThing<i32>
2295 295..310 'OtherThing::Two': Two<i32>(i32) -> OtherThing<i32>
2296 295..316 'OtherT...(1i32)': OtherThing<i32>
2297 311..315 '1i32': i32
2303 fn generic_default_depending_on_other_type_arg() {
2304 // FIXME: the {unknown} is a bug
2307 struct Thing<T = u128, F = fn() -> T> { t: T }
2309 fn test(t1: Thing<u32>, t2: Thing) {
2312 Thing::<_> { t: 1u32 };
2316 56..58 't1': Thing<u32, fn() -> u32>
2317 72..74 't2': Thing<u128, fn() -> u128>
2318 83..130 '{ ...2 }; }': ()
2319 89..91 't1': Thing<u32, fn() -> u32>
2320 97..99 't2': Thing<u128, fn() -> u128>
2321 105..127 'Thing:...1u32 }': Thing<u32, fn() -> {unknown}>
2322 121..125 '1u32': u32
2328 fn generic_default_depending_on_other_type_arg_forward() {
2329 // the {unknown} here is intentional, as defaults are not allowed to
2330 // refer to type parameters coming later
2333 struct Thing<F = fn() -> T, T = u128> { t: T }
2335 fn test(t1: Thing) {
2340 56..58 't1': Thing<fn() -> {unknown}, u128>
2341 67..78 '{ t1; }': ()
2342 73..75 't1': Thing<fn() -> {unknown}, u128>
2348 fn infer_operator_overload() {
2349 cov_mark::check!(infer_expr_inner_binary_operator_overload);
2353 struct V2([f32; 2]);
2356 pub trait Add<Rhs = Self> {
2357 /// The resulting type after applying the `+` operator.
2360 /// Performs the `+` operation.
2362 fn add(self, rhs: Rhs) -> Self::Output;
2365 impl Add<V2> for V2 {
2368 fn add(self, rhs: V2) -> V2 {
2369 let x = self.0[0] + rhs.0[0];
2370 let y = self.0[1] + rhs.0[1];
2376 let va = V2([0.0, 1.0]);
2377 let vb = V2([0.0, 1.0]);
2384 207..211 'self': Self
2388 320..422 '{ ... }': V2
2391 338..344 'self.0': [f32; 2]
2392 338..347 'self.0[0]': {unknown}
2393 338..358 'self.0...s.0[0]': f32
2396 350..355 'rhs.0': [f32; 2]
2397 350..358 'rhs.0[0]': {unknown}
2401 376..382 'self.0': [f32; 2]
2402 376..385 'self.0[1]': {unknown}
2403 376..396 'self.0...s.0[1]': f32
2406 388..393 'rhs.0': [f32; 2]
2407 388..396 'rhs.0[1]': {unknown}
2409 406..408 'V2': V2([f32; 2]) -> V2
2410 406..416 'V2([x, y])': V2
2411 409..415 '[x, y]': [f32; 2]
2414 436..519 '{ ... vb; }': ()
2416 451..453 'V2': V2([f32; 2]) -> V2
2417 451..465 'V2([0.0, 1.0])': V2
2418 454..464 '[0.0, 1.0]': [f32; 2]
2422 480..482 'V2': V2([f32; 2]) -> V2
2423 480..494 'V2([0.0, 1.0])': V2
2424 483..493 '[0.0, 1.0]': [f32; 2]
2429 509..516 'va + vb': V2
2436 fn infer_const_params() {
2439 fn foo<const FOO: usize>() {
2444 27..49 '{ ...FOO; }': ()
2452 fn infer_inner_type() {
2456 struct S { field: u32 }
2457 let s = S { field: 0 };
2462 9..89 '{ ...eld; }': ()
2464 51..65 'S { field: 0 }': S
2468 79..86 's.field': u32
2474 fn infer_nested_inner_type() {
2479 let s = S { field: 0 };
2482 struct S { field: u32 }
2486 9..109 '{ ...32 } }': ()
2487 15..79 '{ ... }': ()
2489 33..47 'S { field: 0 }': S
2493 65..72 's.field': u32
2499 fn inner_use_enum_rename() {
2516 34..123 '{ ... } }': ()
2518 71..78 'R::Info': Request
2519 84..121 'match ... }': ()
2521 102..109 'R::Info': Request
2535 pub trait Unsize<T: ?Sized> {}
2537 #[lang = "coerce_unsized"]
2538 pub trait CoerceUnsized<T> {}
2540 pub unsafe trait Allocator {}
2543 unsafe impl Allocator for Global {}
2545 #[lang = "owned_box"]
2547 pub struct Box<T: ?Sized, A: Allocator = Global>;
2549 impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<Box<U, A>> for Box<T, A> {}
2551 pub struct Vec<T, A: Allocator = Global> {}
2556 #[lang = "slice_alloc"]
2558 pub fn into_vec<A: Allocator>(self: Box<Self, A>) -> Vec<T, A> {
2564 let vec = <[_]>::into_vec(box [1i32]);
2568 569..573 'self': Box<[T], A>
2569 602..634 '{ ... }': Vec<T, A>
2570 612..628 'unimpl...ted!()': Vec<T, A>
2571 648..694 '{ ...2]); }': ()
2572 658..661 'vec': Vec<i32, Global>
2573 664..679 '<[_]>::into_vec': fn into_vec<i32, Global>(Box<[i32], Global>) -> Vec<i32, Global>
2574 664..691 '<[_]>:...1i32])': Vec<i32, Global>
2575 680..690 'box [1i32]': Box<[i32; 1], Global>
2576 684..690 '[1i32]': [i32; 1]
2577 685..689 '1i32': i32
2583 fn cfgd_out_assoc_items() {
2602 fn infer_type_alias_variant() {
2613 Qux::Bar(bar) => (),
2614 Qux::Baz { baz } => (),
2619 72..166 '{ ... } }': ()
2620 78..164 'match ... }': ()
2621 84..92 'Foo::Bar': Bar(i32) -> Foo
2622 84..95 'Foo::Bar(3)': Foo
2624 106..119 'Qux::Bar(bar)': Foo
2627 135..151 'Qux::B... baz }': Foo
2635 fn infer_boxed_self_receiver() {
2641 fn deref(&self) -> &Self::Target;
2646 impl<T> Deref for Box<T> {
2648 fn deref(&self) -> &Self::Target;
2654 fn get_inner<'a>(self: &'a Box<Self>) -> &'a T {}
2656 fn get_self<'a>(self: &'a Box<Self>) -> &'a Self {}
2658 fn into_inner(self: Box<Self>) -> Self {}
2662 let boxed = Box(Foo(0_i32));
2664 let bad1 = boxed.get_inner();
2665 let good1 = Foo::get_inner(&boxed);
2667 let bad2 = boxed.get_self();
2668 let good2 = Foo::get_self(&boxed);
2670 let inner = boxed.into_inner();
2674 67..71 'self': &Self
2675 175..179 'self': &Box<T>
2676 259..263 'self': &Box<Foo<T>>
2678 313..317 'self': &Box<Foo<T>>
2680 368..372 'self': Box<Foo<T>>
2682 409..630 '{ ...r(); }': ()
2683 419..424 'boxed': Box<Foo<i32>>
2684 427..430 'Box': Box<Foo<i32>>(Foo<i32>) -> Box<Foo<i32>>
2685 427..442 'Box(Foo(0_i32))': Box<Foo<i32>>
2686 431..434 'Foo': Foo<i32>(i32) -> Foo<i32>
2687 431..441 'Foo(0_i32)': Foo<i32>
2688 435..440 '0_i32': i32
2689 453..457 'bad1': &i32
2690 460..465 'boxed': Box<Foo<i32>>
2691 460..477 'boxed....nner()': &i32
2692 487..492 'good1': &i32
2693 495..509 'Foo::get_inner': fn get_inner<i32>(&Box<Foo<i32>>) -> &i32
2694 495..517 'Foo::g...boxed)': &i32
2695 510..516 '&boxed': &Box<Foo<i32>>
2696 511..516 'boxed': Box<Foo<i32>>
2697 528..532 'bad2': &Foo<i32>
2698 535..540 'boxed': Box<Foo<i32>>
2699 535..551 'boxed....self()': &Foo<i32>
2700 561..566 'good2': &Foo<i32>
2701 569..582 'Foo::get_self': fn get_self<i32>(&Box<Foo<i32>>) -> &Foo<i32>
2702 569..590 'Foo::g...boxed)': &Foo<i32>
2703 583..589 '&boxed': &Box<Foo<i32>>
2704 584..589 'boxed': Box<Foo<i32>>
2705 601..606 'inner': Foo<i32>
2706 609..614 'boxed': Box<Foo<i32>>
2707 609..627 'boxed....nner()': Foo<i32>
2716 //- /main.rs edition:2015 crate:main deps:core
2722 //- /core.rs crate:core