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 95..113 'unsafe...(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 152..170 'unsafe...(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 block_modifiers_smoke_test() {
1920 //- minicore: future
1922 let x = unsafe { 92 };
1923 let y = async { async { () }.await };
1925 let w = const { 92 };
1930 16..162 '{ ...2 }; }': ()
1932 30..43 'unsafe { 92 }': i32
1933 30..43 'unsafe { 92 }': i32
1935 53..54 'y': impl Future<Output = ()>
1936 57..85 'async ...wait }': ()
1937 57..85 'async ...wait }': impl Future<Output = ()>
1938 65..77 'async { () }': ()
1939 65..77 'async { () }': impl Future<Output = ()>
1940 65..83 'async ....await': ()
1942 95..96 'z': {unknown}
1943 99..109 'try { () }': ()
1944 99..109 'try { () }': {unknown}
1947 123..135 'const { 92 }': i32
1948 123..135 'const { 92 }': i32
1951 149..159 ''a: { 92 }': i32
1958 fn infer_generic_from_later_assignment() {
1961 enum Option<T> { Some(T), None }
1972 59..129 '{ ... } }': ()
1973 69..76 'mut end': Option<bool>
1974 79..83 'None': Option<bool>
1975 89..127 'loop {... }': !
1976 94..127 '{ ... }': ()
1977 104..107 'end': Option<bool>
1978 104..120 'end = ...(true)': ()
1979 110..114 'Some': Some<bool>(bool) -> Option<bool>
1980 110..120 'Some(true)': Option<bool>
1981 115..119 'true': bool
1987 fn infer_loop_break_with_val() {
1990 enum Option<T> { Some(T), None }
2004 59..168 '{ ... }; }': ()
2005 69..70 'x': Option<bool>
2006 73..165 'loop {... }': Option<bool>
2007 78..165 '{ ... }': ()
2008 88..132 'if fal... }': ()
2009 91..96 'false': bool
2010 97..132 '{ ... }': ()
2011 111..121 'break None': !
2012 117..121 'None': Option<bool>
2013 142..158 'break ...(true)': !
2014 148..152 'Some': Some<bool>(bool) -> Option<bool>
2015 148..158 'Some(true)': Option<bool>
2016 153..157 'true': bool
2022 fn infer_loop_break_without_val() {
2025 enum Option<T> { Some(T), None }
2037 59..136 '{ ... }; }': ()
2039 73..133 'loop {... }': ()
2040 78..133 '{ ... }': ()
2041 88..127 'if fal... }': ()
2042 91..96 'false': bool
2043 97..127 '{ ... }': ()
2050 fn infer_labelled_break_with_val() {
2054 let _x = || 'outer: loop {
2055 let inner = 'inner: loop {
2056 let i = Default::default();
2057 if (break 'outer i) {
2058 loop { break 'inner 5i8; };
2069 9..335 '{ ... }; }': ()
2070 19..21 '_x': || -> bool
2071 24..332 '|| 'ou... }': || -> bool
2072 27..332 ''outer... }': bool
2073 40..332 '{ ... }': ()
2075 62..300 ''inner... }': i8
2076 75..300 '{ ... }': ()
2078 97..113 'Defaul...efault': {unknown}
2079 97..115 'Defaul...ault()': bool
2080 129..269 'if (br... }': ()
2081 133..147 'break 'outer i': !
2083 149..208 '{ ... }': ()
2084 167..193 'loop {...5i8; }': !
2085 172..193 '{ brea...5i8; }': ()
2086 174..190 'break ...er 5i8': !
2088 214..269 'if tru... }': ()
2089 217..221 'true': bool
2090 222..269 '{ ... }': ()
2091 240..254 'break 'inner 6': !
2093 282..289 'break 7': !
2095 310..325 'break inner < 8': !
2096 316..321 'inner': i8
2097 316..325 'inner < 8': bool
2104 fn infer_labelled_block_break_with_val() {
2107 fn default<T>() -> T { loop {} }
2110 let inner = 'inner: {
2112 if (break 'outer i) {
2117 break 'inner 'innermost: { 0 };
2120 break 'outer inner < 8;
2125 21..32 '{ loop {} }': T
2128 42..381 '{ ... }; }': ()
2130 57..378 ''outer... }': bool
2132 87..339 ''inner... }': i8
2134 117..124 'default': fn default<bool>() -> bool
2135 117..126 'default()': bool
2136 140..270 'if (br... }': ()
2137 144..158 'break 'outer i': !
2139 160..209 '{ ... }': ()
2140 178..194 'break ...er 5i8': !
2142 215..270 'if tru... }': ()
2143 218..222 'true': bool
2144 223..270 '{ ... }': ()
2145 241..255 'break 'inner 6': !
2147 283..313 'break ... { 0 }': !
2148 296..313 ''inner... { 0 }': i8
2151 349..371 'break ...er < 8': !
2152 362..367 'inner': i8
2153 362..371 'inner < 8': bool
2160 fn generic_default() {
2163 struct Thing<T = ()> { t: T }
2164 enum OtherThing<T = ()> {
2169 fn test(t1: Thing, t2: OtherThing, t3: Thing<i32>, t4: OtherThing<i32>) {
2173 OtherThing::One { t } => { t; },
2174 OtherThing::Two(t) => { t; },
2177 OtherThing::One { t } => { t; },
2178 OtherThing::Two(t) => { t; },
2183 97..99 't1': Thing<()>
2184 108..110 't2': OtherThing<()>
2185 124..126 't3': Thing<i32>
2186 140..142 't4': OtherThing<i32>
2187 161..384 '{ ... } }': ()
2188 167..169 't1': Thing<()>
2190 177..179 't3': Thing<i32>
2191 177..181 't3.t': i32
2192 187..282 'match ... }': ()
2193 193..195 't2': OtherThing<()>
2194 206..227 'OtherT... { t }': OtherThing<()>
2196 231..237 '{ t; }': ()
2198 247..265 'OtherT...Two(t)': OtherThing<()>
2200 269..275 '{ t; }': ()
2202 287..382 'match ... }': ()
2203 293..295 't4': OtherThing<i32>
2204 306..327 'OtherT... { t }': OtherThing<i32>
2206 331..337 '{ t; }': ()
2208 347..365 'OtherT...Two(t)': OtherThing<i32>
2210 369..375 '{ t; }': ()
2217 fn generic_default_in_struct_literal() {
2220 struct Thing<T = ()> { t: T }
2221 enum OtherThing<T = ()> {
2227 let x = Thing { t: loop {} };
2228 let y = Thing { t: () };
2229 let z = Thing { t: 1i32 };
2230 if let Thing { t } = z {
2234 let a = OtherThing::One { t: 1i32 };
2235 let b = OtherThing::Two(1i32);
2239 99..319 '{ ...32); }': ()
2240 109..110 'x': Thing<!>
2241 113..133 'Thing ...p {} }': Thing<!>
2242 124..131 'loop {}': !
2244 143..144 'y': Thing<()>
2245 147..162 'Thing { t: () }': Thing<()>
2247 172..173 'z': Thing<i32>
2248 176..193 'Thing ...1i32 }': Thing<i32>
2249 187..191 '1i32': i32
2250 199..240 'if let... }': ()
2251 202..221 'let Th... } = z': bool
2252 206..217 'Thing { t }': Thing<i32>
2254 220..221 'z': Thing<i32>
2255 222..240 '{ ... }': ()
2257 250..251 'a': OtherThing<i32>
2258 254..281 'OtherT...1i32 }': OtherThing<i32>
2259 275..279 '1i32': i32
2260 291..292 'b': OtherThing<i32>
2261 295..310 'OtherThing::Two': Two<i32>(i32) -> OtherThing<i32>
2262 295..316 'OtherT...(1i32)': OtherThing<i32>
2263 311..315 '1i32': i32
2269 fn generic_default_depending_on_other_type_arg() {
2270 // FIXME: the {unknown} is a bug
2273 struct Thing<T = u128, F = fn() -> T> { t: T }
2275 fn test(t1: Thing<u32>, t2: Thing) {
2278 Thing::<_> { t: 1u32 };
2282 56..58 't1': Thing<u32, fn() -> u32>
2283 72..74 't2': Thing<u128, fn() -> u128>
2284 83..130 '{ ...2 }; }': ()
2285 89..91 't1': Thing<u32, fn() -> u32>
2286 97..99 't2': Thing<u128, fn() -> u128>
2287 105..127 'Thing:...1u32 }': Thing<u32, fn() -> {unknown}>
2288 121..125 '1u32': u32
2294 fn generic_default_depending_on_other_type_arg_forward() {
2295 // the {unknown} here is intentional, as defaults are not allowed to
2296 // refer to type parameters coming later
2299 struct Thing<F = fn() -> T, T = u128> { t: T }
2301 fn test(t1: Thing) {
2306 56..58 't1': Thing<fn() -> {unknown}, u128>
2307 67..78 '{ t1; }': ()
2308 73..75 't1': Thing<fn() -> {unknown}, u128>
2314 fn infer_operator_overload() {
2318 struct V2([f32; 2]);
2320 impl core::ops::Add<V2> for V2 {
2325 let va = V2([0.0, 1.0]);
2326 let vb = V2([0.0, 1.0]);
2337 fn infer_const_params() {
2340 fn foo<const FOO: usize>() {
2345 27..49 '{ ...FOO; }': ()
2353 fn infer_inner_type() {
2357 struct S { field: u32 }
2358 let s = S { field: 0 };
2363 9..89 '{ ...eld; }': ()
2365 51..65 'S { field: 0 }': S
2369 79..86 's.field': u32
2375 fn infer_nested_inner_type() {
2380 let s = S { field: 0 };
2383 struct S { field: u32 }
2387 9..109 '{ ...32 } }': ()
2388 15..79 '{ ... }': ()
2390 33..47 'S { field: 0 }': S
2394 65..72 's.field': u32
2400 fn inner_use_enum_rename() {
2417 34..123 '{ ... } }': ()
2419 71..78 'R::Info': Request
2420 84..121 'match ... }': ()
2422 102..109 'R::Info': Request
2436 pub trait Unsize<T: ?Sized> {}
2438 #[lang = "coerce_unsized"]
2439 pub trait CoerceUnsized<T> {}
2441 pub unsafe trait Allocator {}
2444 unsafe impl Allocator for Global {}
2446 #[lang = "owned_box"]
2448 pub struct Box<T: ?Sized, A: Allocator = Global>;
2450 impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<Box<U, A>> for Box<T, A> {}
2452 pub struct Vec<T, A: Allocator = Global> {}
2457 #[lang = "slice_alloc"]
2459 pub fn into_vec<A: Allocator>(self: Box<Self, A>) -> Vec<T, A> {
2465 let vec = <[_]>::into_vec(box [1i32]);
2469 569..573 'self': Box<[T], A>
2470 602..634 '{ ... }': Vec<T, A>
2471 612..628 'unimpl...ted!()': Vec<T, A>
2472 648..694 '{ ...2]); }': ()
2473 658..661 'vec': Vec<i32, Global>
2474 664..679 '<[_]>::into_vec': fn into_vec<i32, Global>(Box<[i32], Global>) -> Vec<i32, Global>
2475 664..691 '<[_]>:...1i32])': Vec<i32, Global>
2476 680..690 'box [1i32]': Box<[i32; 1], Global>
2477 684..690 '[1i32]': [i32; 1]
2478 685..689 '1i32': i32
2484 fn cfgd_out_assoc_items() {
2503 fn infer_type_alias_variant() {
2514 Qux::Bar(bar) => (),
2515 Qux::Baz { baz } => (),
2520 72..166 '{ ... } }': ()
2521 78..164 'match ... }': ()
2522 84..92 'Foo::Bar': Bar(i32) -> Foo
2523 84..95 'Foo::Bar(3)': Foo
2525 106..119 'Qux::Bar(bar)': Foo
2528 135..151 'Qux::B... baz }': Foo
2536 fn infer_boxed_self_receiver() {
2540 use core::ops::Deref;
2544 impl<T> Deref for Box<T> {
2546 fn deref(&self) -> &Self::Target;
2552 fn get_inner<'a>(self: &'a Box<Self>) -> &'a T {}
2554 fn get_self<'a>(self: &'a Box<Self>) -> &'a Self {}
2556 fn into_inner(self: Box<Self>) -> Self {}
2560 let boxed = Box(Foo(0_i32));
2562 let bad1 = boxed.get_inner();
2563 let good1 = Foo::get_inner(&boxed);
2565 let bad2 = boxed.get_self();
2566 let good2 = Foo::get_self(&boxed);
2568 let inner = boxed.into_inner();
2572 104..108 'self': &Box<T>
2573 188..192 'self': &Box<Foo<T>>
2575 242..246 'self': &Box<Foo<T>>
2577 297..301 'self': Box<Foo<T>>
2579 338..559 '{ ...r(); }': ()
2580 348..353 'boxed': Box<Foo<i32>>
2581 356..359 'Box': Box<Foo<i32>>(Foo<i32>) -> Box<Foo<i32>>
2582 356..371 'Box(Foo(0_i32))': Box<Foo<i32>>
2583 360..363 'Foo': Foo<i32>(i32) -> Foo<i32>
2584 360..370 'Foo(0_i32)': Foo<i32>
2585 364..369 '0_i32': i32
2586 382..386 'bad1': &i32
2587 389..394 'boxed': Box<Foo<i32>>
2588 389..406 'boxed....nner()': &i32
2589 416..421 'good1': &i32
2590 424..438 'Foo::get_inner': fn get_inner<i32>(&Box<Foo<i32>>) -> &i32
2591 424..446 'Foo::g...boxed)': &i32
2592 439..445 '&boxed': &Box<Foo<i32>>
2593 440..445 'boxed': Box<Foo<i32>>
2594 457..461 'bad2': &Foo<i32>
2595 464..469 'boxed': Box<Foo<i32>>
2596 464..480 'boxed....self()': &Foo<i32>
2597 490..495 'good2': &Foo<i32>
2598 498..511 'Foo::get_self': fn get_self<i32>(&Box<Foo<i32>>) -> &Foo<i32>
2599 498..519 'Foo::g...boxed)': &Foo<i32>
2600 512..518 '&boxed': &Box<Foo<i32>>
2601 513..518 'boxed': Box<Foo<i32>>
2602 530..535 'inner': Foo<i32>
2603 538..543 'boxed': Box<Foo<i32>>
2604 538..556 'boxed....nner()': Foo<i32>
2613 //- /main.rs edition:2015 crate:main deps:core
2619 //- /core.rs crate:core