1 use expect_test::expect;
3 use super::{check_infer, check_no_mismatches, 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... }': ()
1000 75..80 'false': bool
1001 81..106 '{ ... }': ()
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 let y: [u8; 2+2] = [1,2,3,4];
1211 27..326 '{ ...,4]; }': ()
1212 37..38 'a': [&str; 1]
1213 41..44 '[x]': [&str; 1]
1215 54..55 'b': [[&str; 1]; 2]
1216 58..64 '[a, a]': [[&str; 1]; 2]
1217 59..60 'a': [&str; 1]
1218 62..63 'a': [&str; 1]
1219 74..75 'c': [[[&str; 1]; 2]; 2]
1220 78..84 '[b, b]': [[[&str; 1]; 2]; 2]
1221 79..80 'b': [[&str; 1]; 2]
1222 82..83 'b': [[&str; 1]; 2]
1223 95..96 'd': [isize; 4]
1224 99..111 '[y, 1, 2, 3]': [isize; 4]
1229 121..122 'd': [isize; 4]
1230 125..137 '[1, y, 2, 3]': [isize; 4]
1235 147..148 'e': [isize; 1]
1236 151..154 '[y]': [isize; 1]
1238 164..165 'f': [[isize; 4]; 2]
1239 168..174 '[d, d]': [[isize; 4]; 2]
1240 169..170 'd': [isize; 4]
1241 172..173 'd': [isize; 4]
1242 184..185 'g': [[isize; 1]; 2]
1243 188..194 '[e, e]': [[isize; 1]; 2]
1244 189..190 'e': [isize; 1]
1245 192..193 'e': [isize; 1]
1246 205..206 'h': [i32; 2]
1247 209..215 '[1, 2]': [i32; 2]
1250 225..226 'i': [&str; 2]
1251 229..239 '["a", "b"]': [&str; 2]
1252 230..233 '"a"': &str
1253 235..238 '"b"': &str
1254 250..251 'b': [[&str; 1]; 2]
1255 254..264 '[a, ["b"]]': [[&str; 1]; 2]
1256 255..256 'a': [&str; 1]
1257 258..263 '["b"]': [&str; 1]
1258 259..262 '"b"': &str
1259 274..275 'x': [u8; 0]
1260 287..289 '[]': [u8; 0]
1261 299..300 'y': [u8; 4]
1262 314..323 '[1,2,3,4]': [u8; 4]
1272 fn infer_struct_generics() {
1279 fn test(a1: A<u32>, i: i32) {
1281 let a2 = A { x: i };
1283 let a3 = A::<i128> { x: 1 };
1290 55..146 '{ ...3.x; }': ()
1294 80..90 'A { x: i }': A<i32>
1298 110..112 'a3': A<i128>
1299 115..133 'A::<i1...x: 1 }': A<i128>
1301 139..141 'a3': A<i128>
1302 139..143 'a3.x': i128
1308 fn infer_tuple_struct_generics() {
1312 enum Option<T> { Some(T), None }
1321 let x: Option<i64> = None;
1325 75..183 '{ ...one; }': ()
1326 81..82 'A': A<i32>(i32) -> A<i32>
1327 81..86 'A(42)': A<i32>
1329 92..93 'A': A<u128>(u128) -> A<u128>
1330 92..101 'A(42u128)': A<u128>
1331 94..100 '42u128': u128
1332 107..111 'Some': Some<&str>(&str) -> Option<&str>
1333 107..116 'Some("x")': Option<&str>
1334 112..115 '"x"': &str
1335 122..134 'Option::Some': Some<&str>(&str) -> Option<&str>
1336 122..139 'Option...e("x")': Option<&str>
1337 135..138 '"x"': &str
1338 145..149 'None': Option<{unknown}>
1339 159..160 'x': Option<i64>
1340 176..180 'None': Option<i64>
1346 fn infer_function_generics() {
1349 fn id<T>(t: T) -> T { t }
1361 37..97 '{ ...(1); }': ()
1362 43..45 'id': fn id<u32>(u32) -> u32
1363 43..51 'id(1u32)': u32
1365 57..67 'id::<i128>': fn id<i128>(i128) -> i128
1366 57..70 'id::<i128>(1)': i128
1369 89..91 'id': fn id<u64>(u64) -> u64
1377 fn infer_impl_generics_basic() {
1384 impl<Y, X> A<X, Y> {
1391 fn z<T>(self, t: T) -> (X, Y, T) {
1397 let a = A { x: 1u64, y: 1i64 };
1405 73..77 'self': A<X, Y>
1406 84..106 '{ ... }': X
1407 94..98 'self': A<X, Y>
1409 116..120 'self': A<X, Y>
1410 127..149 '{ ... }': Y
1411 137..141 'self': A<X, Y>
1412 137..143 'self.y': Y
1413 162..166 'self': A<X, Y>
1415 187..222 '{ ... }': (X, Y, T)
1416 197..216 '(self.....y, t)': (X, Y, T)
1417 198..202 'self': A<X, Y>
1418 198..204 'self.x': X
1419 206..210 'self': A<X, Y>
1420 206..212 'self.y': Y
1422 244..341 '{ ...(1); }': i128
1423 254..255 'a': A<u64, i64>
1424 258..280 'A { x:...1i64 }': A<u64, i64>
1425 265..269 '1u64': u64
1426 274..278 '1i64': i64
1427 286..287 'a': A<u64, i64>
1428 286..291 'a.x()': u64
1429 297..298 'a': A<u64, i64>
1430 297..302 'a.y()': i64
1431 308..309 'a': A<u64, i64>
1432 308..318 'a.z(1i128)': (u64, i64, i128)
1433 312..317 '1i128': i128
1434 324..325 'a': A<u64, i64>
1435 324..338 'a.z::<u128>(1)': (u64, i64, u128)
1442 fn infer_impl_generics_with_autoderef() {
1450 fn as_ref(&self) -> Option<&T> {}
1452 fn test(o: Option<u32>) {
1458 77..81 'self': &Option<T>
1459 97..99 '{}': Option<&T>
1460 110..111 'o': Option<u32>
1461 126..164 '{ ...f(); }': ()
1462 132..145 '(&o).as_ref()': Option<&u32>
1463 133..135 '&o': &Option<u32>
1464 134..135 'o': Option<u32>
1465 151..152 'o': Option<u32>
1466 151..161 'o.as_ref()': Option<&u32>
1472 fn infer_generic_chain() {
1483 fn id<T>(t: T) -> T { t }
1488 let a = A { x: id(y) };
1495 52..56 'self': A<T2>
1496 64..86 '{ ... }': T2
1497 74..78 'self': A<T2>
1502 134..254 '{ ....x() }': i128
1506 163..165 'id': fn id<i128>(i128) -> i128
1507 163..168 'id(x)': i128
1509 178..179 'a': A<i128>
1510 182..196 'A { x: id(y) }': A<i128>
1511 189..191 'id': fn id<i128>(i128) -> i128
1512 189..194 'id(y)': i128
1515 210..212 'id': fn id<i128>(i128) -> i128
1516 210..217 'id(a.x)': i128
1517 213..214 'a': A<i128>
1518 213..216 'a.x': i128
1519 227..228 'b': A<i128>
1520 231..241 'A { x: z }': A<i128>
1522 247..248 'b': A<i128>
1523 247..252 'b.x()': i128
1529 fn infer_associated_const() {
1550 impl Trait for TraitTest {
1555 let x = Struct::FOO;
1557 let z = TraitTest::ID;
1564 228..306 '{ ...:ID; }': ()
1566 242..253 'Struct::FOO': u32
1568 267..276 'Enum::BAR': u32
1570 290..303 'TraitTest::ID': u32
1576 fn infer_type_alias() {
1579 struct A<X, Y> { x: X, y: Y }
1580 type Foo = A<u32, i128>;
1581 type Bar<T> = A<T, u128>;
1582 type Baz<U, V> = A<V, U>;
1583 fn test(x: Foo, y: Bar<&str>, z: Baz<i8, u8>) {
1595 pub type Alias = Enum;
1598 let e = m::Alias::Foo(0);
1599 let m::Alias::Foo(x) = &e;
1603 115..116 'x': A<u32, i128>
1604 123..124 'y': A<&str, u128>
1605 137..138 'z': A<u8, i8>
1606 153..210 '{ ...z.y; }': ()
1607 159..160 'x': A<u32, i128>
1609 168..169 'x': A<u32, i128>
1610 168..171 'x.y': i128
1611 177..178 'y': A<&str, u128>
1612 177..180 'y.x': &str
1613 186..187 'y': A<&str, u128>
1614 186..189 'y.y': u128
1615 195..196 'z': A<u8, i8>
1617 204..205 'z': A<u8, i8>
1619 298..362 '{ ... &e; }': ()
1621 312..325 'm::Alias::Foo': Foo(u8) -> Enum
1622 312..328 'm::Ali...Foo(0)': Enum
1624 338..354 'm::Ali...Foo(x)': Enum
1626 357..359 '&e': &Enum
1633 fn recursive_type_alias() {
1642 58..59 'x': {unknown}
1649 fn infer_type_param() {
1652 fn id<T>(x: T) -> T {
1656 fn clone<T>(x: &T) -> T {
1663 let x: bool = clone(z);
1675 77..157 '{ ...(1); }': ()
1678 102..104 'id': fn id<u32>(u32) -> u32
1679 102..107 'id(y)': u32
1682 127..132 'clone': fn clone<bool>(&bool) -> bool
1683 127..135 'clone(z)': bool
1685 141..151 'id::<i128>': fn id<i128>(i128) -> i128
1686 141..154 'id::<i128>(1)': i128
1697 impl Foo { const ASSOC_CONST: u32 = 0; }
1698 const GLOBAL_CONST: u32 = 101;
1700 const LOCAL_CONST: u32 = 99;
1701 let x = LOCAL_CONST;
1702 let z = GLOBAL_CONST;
1703 let id = Foo::ASSOC_CONST;
1709 94..212 '{ ...NST; }': ()
1711 141..152 'LOCAL_CONST': u32
1713 166..178 'GLOBAL_CONST': u32
1715 193..209 'Foo::A..._CONST': u32
1725 static GLOBAL_STATIC: u32 = 101;
1726 static mut GLOBAL_STATIC_MUT: u32 = 101;
1728 static LOCAL_STATIC: u32 = 99;
1729 static mut LOCAL_STATIC_MUT: u32 = 99;
1730 let x = LOCAL_STATIC;
1731 let y = LOCAL_STATIC_MUT;
1732 let z = GLOBAL_STATIC;
1733 let w = GLOBAL_STATIC_MUT;
1739 84..279 '{ ...MUT; }': ()
1741 176..188 'LOCAL_STATIC': u32
1743 202..218 'LOCAL_...IC_MUT': u32
1745 232..245 'GLOBAL_STATIC': u32
1747 259..276 'GLOBAL...IC_MUT': u32
1755 fn shadowing_primitive() {
1761 impl i32 { fn foo(&self) -> Foo { Foo } }
1772 fn const_eval_array_repeat_expr() {
1776 const X: usize = 6 - 1;
1777 let t = [(); X + 2];
1784 fn shadowing_primitive_with_inner_items() {
1790 impl i32 { fn foo(&self) -> Foo { Foo } }
1802 fn not_shadowing_primitive_by_module() {
1810 fn foo() -> &'static str { "" }
1820 fn not_shadowing_module_by_primitive() {
1828 fn foo() -> &'static str { "" }
1837 // This test is actually testing the shadowing behavior within hir_def. It
1838 // lives here because the testing infrastructure in hir_def isn't currently
1839 // capable of asserting the necessary conditions.
1841 fn should_be_shadowing_imports() {
1845 pub fn foo() -> i8 {0}
1846 pub struct foo { a: i8 }
1848 mod b { pub fn foo () -> u8 {0} }
1849 mod c { pub struct foo { a: u8 } }
1851 pub use super::a::*;
1852 pub use super::c::foo;
1853 pub use super::b::foo;
1866 fn closure_return() {
1870 let x = || -> usize { return 1; };
1874 16..58 '{ ...; }; }': u32
1875 26..27 'x': || -> usize
1876 30..55 '|| -> ...n 1; }': || -> usize
1877 42..55 '{ return 1; }': usize
1878 44..52 'return 1': !
1885 fn closure_return_unit() {
1889 let x = || { return; };
1893 16..47 '{ ...; }; }': u32
1894 26..27 'x': || -> ()
1895 30..44 '|| { return; }': || -> ()
1896 33..44 '{ return; }': ()
1903 fn closure_return_inferred() {
1907 let x = || { "test" };
1911 16..46 '{ ..." }; }': u32
1912 26..27 'x': || -> &str
1913 30..43 '|| { "test" }': || -> &str
1914 33..43 '{ "test" }': &str
1915 35..41 '"test"': &str
1921 fn fn_pointer_return() {
1929 let vtable = Vtable { method: || {} };
1930 let m = vtable.method;
1934 47..120 '{ ...hod; }': ()
1935 57..63 'vtable': Vtable
1936 66..90 'Vtable...| {} }': Vtable
1937 83..88 '|| {}': || -> ()
1940 104..110 'vtable': Vtable
1941 104..117 'vtable.method': fn()
1947 fn block_modifiers_smoke_test() {
1950 //- minicore: future
1952 let x = unsafe { 92 };
1953 let y = async { async { () }.await };
1955 let w = const { 92 };
1960 16..162 '{ ...2 }; }': ()
1962 30..43 'unsafe { 92 }': i32
1963 30..43 'unsafe { 92 }': i32
1965 53..54 'y': impl Future<Output = ()>
1966 57..85 'async ...wait }': ()
1967 57..85 'async ...wait }': impl Future<Output = ()>
1968 65..77 'async { () }': ()
1969 65..77 'async { () }': impl Future<Output = ()>
1970 65..83 'async ....await': ()
1972 95..96 'z': {unknown}
1973 99..109 'try { () }': ()
1974 99..109 'try { () }': {unknown}
1977 123..135 'const { 92 }': i32
1978 123..135 'const { 92 }': i32
1981 149..159 ''a: { 92 }': i32
1987 fn async_block_early_return() {
1990 //- minicore: future, result, fn
1991 fn test<I, E, F: FnMut() -> Fut, Fut: core::future::Future<Output = Result<I, E>>>(f: F) {}
2007 103..231 '{ ... }); }': ()
2008 109..161 'async ... }': Result<(), ()>
2009 109..161 'async ... }': impl Future<Output = Result<(), ()>>
2010 125..139 'return Err(())': !
2011 132..135 'Err': Err<(), ()>(()) -> Result<(), ()>
2012 132..139 'Err(())': Result<(), ()>
2014 149..151 'Ok': Ok<(), ()>(()) -> Result<(), ()>
2015 149..155 'Ok(())': Result<(), ()>
2017 167..171 'test': fn test<(), (), || -> impl Future<Output = Result<(), ()>>, impl Future<Output = Result<(), ()>>>(|| -> impl Future<Output = Result<(), ()>>)
2018 167..228 'test(|... })': ()
2019 172..227 '|| asy... }': || -> impl Future<Output = Result<(), ()>>
2020 175..227 'async ... }': Result<(), ()>
2021 175..227 'async ... }': impl Future<Output = Result<(), ()>>
2022 191..205 'return Err(())': !
2023 198..201 'Err': Err<(), ()>(()) -> Result<(), ()>
2024 198..205 'Err(())': Result<(), ()>
2026 215..217 'Ok': Ok<(), ()>(()) -> Result<(), ()>
2027 215..221 'Ok(())': Result<(), ()>
2034 fn infer_generic_from_later_assignment() {
2037 enum Option<T> { Some(T), None }
2048 59..129 '{ ... } }': ()
2049 69..76 'mut end': Option<bool>
2050 79..83 'None': Option<bool>
2051 89..127 'loop {... }': !
2052 94..127 '{ ... }': ()
2053 104..107 'end': Option<bool>
2054 104..120 'end = ...(true)': ()
2055 110..114 'Some': Some<bool>(bool) -> Option<bool>
2056 110..120 'Some(true)': Option<bool>
2057 115..119 'true': bool
2063 fn infer_loop_break_with_val() {
2066 enum Option<T> { Some(T), None }
2080 59..168 '{ ... }; }': ()
2081 69..70 'x': Option<bool>
2082 73..165 'loop {... }': Option<bool>
2083 78..165 '{ ... }': ()
2084 88..132 'if fal... }': ()
2085 91..96 'false': bool
2086 97..132 '{ ... }': ()
2087 111..121 'break None': !
2088 117..121 'None': Option<bool>
2089 142..158 'break ...(true)': !
2090 148..152 'Some': Some<bool>(bool) -> Option<bool>
2091 148..158 'Some(true)': Option<bool>
2092 153..157 'true': bool
2098 fn infer_loop_break_without_val() {
2101 enum Option<T> { Some(T), None }
2113 59..136 '{ ... }; }': ()
2115 73..133 'loop {... }': ()
2116 78..133 '{ ... }': ()
2117 88..127 'if fal... }': ()
2118 91..96 'false': bool
2119 97..127 '{ ... }': ()
2126 fn infer_labelled_break_with_val() {
2130 let _x = || 'outer: loop {
2131 let inner = 'inner: loop {
2132 let i = Default::default();
2133 if (break 'outer i) {
2134 loop { break 'inner 5i8; };
2145 9..335 '{ ... }; }': ()
2146 19..21 '_x': || -> bool
2147 24..332 '|| 'ou... }': || -> bool
2148 27..332 ''outer... }': bool
2149 40..332 '{ ... }': ()
2151 62..300 ''inner... }': i8
2152 75..300 '{ ... }': ()
2154 97..113 'Defaul...efault': {unknown}
2155 97..115 'Defaul...ault()': bool
2156 129..269 'if (br... }': ()
2157 133..147 'break 'outer i': !
2159 149..208 '{ ... }': ()
2160 167..193 'loop {...5i8; }': !
2161 172..193 '{ brea...5i8; }': ()
2162 174..190 'break ...er 5i8': !
2164 214..269 'if tru... }': ()
2165 217..221 'true': bool
2166 222..269 '{ ... }': ()
2167 240..254 'break 'inner 6': !
2169 282..289 'break 7': !
2171 310..325 'break inner < 8': !
2172 316..321 'inner': i8
2173 316..325 'inner < 8': bool
2180 fn infer_labelled_block_break_with_val() {
2183 fn default<T>() -> T { loop {} }
2186 let inner = 'inner: {
2188 if (break 'outer i) {
2193 break 'inner 'innermost: { 0 };
2196 break 'outer inner < 8;
2201 21..32 '{ loop {} }': T
2204 42..381 '{ ... }; }': ()
2206 57..378 ''outer... }': bool
2208 87..339 ''inner... }': i8
2210 117..124 'default': fn default<bool>() -> bool
2211 117..126 'default()': bool
2212 140..270 'if (br... }': ()
2213 144..158 'break 'outer i': !
2215 160..209 '{ ... }': ()
2216 178..194 'break ...er 5i8': !
2218 215..270 'if tru... }': ()
2219 218..222 'true': bool
2220 223..270 '{ ... }': ()
2221 241..255 'break 'inner 6': !
2223 283..313 'break ... { 0 }': !
2224 296..313 ''inner... { 0 }': i8
2227 349..371 'break ...er < 8': !
2228 362..367 'inner': i8
2229 362..371 'inner < 8': bool
2236 fn generic_default() {
2239 struct Thing<T = ()> { t: T }
2240 enum OtherThing<T = ()> {
2245 fn test(t1: Thing, t2: OtherThing, t3: Thing<i32>, t4: OtherThing<i32>) {
2249 OtherThing::One { t } => { t; },
2250 OtherThing::Two(t) => { t; },
2253 OtherThing::One { t } => { t; },
2254 OtherThing::Two(t) => { t; },
2259 97..99 't1': Thing<()>
2260 108..110 't2': OtherThing<()>
2261 124..126 't3': Thing<i32>
2262 140..142 't4': OtherThing<i32>
2263 161..384 '{ ... } }': ()
2264 167..169 't1': Thing<()>
2266 177..179 't3': Thing<i32>
2267 177..181 't3.t': i32
2268 187..282 'match ... }': ()
2269 193..195 't2': OtherThing<()>
2270 206..227 'OtherT... { t }': OtherThing<()>
2272 231..237 '{ t; }': ()
2274 247..265 'OtherT...Two(t)': OtherThing<()>
2276 269..275 '{ t; }': ()
2278 287..382 'match ... }': ()
2279 293..295 't4': OtherThing<i32>
2280 306..327 'OtherT... { t }': OtherThing<i32>
2282 331..337 '{ t; }': ()
2284 347..365 'OtherT...Two(t)': OtherThing<i32>
2286 369..375 '{ t; }': ()
2293 fn generic_default_in_struct_literal() {
2296 struct Thing<T = ()> { t: T }
2297 enum OtherThing<T = ()> {
2303 let x = Thing { t: loop {} };
2304 let y = Thing { t: () };
2305 let z = Thing { t: 1i32 };
2306 if let Thing { t } = z {
2310 let a = OtherThing::One { t: 1i32 };
2311 let b = OtherThing::Two(1i32);
2315 99..319 '{ ...32); }': ()
2316 109..110 'x': Thing<!>
2317 113..133 'Thing ...p {} }': Thing<!>
2318 124..131 'loop {}': !
2320 143..144 'y': Thing<()>
2321 147..162 'Thing { t: () }': Thing<()>
2323 172..173 'z': Thing<i32>
2324 176..193 'Thing ...1i32 }': Thing<i32>
2325 187..191 '1i32': i32
2326 199..240 'if let... }': ()
2327 202..221 'let Th... } = z': bool
2328 206..217 'Thing { t }': Thing<i32>
2330 220..221 'z': Thing<i32>
2331 222..240 '{ ... }': ()
2333 250..251 'a': OtherThing<i32>
2334 254..281 'OtherT...1i32 }': OtherThing<i32>
2335 275..279 '1i32': i32
2336 291..292 'b': OtherThing<i32>
2337 295..310 'OtherThing::Two': Two<i32>(i32) -> OtherThing<i32>
2338 295..316 'OtherT...(1i32)': OtherThing<i32>
2339 311..315 '1i32': i32
2345 fn generic_default_depending_on_other_type_arg() {
2346 // FIXME: the {unknown} is a bug
2349 struct Thing<T = u128, F = fn() -> T> { t: T }
2351 fn test(t1: Thing<u32>, t2: Thing) {
2354 Thing::<_> { t: 1u32 };
2358 56..58 't1': Thing<u32, fn() -> u32>
2359 72..74 't2': Thing<u128, fn() -> u128>
2360 83..130 '{ ...2 }; }': ()
2361 89..91 't1': Thing<u32, fn() -> u32>
2362 97..99 't2': Thing<u128, fn() -> u128>
2363 105..127 'Thing:...1u32 }': Thing<u32, fn() -> {unknown}>
2364 121..125 '1u32': u32
2370 fn generic_default_depending_on_other_type_arg_forward() {
2371 // the {unknown} here is intentional, as defaults are not allowed to
2372 // refer to type parameters coming later
2375 struct Thing<F = fn() -> T, T = u128> { t: T }
2377 fn test(t1: Thing) {
2382 56..58 't1': Thing<fn() -> {unknown}, u128>
2383 67..78 '{ t1; }': ()
2384 73..75 't1': Thing<fn() -> {unknown}, u128>
2390 fn infer_operator_overload() {
2394 struct V2([f32; 2]);
2396 impl core::ops::Add<V2> for V2 {
2401 let va = V2([0.0, 1.0]);
2402 let vb = V2([0.0, 1.0]);
2413 fn infer_const_params() {
2416 fn foo<const FOO: usize>() {
2421 27..49 '{ ...FOO; }': ()
2429 fn infer_inner_type() {
2433 struct S { field: u32 }
2434 let s = S { field: 0 };
2439 9..89 '{ ...eld; }': ()
2441 51..65 'S { field: 0 }': S
2445 79..86 's.field': u32
2451 fn infer_nested_inner_type() {
2456 let s = S { field: 0 };
2459 struct S { field: u32 }
2463 9..109 '{ ...32 } }': ()
2464 15..79 '{ ... }': ()
2466 33..47 'S { field: 0 }': S
2470 65..72 's.field': u32
2476 fn inner_use_enum_rename() {
2493 34..123 '{ ... } }': ()
2495 71..78 'R::Info': Request
2496 84..121 'match ... }': ()
2498 102..109 'R::Info': Request
2512 pub trait Unsize<T: ?Sized> {}
2514 #[lang = "coerce_unsized"]
2515 pub trait CoerceUnsized<T> {}
2517 pub unsafe trait Allocator {}
2520 unsafe impl Allocator for Global {}
2522 #[lang = "owned_box"]
2524 pub struct Box<T: ?Sized, A: Allocator = Global>;
2526 impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<Box<U, A>> for Box<T, A> {}
2528 pub struct Vec<T, A: Allocator = Global> {}
2533 #[lang = "slice_alloc"]
2535 pub fn into_vec<A: Allocator>(self: Box<Self, A>) -> Vec<T, A> {
2541 let vec = <[_]>::into_vec(box [1i32]);
2542 let v: Vec<Box<dyn B>> = <[_]> :: into_vec(box [box Astruct]);
2547 impl B for Astruct {}
2550 569..573 'self': Box<[T], A>
2551 602..634 '{ ... }': Vec<T, A>
2552 612..628 'unimpl...ted!()': Vec<T, A>
2553 648..761 '{ ...t]); }': ()
2554 658..661 'vec': Vec<i32, Global>
2555 664..679 '<[_]>::into_vec': fn into_vec<i32, Global>(Box<[i32], Global>) -> Vec<i32, Global>
2556 664..691 '<[_]>:...1i32])': Vec<i32, Global>
2557 680..690 'box [1i32]': Box<[i32; 1], Global>
2558 684..690 '[1i32]': [i32; 1]
2559 685..689 '1i32': i32
2560 701..702 'v': Vec<Box<dyn B, Global>, Global>
2561 722..739 '<[_]> ...to_vec': fn into_vec<Box<dyn B, Global>, Global>(Box<[Box<dyn B, Global>], Global>) -> Vec<Box<dyn B, Global>, Global>
2562 722..758 '<[_]> ...ruct])': Vec<Box<dyn B, Global>, Global>
2563 740..757 'box [b...truct]': Box<[Box<dyn B, Global>; 1], Global>
2564 744..757 '[box Astruct]': [Box<dyn B, Global>; 1]
2565 745..756 'box Astruct': Box<Astruct, Global>
2566 749..756 'Astruct': Astruct
2572 fn cfgd_out_assoc_items() {
2591 fn infer_missing_type() {
2605 fn infer_type_alias_variant() {
2616 Qux::Bar(bar) => (),
2617 Qux::Baz { baz } => (),
2622 72..166 '{ ... } }': ()
2623 78..164 'match ... }': ()
2624 84..92 'Foo::Bar': Bar(i32) -> Foo
2625 84..95 'Foo::Bar(3)': Foo
2627 106..119 'Qux::Bar(bar)': Foo
2630 135..151 'Qux::B... baz }': Foo
2638 fn infer_boxed_self_receiver() {
2642 use core::ops::Deref;
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 104..108 'self': &Box<T>
2675 188..192 'self': &Box<Foo<T>>
2677 242..246 'self': &Box<Foo<T>>
2678 275..277 '{}': &Foo<T>
2679 297..301 'self': Box<Foo<T>>
2680 322..324 '{}': Foo<T>
2681 338..559 '{ ...r(); }': ()
2682 348..353 'boxed': Box<Foo<i32>>
2683 356..359 'Box': Box<Foo<i32>>(Foo<i32>) -> Box<Foo<i32>>
2684 356..371 'Box(Foo(0_i32))': Box<Foo<i32>>
2685 360..363 'Foo': Foo<i32>(i32) -> Foo<i32>
2686 360..370 'Foo(0_i32)': Foo<i32>
2687 364..369 '0_i32': i32
2688 382..386 'bad1': &i32
2689 389..394 'boxed': Box<Foo<i32>>
2690 389..406 'boxed....nner()': &i32
2691 416..421 'good1': &i32
2692 424..438 'Foo::get_inner': fn get_inner<i32>(&Box<Foo<i32>>) -> &i32
2693 424..446 'Foo::g...boxed)': &i32
2694 439..445 '&boxed': &Box<Foo<i32>>
2695 440..445 'boxed': Box<Foo<i32>>
2696 457..461 'bad2': &Foo<i32>
2697 464..469 'boxed': Box<Foo<i32>>
2698 464..480 'boxed....self()': &Foo<i32>
2699 490..495 'good2': &Foo<i32>
2700 498..511 'Foo::get_self': fn get_self<i32>(&Box<Foo<i32>>) -> &Foo<i32>
2701 498..519 'Foo::g...boxed)': &Foo<i32>
2702 512..518 '&boxed': &Box<Foo<i32>>
2703 513..518 'boxed': Box<Foo<i32>>
2704 530..535 'inner': Foo<i32>
2705 538..543 'boxed': Box<Foo<i32>>
2706 538..556 'boxed....nner()': Foo<i32>
2715 //- /main.rs edition:2015 crate:main deps:core
2721 //- /core.rs crate:core
2732 fn legacy_const_generics() {
2733 check_no_mismatches(
2735 #[rustc_legacy_const_generics(1, 3)]
2736 fn mixed<const N1: &'static str, const N2: bool>(
2742 mixed(0, "", -1, true);
2743 mixed::<"", true>(0, -1);
2750 fn nested_tuple_index() {
2751 check_no_mismatches(
2754 let fld: i32 = ((0,),).0.0;