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>
125 let t = (a, b, c, d, e, f);
127 } //^ (RangeFull, RangeFrom<i32>, RangeTo<u32>, Range<usize>, RangeToInclusive<i32>, RangeInclusive<char>)
133 fn infer_while_let() {
136 enum Option<T> { Some(T), None }
139 let foo: Option<f32> = None;
140 while let Option::Some(x) = foo {
152 fn test(a: u32, b: isize, c: !, d: &str) {
168 41..120 '{ ...f32; }': ()
173 75..81 '1usize': usize
174 87..93 '1isize': isize
175 99..105 '"test"': &str
176 111..117 '1.0f32': f32
195 10..117 '{ ...= e; }': ()
197 24..30 '1isize': isize
230 66..90 '{ ...c(); }': ()
231 72..73 'a': fn a() -> u32
233 81..85 'b::c': fn c() -> u32
240 fn infer_path_type() {
246 fn foo() -> i32 { 1 }
257 59..92 '{ ...o(); }': ()
258 65..71 'S::foo': fn foo() -> i32
259 65..73 'S::foo()': i32
260 79..87 '<S>::foo': fn foo() -> i32
261 79..89 '<S>::foo()': i32
280 let a: A = A { b: B, c: C(1) };
286 71..153 '{ ...a.c; }': ()
288 85..86 'C': C(usize) -> C
293 113..132 'A { b:...C(1) }': A
295 126..127 'C': C(usize) -> C
320 51..89 '{ ...:V2; }': ()
321 57..75 'E::V1 ...d: 1 }': E
338 let u = MyUnion { foo: 0 };
340 let u = MyUnion { bar: 0.0 };
344 unsafe fn baz(u: MyUnion) {
350 57..172 '{ ...); } }': ()
352 71..89 'MyUnio...o: 0 }': MyUnion
354 95..113 'unsafe...(u); }': ()
355 102..113 '{ baz(u); }': ()
356 104..107 'baz': fn baz(MyUnion)
357 104..110 'baz(u)': ()
358 108..109 'u': MyUnion
359 122..123 'u': MyUnion
360 126..146 'MyUnio... 0.0 }': MyUnion
362 152..170 'unsafe...(u); }': ()
363 159..170 '{ baz(u); }': ()
364 161..164 'baz': fn baz(MyUnion)
365 161..167 'baz(u)': ()
366 165..166 'u': MyUnion
367 188..189 'u': MyUnion
368 200..249 '{ ...bar; }': ()
369 210..215 'inner': u32
370 218..219 'u': MyUnion
371 218..223 'u.foo': u32
372 233..238 'inner': f32
373 241..242 'u': MyUnion
374 241..246 'u.bar': f32
383 fn test(a: &u32, b: &mut u32, c: *const u32, d: *mut u32) {
400 30..31 'c': *const u32
402 58..149 '{ ... *d; }': ()
408 87..93 '&mut a': &mut &u32
410 99..100 'b': &mut u32
412 107..108 'b': &mut u32
413 114..116 '&b': &&mut u32
414 115..116 'b': &mut u32
415 122..123 'c': *const u32
417 130..131 'c': *const u32
418 137..138 'd': *mut u32
420 145..146 'd': *mut u32
436 16..53 '{ ...t a; }': ()
437 22..32 '&raw mut a': *mut i32
439 38..50 '&raw const a': *const i32
446 fn infer_literals() {
471 let c = br#"x"\"yb"#;
475 18..478 '{ ... }': ()
479 86..93 '"hello"': &str
480 107..115 'b"bytes"': &[u8; 5]
485 200..205 'false': bool
486 219..223 'true': bool
487 237..333 'r#" ... "#': &str
488 347..357 'br#"yolo"#': &[u8; 4]
489 375..376 'a': &[u8; 4]
490 379..403 'b"a\x2... c"': &[u8; 4]
491 421..422 'b': &[u8; 4]
492 425..433 'br"g\ h"': &[u8; 4]
493 451..452 'c': &[u8; 6]
494 455..467 'br#"x"\"yb"#': &[u8; 6]
500 fn infer_unary_op() {
505 fn test(x: SomeType) {
525 39..271 '{ ...lo"; }': ()
540 145..152 '!!!true': bool
541 146..152 '!!true': bool
542 147..152 '!true': bool
543 148..152 'true': bool
548 183..189 '!10u32': u32
549 184..189 '10u32': u32
553 211..216 '-3.14': f64
557 230..232 '-x': {unknown}
558 231..232 'x': SomeType
559 238..240 '!x': {unknown}
560 239..240 'x': SomeType
561 246..254 '-"hello"': {unknown}
562 247..254 '"hello"': &str
563 260..268 '!"hello"': {unknown}
564 261..268 '"hello"': &str
570 fn infer_backwards() {
573 fn takes_u32(x: u32) {}
575 struct S { i32_field: i32 }
577 fn test() -> &mut &f64 {
578 let a = unknown_function();
580 let b = unknown_function();
582 let c = unknown_function();
589 77..230 '{ ...t &c }': &mut &f64
591 91..107 'unknow...nction': {unknown}
592 91..109 'unknow...tion()': u32
593 115..124 'takes_u32': fn takes_u32(u32)
594 115..127 'takes_u32(a)': ()
597 141..157 'unknow...nction': {unknown}
598 141..159 'unknow...tion()': i32
599 165..183 'S { i3...d: b }': S
602 197..213 'unknow...nction': {unknown}
603 197..215 'unknow...tion()': f64
604 221..228 '&mut &c': &mut &f64
621 fn test2(self: &Self) {
637 87..108 '{ ... }': ()
639 132..152 '{ ... }': S
641 176..199 '{ ... }': S
642 186..193 'Self {}': S
648 fn infer_self_as_path() {
676 86..107 '{ ... }': ()
678 134..158 '{ ... }': ()
679 144..148 'Self': S2(isize) -> S2
680 144..151 'Self(1)': S2
682 184..230 '{ ... }': ()
683 194..202 'Self::V1': E
684 212..220 'Self::V2': V2(u32) -> E
685 212..223 'Self::V2(1)': E
692 fn infer_binary_op() {
695 fn f(x: bool) -> i32 {
701 let y = true || false;
704 let minus_forty: isize = -40isize;
705 let h = minus_forty <= CONST_2;
706 let c = f(z || y) + 5;
708 let g = minus_forty ^= i;
710 let ten_is_eleven = ten == some_num;
717 21..33 '{ 0i32 }': i32
719 53..369 '{ ... < 3 }': bool
722 67..73 'a && b': bool
726 87..100 'true || false': bool
727 95..100 'false': bool
730 114..120 'x == y': bool
734 134..140 'x != y': bool
736 150..161 'minus_forty': isize
737 171..179 '-40isize': isize
738 172..179 '40isize': isize
740 193..204 'minus_forty': isize
741 193..215 'minus_...ONST_2': bool
742 208..215 'CONST_2': isize
744 229..230 'f': fn f(bool) -> i32
745 229..238 'f(z || y)': i32
746 229..242 'f(z || y) + 5': i32
748 231..237 'z || y': bool
751 252..253 'd': {unknown}
752 256..257 'b': {unknown}
754 271..282 'minus_forty': isize
755 271..287 'minus_...y ^= i': ()
757 297..300 'ten': usize
759 322..335 'ten_is_eleven': bool
760 338..341 'ten': usize
761 338..353 'ten == some_num': bool
762 345..353 'some_num': usize
763 360..363 'ten': usize
764 360..367 'ten < 3': bool
771 fn infer_shift_op() {
780 10..47 '{ ...5u8; }': ()
782 16..27 '1u32 << 5u8': u32
785 33..44 '1u32 >> 5u8': u32
792 fn infer_field_autoderef() {
809 let a5 = &mut &&mut &&mut a;
813 fn test2(a1: *const A, a2: *mut A) {
820 49..212 '{ ...5.b; }': ()
830 112..114 'a3': &mut A
831 117..123 '&mut a': &mut A
833 129..131 'a3': &mut A
835 143..145 'a4': &&&&&&&A
836 148..156 '&&&&&&&a': &&&&&&&A
837 149..156 '&&&&&&a': &&&&&&A
838 150..156 '&&&&&a': &&&&&A
839 151..156 '&&&&a': &&&&A
840 152..156 '&&&a': &&&A
844 162..164 'a4': &&&&&&&A
846 176..178 'a5': &mut &&mut &&mut A
847 181..199 '&mut &...&mut a': &mut &&mut &&mut A
848 186..199 '&&mut &&mut a': &&mut &&mut A
849 187..199 '&mut &&mut a': &mut &&mut A
850 192..199 '&&mut a': &&mut A
851 193..199 '&mut a': &mut A
853 205..207 'a5': &mut &&mut &&mut A
855 223..225 'a1': *const A
856 237..239 'a2': *mut A
857 249..272 '{ ...2.b; }': ()
858 255..257 'a1': *const A
860 265..267 'a2': *mut A
867 fn infer_argument_autoderef() {
871 use core::ops::Deref;
875 fn foo(&self) -> &T {
882 impl<T> Deref for B<T> {
884 fn deref(&self) -> &Self::Target {
890 let t = A::foo(&&B(B(A(42))));
895 78..101 '{ ... }': &T
899 182..186 'self': &B<T>
900 205..228 '{ ... }': &T
901 215..222 '&self.0': &T
902 216..220 'self': &B<T>
904 242..280 '{ ...))); }': ()
906 256..262 'A::foo': fn foo<i32>(&A<i32>) -> &i32
907 256..277 'A::foo...42))))': &i32
908 263..276 '&&B(B(A(42)))': &&B<B<A<i32>>>
909 264..276 '&B(B(A(42)))': &B<B<A<i32>>>
910 265..266 'B': B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>>
911 265..276 'B(B(A(42)))': B<B<A<i32>>>
912 267..268 'B': B<A<i32>>(A<i32>) -> B<A<i32>>
913 267..275 'B(A(42))': B<A<i32>>
914 269..270 'A': A<i32>(i32) -> A<i32>
915 269..274 'A(42)': A<i32>
922 fn infer_method_argument_autoderef() {
926 use core::ops::Deref;
930 fn foo(&self, x: &A<T>) -> &T {
937 impl<T> Deref for B<T> {
939 fn deref(&self) -> &Self::Target {
945 let t = A(0 as *mut _).foo(&&B(B(a)));
951 93..114 '{ ... }': &T
955 105..108 'x.0': *mut T
956 195..199 'self': &B<T>
957 218..241 '{ ... }': &T
958 228..235 '&self.0': &T
959 229..233 'self': &B<T>
962 264..310 '{ ...))); }': ()
964 278..279 'A': A<i32>(*mut i32) -> A<i32>
965 278..292 'A(0 as *mut _)': A<i32>
966 278..307 'A(0 as...B(a)))': &i32
968 280..291 '0 as *mut _': *mut i32
969 297..306 '&&B(B(a))': &&B<B<A<i32>>>
970 298..306 '&B(B(a))': &B<B<A<i32>>>
971 299..300 'B': B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>>
972 299..306 'B(B(a))': B<B<A<i32>>>
973 301..302 'B': B<A<i32>>(A<i32>) -> B<A<i32>>
974 301..305 'B(a)': B<A<i32>>
981 fn infer_in_elseif() {
984 struct Foo { field: i32 }
995 44..108 '{ ... } }': ()
996 50..106 'if tru... }': ()
999 72..106 'if fal... }': i32
1000 75..80 'false': bool
1001 81..106 '{ ... }': i32
1003 91..100 'foo.field': i32
1009 fn infer_if_match_with_return() {
1023 let _x3 = match true {
1029 let _x4 = match true {
1036 9..322 '{ ... }; }': ()
1038 25..79 'if tru... }': i32
1040 33..50 '{ ... }': i32
1042 56..79 '{ ... }': i32
1045 95..148 'if tru... }': i32
1046 98..102 'true': bool
1047 103..120 '{ ... }': i32
1049 126..148 '{ ... }': !
1050 136..142 'return': !
1052 164..246 'match ... }': i32
1053 170..174 'true': bool
1054 185..189 'true': bool
1055 185..189 'true': bool
1058 209..240 '{ ... }': i32
1059 223..229 'return': !
1061 262..319 'match ... }': i32
1062 268..272 'true': bool
1063 283..287 'true': bool
1064 283..287 'true': bool
1067 307..313 'return': !
1073 fn infer_inherent_method() {
1079 fn foo(self, x: u32) -> i32 {}
1084 pub fn bar(&self, x: u64) -> i64 {}
1102 153..201 '{ ...(1); }': ()
1104 159..167 'a.foo(1)': i32
1106 173..184 '(&a).bar(1)': i64
1111 190..198 'a.bar(1)': i64
1118 fn infer_inherent_method_str() {
1123 fn foo(&self) -> i32 {}
1133 68..88 '{ ...o(); }': ()
1134 74..79 '"foo"': &str
1135 74..85 '"foo".foo()': i32
1144 fn test(x: &str, y: isize) {
1145 let a: (u32, &str) = (1, "a");
1156 27..169 '{ ...d"); }': ()
1157 37..38 'a': (u32, &str)
1158 54..62 '(1, "a")': (u32, &str)
1161 72..73 'b': ((u32, &str), &str)
1162 76..82 '(a, x)': ((u32, &str), &str)
1163 77..78 'a': (u32, &str)
1165 92..93 'c': (isize, &str)
1166 96..102 '(y, x)': (isize, &str)
1169 112..113 'd': ((isize, &str), &str)
1170 116..122 '(c, x)': ((isize, &str), &str)
1171 117..118 'c': (isize, &str)
1173 132..133 'e': (i32, &str)
1174 136..144 '(1, "e")': (i32, &str)
1176 140..143 '"e"': &str
1177 154..155 'f': ((i32, &str), &str)
1178 158..166 '(e, "d")': ((i32, &str), &str)
1179 159..160 'e': (i32, &str)
1180 162..165 '"d"': &str
1189 fn test(x: &str, y: isize) {
1194 let d = [y, 1, 2, 3];
1195 let d = [1, y, 2, 3];
1204 let x: [u8; 0] = [];
1205 // FIXME: requires const evaluation/taking type from rhs somehow
1206 let y: [u8; 2+2] = [1,2,3,4];
1212 27..395 '{ ...,4]; }': ()
1213 37..38 'a': [&str; 1]
1214 41..44 '[x]': [&str; 1]
1216 54..55 'b': [[&str; 1]; 2]
1217 58..64 '[a, a]': [[&str; 1]; 2]
1218 59..60 'a': [&str; 1]
1219 62..63 'a': [&str; 1]
1220 74..75 'c': [[[&str; 1]; 2]; 2]
1221 78..84 '[b, b]': [[[&str; 1]; 2]; 2]
1222 79..80 'b': [[&str; 1]; 2]
1223 82..83 'b': [[&str; 1]; 2]
1224 95..96 'd': [isize; 4]
1225 99..111 '[y, 1, 2, 3]': [isize; 4]
1230 121..122 'd': [isize; 4]
1231 125..137 '[1, y, 2, 3]': [isize; 4]
1236 147..148 'e': [isize; 1]
1237 151..154 '[y]': [isize; 1]
1239 164..165 'f': [[isize; 4]; 2]
1240 168..174 '[d, d]': [[isize; 4]; 2]
1241 169..170 'd': [isize; 4]
1242 172..173 'd': [isize; 4]
1243 184..185 'g': [[isize; 1]; 2]
1244 188..194 '[e, e]': [[isize; 1]; 2]
1245 189..190 'e': [isize; 1]
1246 192..193 'e': [isize; 1]
1247 205..206 'h': [i32; 2]
1248 209..215 '[1, 2]': [i32; 2]
1251 225..226 'i': [&str; 2]
1252 229..239 '["a", "b"]': [&str; 2]
1253 230..233 '"a"': &str
1254 235..238 '"b"': &str
1255 250..251 'b': [[&str; 1]; 2]
1256 254..264 '[a, ["b"]]': [[&str; 1]; 2]
1257 255..256 'a': [&str; 1]
1258 258..263 '["b"]': [&str; 1]
1259 259..262 '"b"': &str
1260 274..275 'x': [u8; 0]
1261 287..289 '[]': [u8; 0]
1262 368..369 'y': [u8; _]
1263 383..392 '[1,2,3,4]': [u8; 4]
1273 fn infer_struct_generics() {
1280 fn test(a1: A<u32>, i: i32) {
1282 let a2 = A { x: i };
1284 let a3 = A::<i128> { x: 1 };
1291 55..146 '{ ...3.x; }': ()
1295 80..90 'A { x: i }': A<i32>
1299 110..112 'a3': A<i128>
1300 115..133 'A::<i1...x: 1 }': A<i128>
1302 139..141 'a3': A<i128>
1303 139..143 'a3.x': i128
1309 fn infer_tuple_struct_generics() {
1313 enum Option<T> { Some(T), None }
1322 let x: Option<i64> = None;
1326 75..183 '{ ...one; }': ()
1327 81..82 'A': A<i32>(i32) -> A<i32>
1328 81..86 'A(42)': A<i32>
1330 92..93 'A': A<u128>(u128) -> A<u128>
1331 92..101 'A(42u128)': A<u128>
1332 94..100 '42u128': u128
1333 107..111 'Some': Some<&str>(&str) -> Option<&str>
1334 107..116 'Some("x")': Option<&str>
1335 112..115 '"x"': &str
1336 122..134 'Option::Some': Some<&str>(&str) -> Option<&str>
1337 122..139 'Option...e("x")': Option<&str>
1338 135..138 '"x"': &str
1339 145..149 'None': Option<{unknown}>
1340 159..160 'x': Option<i64>
1341 176..180 'None': Option<i64>
1347 fn infer_function_generics() {
1350 fn id<T>(t: T) -> T { t }
1362 37..97 '{ ...(1); }': ()
1363 43..45 'id': fn id<u32>(u32) -> u32
1364 43..51 'id(1u32)': u32
1366 57..67 'id::<i128>': fn id<i128>(i128) -> i128
1367 57..70 'id::<i128>(1)': i128
1370 89..91 'id': fn id<u64>(u64) -> u64
1378 fn infer_impl_generics_basic() {
1385 impl<Y, X> A<X, Y> {
1392 fn z<T>(self, t: T) -> (X, Y, T) {
1398 let a = A { x: 1u64, y: 1i64 };
1406 73..77 'self': A<X, Y>
1407 84..106 '{ ... }': X
1408 94..98 'self': A<X, Y>
1410 116..120 'self': A<X, Y>
1411 127..149 '{ ... }': Y
1412 137..141 'self': A<X, Y>
1413 137..143 'self.y': Y
1414 162..166 'self': A<X, Y>
1416 187..222 '{ ... }': (X, Y, T)
1417 197..216 '(self.....y, t)': (X, Y, T)
1418 198..202 'self': A<X, Y>
1419 198..204 'self.x': X
1420 206..210 'self': A<X, Y>
1421 206..212 'self.y': Y
1423 244..341 '{ ...(1); }': ()
1424 254..255 'a': A<u64, i64>
1425 258..280 'A { x:...1i64 }': A<u64, i64>
1426 265..269 '1u64': u64
1427 274..278 '1i64': i64
1428 286..287 'a': A<u64, i64>
1429 286..291 'a.x()': u64
1430 297..298 'a': A<u64, i64>
1431 297..302 'a.y()': i64
1432 308..309 'a': A<u64, i64>
1433 308..318 'a.z(1i128)': (u64, i64, i128)
1434 312..317 '1i128': i128
1435 324..325 'a': A<u64, i64>
1436 324..338 'a.z::<u128>(1)': (u64, i64, u128)
1443 fn infer_impl_generics_with_autoderef() {
1451 fn as_ref(&self) -> Option<&T> {}
1453 fn test(o: Option<u32>) {
1459 77..81 'self': &Option<T>
1461 110..111 'o': Option<u32>
1462 126..164 '{ ...f(); }': ()
1463 132..145 '(&o).as_ref()': Option<&u32>
1464 133..135 '&o': &Option<u32>
1465 134..135 'o': Option<u32>
1466 151..152 'o': Option<u32>
1467 151..161 'o.as_ref()': Option<&u32>
1473 fn infer_generic_chain() {
1484 fn id<T>(t: T) -> T { t }
1489 let a = A { x: id(y) };
1496 52..56 'self': A<T2>
1497 64..86 '{ ... }': T2
1498 74..78 'self': A<T2>
1503 134..254 '{ ....x() }': i128
1507 163..165 'id': fn id<i128>(i128) -> i128
1508 163..168 'id(x)': i128
1510 178..179 'a': A<i128>
1511 182..196 'A { x: id(y) }': A<i128>
1512 189..191 'id': fn id<i128>(i128) -> i128
1513 189..194 'id(y)': i128
1516 210..212 'id': fn id<i128>(i128) -> i128
1517 210..217 'id(a.x)': i128
1518 213..214 'a': A<i128>
1519 213..216 'a.x': i128
1520 227..228 'b': A<i128>
1521 231..241 'A { x: z }': A<i128>
1523 247..248 'b': A<i128>
1524 247..252 'b.x()': i128
1530 fn infer_associated_const() {
1551 impl Trait for TraitTest {
1556 let x = Struct::FOO;
1558 let z = TraitTest::ID;
1565 228..306 '{ ...:ID; }': ()
1567 242..253 'Struct::FOO': u32
1569 267..276 'Enum::BAR': u32
1571 290..303 'TraitTest::ID': u32
1577 fn infer_type_alias() {
1580 struct A<X, Y> { x: X, y: Y }
1581 type Foo = A<u32, i128>;
1582 type Bar<T> = A<T, u128>;
1583 type Baz<U, V> = A<V, U>;
1584 fn test(x: Foo, y: Bar<&str>, z: Baz<i8, u8>) {
1594 115..116 'x': A<u32, i128>
1595 123..124 'y': A<&str, u128>
1596 137..138 'z': A<u8, i8>
1597 153..210 '{ ...z.y; }': ()
1598 159..160 'x': A<u32, i128>
1600 168..169 'x': A<u32, i128>
1601 168..171 'x.y': i128
1602 177..178 'y': A<&str, u128>
1603 177..180 'y.x': &str
1604 186..187 'y': A<&str, u128>
1605 186..189 'y.y': u128
1606 195..196 'z': A<u8, i8>
1608 204..205 'z': A<u8, i8>
1615 fn recursive_type_alias() {
1624 58..59 'x': {unknown}
1631 fn infer_type_param() {
1634 fn id<T>(x: T) -> T {
1638 fn clone<T>(x: &T) -> T {
1645 let x: bool = clone(z);
1657 77..157 '{ ...(1); }': ()
1660 102..104 'id': fn id<u32>(u32) -> u32
1661 102..107 'id(y)': u32
1664 127..132 'clone': fn clone<bool>(&bool) -> bool
1665 127..135 'clone(z)': bool
1667 141..151 'id::<i128>': fn id<i128>(i128) -> i128
1668 141..154 'id::<i128>(1)': i128
1679 impl Foo { const ASSOC_CONST: u32 = 0; }
1680 const GLOBAL_CONST: u32 = 101;
1682 const LOCAL_CONST: u32 = 99;
1683 let x = LOCAL_CONST;
1684 let z = GLOBAL_CONST;
1685 let id = Foo::ASSOC_CONST;
1691 94..212 '{ ...NST; }': ()
1693 141..152 'LOCAL_CONST': u32
1695 166..178 'GLOBAL_CONST': u32
1697 193..209 'Foo::A..._CONST': u32
1707 static GLOBAL_STATIC: u32 = 101;
1708 static mut GLOBAL_STATIC_MUT: u32 = 101;
1710 static LOCAL_STATIC: u32 = 99;
1711 static mut LOCAL_STATIC_MUT: u32 = 99;
1712 let x = LOCAL_STATIC;
1713 let y = LOCAL_STATIC_MUT;
1714 let z = GLOBAL_STATIC;
1715 let w = GLOBAL_STATIC_MUT;
1721 84..279 '{ ...MUT; }': ()
1723 176..188 'LOCAL_STATIC': u32
1725 202..218 'LOCAL_...IC_MUT': u32
1727 232..245 'GLOBAL_STATIC': u32
1729 259..276 'GLOBAL...IC_MUT': u32
1737 fn shadowing_primitive() {
1743 impl i32 { fn foo(&self) -> Foo { Foo } }
1754 fn shadowing_primitive_with_inner_items() {
1760 impl i32 { fn foo(&self) -> Foo { Foo } }
1772 fn not_shadowing_primitive_by_module() {
1780 fn foo() -> &'static str { "" }
1790 fn not_shadowing_module_by_primitive() {
1798 fn foo() -> &'static str { "" }
1807 // This test is actually testing the shadowing behavior within hir_def. It
1808 // lives here because the testing infrastructure in hir_def isn't currently
1809 // capable of asserting the necessary conditions.
1811 fn should_be_shadowing_imports() {
1815 pub fn foo() -> i8 {0}
1816 pub struct foo { a: i8 }
1818 mod b { pub fn foo () -> u8 {0} }
1819 mod c { pub struct foo { a: u8 } }
1821 pub use super::a::*;
1822 pub use super::c::foo;
1823 pub use super::b::foo;
1836 fn closure_return() {
1840 let x = || -> usize { return 1; };
1844 16..58 '{ ...; }; }': ()
1845 26..27 'x': || -> usize
1846 30..55 '|| -> ...n 1; }': || -> usize
1847 42..55 '{ return 1; }': usize
1848 44..52 'return 1': !
1855 fn closure_return_unit() {
1859 let x = || { return; };
1863 16..47 '{ ...; }; }': ()
1864 26..27 'x': || -> ()
1865 30..44 '|| { return; }': || -> ()
1866 33..44 '{ return; }': ()
1873 fn closure_return_inferred() {
1877 let x = || { "test" };
1881 16..46 '{ ..." }; }': ()
1882 26..27 'x': || -> &str
1883 30..43 '|| { "test" }': || -> &str
1884 33..43 '{ "test" }': &str
1885 35..41 '"test"': &str
1891 fn fn_pointer_return() {
1899 let vtable = Vtable { method: || {} };
1900 let m = vtable.method;
1904 47..120 '{ ...hod; }': ()
1905 57..63 'vtable': Vtable
1906 66..90 'Vtable...| {} }': Vtable
1907 83..88 '|| {}': || -> ()
1910 104..110 'vtable': Vtable
1911 104..117 'vtable.method': fn()
1917 fn effects_smoke_test() {
1921 let x = unsafe { 92 };
1922 let y = async { async { () }.await };
1924 let w = const { 92 };
1928 #[prelude_import] use future::*;
1931 #[lang = "future_trait"]
1932 pub trait Future { type Output; }
1936 16..162 '{ ...2 }; }': ()
1938 30..43 'unsafe { 92 }': i32
1939 37..43 '{ 92 }': i32
1941 53..54 'y': impl Future<Output = ()>
1942 57..85 'async ...wait }': impl Future<Output = ()>
1943 63..85 '{ asyn...wait }': ()
1944 65..77 'async { () }': impl Future<Output = ()>
1945 65..83 'async ....await': ()
1948 95..96 'z': {unknown}
1949 99..109 'try { () }': {unknown}
1950 103..109 '{ () }': ()
1953 123..135 'const { 92 }': i32
1954 129..135 '{ 92 }': i32
1957 153..159 '{ 92 }': i32
1964 fn infer_generic_from_later_assignment() {
1967 enum Option<T> { Some(T), None }
1978 59..129 '{ ... } }': ()
1979 69..76 'mut end': Option<bool>
1980 79..83 'None': Option<bool>
1981 89..127 'loop {... }': !
1982 94..127 '{ ... }': ()
1983 104..107 'end': Option<bool>
1984 104..120 'end = ...(true)': ()
1985 110..114 'Some': Some<bool>(bool) -> Option<bool>
1986 110..120 'Some(true)': Option<bool>
1987 115..119 'true': bool
1993 fn infer_loop_break_with_val() {
1996 enum Option<T> { Some(T), None }
2010 59..168 '{ ... }; }': ()
2011 69..70 'x': Option<bool>
2012 73..165 'loop {... }': Option<bool>
2013 78..165 '{ ... }': ()
2014 88..132 'if fal... }': ()
2015 91..96 'false': bool
2016 97..132 '{ ... }': ()
2017 111..121 'break None': !
2018 117..121 'None': Option<bool>
2019 142..158 'break ...(true)': !
2020 148..152 'Some': Some<bool>(bool) -> Option<bool>
2021 148..158 'Some(true)': Option<bool>
2022 153..157 'true': bool
2028 fn infer_loop_break_without_val() {
2031 enum Option<T> { Some(T), None }
2043 59..136 '{ ... }; }': ()
2045 73..133 'loop {... }': ()
2046 78..133 '{ ... }': ()
2047 88..127 'if fal... }': ()
2048 91..96 'false': bool
2049 97..127 '{ ... }': ()
2056 fn infer_labelled_break_with_val() {
2060 let _x = || 'outer: loop {
2061 let inner = 'inner: loop {
2062 let i = Default::default();
2063 if (break 'outer i) {
2064 loop { break 'inner 5i8; };
2075 9..335 '{ ... }; }': ()
2076 19..21 '_x': || -> bool
2077 24..332 '|| 'ou... }': || -> bool
2078 27..332 ''outer... }': bool
2079 40..332 '{ ... }': ()
2081 62..300 ''inner... }': i8
2082 75..300 '{ ... }': ()
2084 97..113 'Defaul...efault': {unknown}
2085 97..115 'Defaul...ault()': bool
2086 129..269 'if (br... }': ()
2087 133..147 'break 'outer i': !
2089 149..208 '{ ... }': ()
2090 167..193 'loop {...5i8; }': !
2091 172..193 '{ brea...5i8; }': ()
2092 174..190 'break ...er 5i8': !
2094 214..269 'if tru... }': ()
2095 217..221 'true': bool
2096 222..269 '{ ... }': ()
2097 240..254 'break 'inner 6': !
2099 282..289 'break 7': !
2101 310..325 'break inner < 8': !
2102 316..321 'inner': i8
2103 316..325 'inner < 8': bool
2110 fn infer_labelled_block_break_with_val() {
2113 fn default<T>() -> T { loop {} }
2116 let inner = 'inner: {
2118 if (break 'outer i) {
2123 break 'inner 'innermost: { 0 };
2126 break 'outer inner < 8;
2131 21..32 '{ loop {} }': T
2134 42..381 '{ ... }; }': ()
2136 65..378 '{ ... }': bool
2138 95..339 '{ ... }': i8
2140 117..124 'default': fn default<bool>() -> bool
2141 117..126 'default()': bool
2142 140..270 'if (br... }': ()
2143 144..158 'break 'outer i': !
2145 160..209 '{ ... }': ()
2146 178..194 'break ...er 5i8': !
2148 215..270 'if tru... }': ()
2149 218..222 'true': bool
2150 223..270 '{ ... }': ()
2151 241..255 'break 'inner 6': !
2153 283..313 'break ... { 0 }': !
2154 308..313 '{ 0 }': i8
2157 349..371 'break ...er < 8': !
2158 362..367 'inner': i8
2159 362..371 'inner < 8': bool
2166 fn generic_default() {
2169 struct Thing<T = ()> { t: T }
2170 enum OtherThing<T = ()> {
2175 fn test(t1: Thing, t2: OtherThing, t3: Thing<i32>, t4: OtherThing<i32>) {
2179 OtherThing::One { t } => { t; },
2180 OtherThing::Two(t) => { t; },
2183 OtherThing::One { t } => { t; },
2184 OtherThing::Two(t) => { t; },
2189 97..99 't1': Thing<()>
2190 108..110 't2': OtherThing<()>
2191 124..126 't3': Thing<i32>
2192 140..142 't4': OtherThing<i32>
2193 161..384 '{ ... } }': ()
2194 167..169 't1': Thing<()>
2196 177..179 't3': Thing<i32>
2197 177..181 't3.t': i32
2198 187..282 'match ... }': ()
2199 193..195 't2': OtherThing<()>
2200 206..227 'OtherT... { t }': OtherThing<()>
2202 231..237 '{ t; }': ()
2204 247..265 'OtherT...Two(t)': OtherThing<()>
2206 269..275 '{ t; }': ()
2208 287..382 'match ... }': ()
2209 293..295 't4': OtherThing<i32>
2210 306..327 'OtherT... { t }': OtherThing<i32>
2212 331..337 '{ t; }': ()
2214 347..365 'OtherT...Two(t)': OtherThing<i32>
2216 369..375 '{ t; }': ()
2223 fn generic_default_in_struct_literal() {
2226 struct Thing<T = ()> { t: T }
2227 enum OtherThing<T = ()> {
2233 let x = Thing { t: loop {} };
2234 let y = Thing { t: () };
2235 let z = Thing { t: 1i32 };
2236 if let Thing { t } = z {
2240 let a = OtherThing::One { t: 1i32 };
2241 let b = OtherThing::Two(1i32);
2245 99..319 '{ ...32); }': ()
2246 109..110 'x': Thing<!>
2247 113..133 'Thing ...p {} }': Thing<!>
2248 124..131 'loop {}': !
2250 143..144 'y': Thing<()>
2251 147..162 'Thing { t: () }': Thing<()>
2253 172..173 'z': Thing<i32>
2254 176..193 'Thing ...1i32 }': Thing<i32>
2255 187..191 '1i32': i32
2256 199..240 'if let... }': ()
2257 206..217 'Thing { t }': Thing<i32>
2259 220..221 'z': Thing<i32>
2260 222..240 '{ ... }': ()
2262 250..251 'a': OtherThing<i32>
2263 254..281 'OtherT...1i32 }': OtherThing<i32>
2264 275..279 '1i32': i32
2265 291..292 'b': OtherThing<i32>
2266 295..310 'OtherThing::Two': Two<i32>(i32) -> OtherThing<i32>
2267 295..316 'OtherT...(1i32)': OtherThing<i32>
2268 311..315 '1i32': i32
2274 fn generic_default_depending_on_other_type_arg() {
2275 // FIXME: the {unknown} is a bug
2278 struct Thing<T = u128, F = fn() -> T> { t: T }
2280 fn test(t1: Thing<u32>, t2: Thing) {
2283 Thing::<_> { t: 1u32 };
2287 56..58 't1': Thing<u32, fn() -> u32>
2288 72..74 't2': Thing<u128, fn() -> u128>
2289 83..130 '{ ...2 }; }': ()
2290 89..91 't1': Thing<u32, fn() -> u32>
2291 97..99 't2': Thing<u128, fn() -> u128>
2292 105..127 'Thing:...1u32 }': Thing<u32, fn() -> {unknown}>
2293 121..125 '1u32': u32
2299 fn generic_default_depending_on_other_type_arg_forward() {
2300 // the {unknown} here is intentional, as defaults are not allowed to
2301 // refer to type parameters coming later
2304 struct Thing<F = fn() -> T, T = u128> { t: T }
2306 fn test(t1: Thing) {
2311 56..58 't1': Thing<fn() -> {unknown}, u128>
2312 67..78 '{ t1; }': ()
2313 73..75 't1': Thing<fn() -> {unknown}, u128>
2319 fn infer_operator_overload() {
2320 cov_mark::check!(infer_expr_inner_binary_operator_overload);
2324 struct V2([f32; 2]);
2327 pub trait Add<Rhs = Self> {
2328 /// The resulting type after applying the `+` operator.
2331 /// Performs the `+` operation.
2333 fn add(self, rhs: Rhs) -> Self::Output;
2336 impl Add<V2> for V2 {
2339 fn add(self, rhs: V2) -> V2 {
2340 let x = self.0[0] + rhs.0[0];
2341 let y = self.0[1] + rhs.0[1];
2347 let va = V2([0.0, 1.0]);
2348 let vb = V2([0.0, 1.0]);
2355 207..211 'self': Self
2359 320..422 '{ ... }': V2
2362 338..344 'self.0': [f32; 2]
2363 338..347 'self.0[0]': {unknown}
2364 338..358 'self.0...s.0[0]': f32
2367 350..355 'rhs.0': [f32; 2]
2368 350..358 'rhs.0[0]': {unknown}
2372 376..382 'self.0': [f32; 2]
2373 376..385 'self.0[1]': {unknown}
2374 376..396 'self.0...s.0[1]': f32
2377 388..393 'rhs.0': [f32; 2]
2378 388..396 'rhs.0[1]': {unknown}
2380 406..408 'V2': V2([f32; 2]) -> V2
2381 406..416 'V2([x, y])': V2
2382 409..415 '[x, y]': [f32; 2]
2385 436..519 '{ ... vb; }': ()
2387 451..453 'V2': V2([f32; 2]) -> V2
2388 451..465 'V2([0.0, 1.0])': V2
2389 454..464 '[0.0, 1.0]': [f32; 2]
2393 480..482 'V2': V2([f32; 2]) -> V2
2394 480..494 'V2([0.0, 1.0])': V2
2395 483..493 '[0.0, 1.0]': [f32; 2]
2400 509..516 'va + vb': V2
2407 fn infer_const_params() {
2410 fn foo<const FOO: usize>() {
2415 27..49 '{ ...FOO; }': ()
2423 fn infer_inner_type() {
2427 struct S { field: u32 }
2428 let s = S { field: 0 };
2433 9..89 '{ ...eld; }': ()
2435 51..65 'S { field: 0 }': S
2439 79..86 's.field': u32
2445 fn infer_nested_inner_type() {
2450 let s = S { field: 0 };
2453 struct S { field: u32 }
2457 9..109 '{ ...32 } }': ()
2458 15..79 '{ ... }': ()
2460 33..47 'S { field: 0 }': S
2464 65..72 's.field': u32
2470 fn inner_use_enum_rename() {
2487 34..123 '{ ... } }': ()
2489 71..78 'R::Info': Request
2490 84..121 'match ... }': ()
2492 102..109 'R::Info': Request
2506 pub trait Unsize<T: ?Sized> {}
2508 #[lang = "coerce_unsized"]
2509 pub trait CoerceUnsized<T> {}
2511 pub unsafe trait Allocator {}
2514 unsafe impl Allocator for Global {}
2516 #[lang = "owned_box"]
2518 pub struct Box<T: ?Sized, A: Allocator = Global>;
2520 impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<Box<U, A>> for Box<T, A> {}
2522 pub struct Vec<T, A: Allocator = Global> {}
2527 #[lang = "slice_alloc"]
2529 pub fn into_vec<A: Allocator>(self: Box<Self, A>) -> Vec<T, A> {
2535 let vec = <[_]>::into_vec(box [1i32]);
2539 569..573 'self': Box<[T], A>
2540 602..634 '{ ... }': Vec<T, A>
2541 612..628 'unimpl...ted!()': Vec<T, A>
2542 648..694 '{ ...2]); }': ()
2543 658..661 'vec': Vec<i32, Global>
2544 664..679 '<[_]>::into_vec': fn into_vec<i32, Global>(Box<[i32], Global>) -> Vec<i32, Global>
2545 664..691 '<[_]>:...1i32])': Vec<i32, Global>
2546 680..690 'box [1i32]': Box<[i32; 1], Global>
2547 684..690 '[1i32]': [i32; 1]
2548 685..689 '1i32': i32
2554 fn cfgd_out_assoc_items() {
2573 fn infer_type_alias_variant() {
2584 Qux::Bar(bar) => (),
2585 Qux::Baz { baz } => (),
2590 72..166 '{ ... } }': ()
2591 78..164 'match ... }': ()
2592 84..92 'Foo::Bar': Bar(i32) -> Foo
2593 84..95 'Foo::Bar(3)': Foo
2595 106..119 'Qux::Bar(bar)': Foo
2598 135..151 'Qux::B... baz }': Foo
2606 fn infer_boxed_self_receiver() {
2610 use core::ops::Deref;
2614 impl<T> Deref for Box<T> {
2616 fn deref(&self) -> &Self::Target;
2622 fn get_inner<'a>(self: &'a Box<Self>) -> &'a T {}
2624 fn get_self<'a>(self: &'a Box<Self>) -> &'a Self {}
2626 fn into_inner(self: Box<Self>) -> Self {}
2630 let boxed = Box(Foo(0_i32));
2632 let bad1 = boxed.get_inner();
2633 let good1 = Foo::get_inner(&boxed);
2635 let bad2 = boxed.get_self();
2636 let good2 = Foo::get_self(&boxed);
2638 let inner = boxed.into_inner();
2642 104..108 'self': &Box<T>
2643 188..192 'self': &Box<Foo<T>>
2645 242..246 'self': &Box<Foo<T>>
2647 297..301 'self': Box<Foo<T>>
2649 338..559 '{ ...r(); }': ()
2650 348..353 'boxed': Box<Foo<i32>>
2651 356..359 'Box': Box<Foo<i32>>(Foo<i32>) -> Box<Foo<i32>>
2652 356..371 'Box(Foo(0_i32))': Box<Foo<i32>>
2653 360..363 'Foo': Foo<i32>(i32) -> Foo<i32>
2654 360..370 'Foo(0_i32)': Foo<i32>
2655 364..369 '0_i32': i32
2656 382..386 'bad1': &i32
2657 389..394 'boxed': Box<Foo<i32>>
2658 389..406 'boxed....nner()': &i32
2659 416..421 'good1': &i32
2660 424..438 'Foo::get_inner': fn get_inner<i32>(&Box<Foo<i32>>) -> &i32
2661 424..446 'Foo::g...boxed)': &i32
2662 439..445 '&boxed': &Box<Foo<i32>>
2663 440..445 'boxed': Box<Foo<i32>>
2664 457..461 'bad2': &Foo<i32>
2665 464..469 'boxed': Box<Foo<i32>>
2666 464..480 'boxed....self()': &Foo<i32>
2667 490..495 'good2': &Foo<i32>
2668 498..511 'Foo::get_self': fn get_self<i32>(&Box<Foo<i32>>) -> &Foo<i32>
2669 498..519 'Foo::g...boxed)': &Foo<i32>
2670 512..518 '&boxed': &Box<Foo<i32>>
2671 513..518 'boxed': Box<Foo<i32>>
2672 530..535 'inner': Foo<i32>
2673 538..543 'boxed': Box<Foo<i32>>
2674 538..556 'boxed....nner()': Foo<i32>
2683 //- /main.rs edition:2015 crate:main deps:core
2689 //- /core.rs crate:core