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; _]>)
17 #[prelude_import] use prelude::*;
22 pub struct Box<T: ?Sized> {
34 enum Nat { Succ(Self), Demo(Nat), Zero }
37 let foo: Nat = Nat::Zero;
38 if let Nat::Succ(x) = foo {
47 fn self_in_struct_lit() {
61 59..72 'Self { x: 1 }': S<u32>
68 fn type_alias_in_struct_lit() {
81 50..70 '{ ...1 }; }': ()
82 56..67 'SS { x: 1 }': S<u32>
92 //- /main.rs crate:main deps:core
101 let t = (a, b, c, d, e, f);
103 } //^ (RangeFull, RangeFrom<i32>, RangeTo<u32>, Range<usize>, RangeToInclusive<i32>, RangeInclusive<char>)
105 //- /core.rs crate:core
106 #[prelude_import] use prelude::*;
110 pub struct Range<Idx> {
114 pub struct RangeFrom<Idx> {
118 pub struct RangeInclusive<Idx> {
123 pub struct RangeTo<Idx> {
126 pub struct RangeToInclusive<Idx> {
135 fn infer_while_let() {
138 enum Option<T> { Some(T), None }
141 let foo: Option<f32> = None;
142 while let Option::Some(x) = foo {
154 fn test(a: u32, b: isize, c: !, d: &str) {
169 41..120 '{ ...f32; }': ()
174 75..81 '1usize': usize
175 87..93 '1isize': isize
176 99..105 '"test"': &str
177 111..117 '1.0f32': f32
196 10..117 '{ ...= e; }': ()
198 24..30 '1isize': isize
231 66..90 '{ ...c(); }': ()
232 72..73 'a': fn a() -> u32
234 81..85 'b::c': fn c() -> u32
241 fn infer_path_type() {
247 fn foo() -> i32 { 1 }
258 59..92 '{ ...o(); }': ()
259 65..71 'S::foo': fn foo() -> i32
260 65..73 'S::foo()': i32
261 79..87 '<S>::foo': fn foo() -> i32
262 79..89 '<S>::foo()': i32
281 let a: A = A { b: B, c: C(1) };
287 71..153 '{ ...a.c; }': ()
289 85..86 'C': C(usize) -> C
294 113..132 'A { b:...C(1) }': A
296 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() {
470 10..216 '{ ...o"#; }': ()
474 46..53 '"hello"': &str
475 59..67 'b"bytes"': &[u8; _]
480 112..117 'false': bool
481 123..127 'true': bool
482 133..197 'r#" ... "#': &str
483 203..213 'br#"yolo"#': &[u8; _]
489 fn infer_unary_op() {
494 fn test(x: SomeType) {
514 39..271 '{ ...lo"; }': ()
529 145..152 '!!!true': bool
530 146..152 '!!true': bool
531 147..152 '!true': bool
532 148..152 'true': bool
537 183..189 '!10u32': u32
538 184..189 '10u32': u32
542 211..216 '-3.14': f64
546 230..232 '-x': {unknown}
547 231..232 'x': SomeType
548 238..240 '!x': {unknown}
549 239..240 'x': SomeType
550 246..254 '-"hello"': {unknown}
551 247..254 '"hello"': &str
552 260..268 '!"hello"': {unknown}
553 261..268 '"hello"': &str
559 fn infer_backwards() {
562 fn takes_u32(x: u32) {}
564 struct S { i32_field: i32 }
566 fn test() -> &mut &f64 {
567 let a = unknown_function();
569 let b = unknown_function();
571 let c = unknown_function();
578 77..230 '{ ...t &c }': &mut &f64
580 91..107 'unknow...nction': {unknown}
581 91..109 'unknow...tion()': u32
582 115..124 'takes_u32': fn takes_u32(u32)
583 115..127 'takes_u32(a)': ()
586 141..157 'unknow...nction': {unknown}
587 141..159 'unknow...tion()': i32
588 165..183 'S { i3...d: b }': S
591 197..213 'unknow...nction': {unknown}
592 197..215 'unknow...tion()': f64
593 221..228 '&mut &c': &mut &f64
610 fn test2(self: &Self) {
626 87..108 '{ ... }': ()
628 132..152 '{ ... }': S
630 176..199 '{ ... }': S
631 186..193 'Self {}': S
637 fn infer_self_as_path() {
665 86..107 '{ ... }': ()
667 134..158 '{ ... }': ()
668 144..148 'Self': S2(isize) -> S2
669 144..151 'Self(1)': S2
671 184..230 '{ ... }': ()
672 194..202 'Self::V1': E
673 212..220 'Self::V2': V2(u32) -> E
674 212..223 'Self::V2(1)': E
681 fn infer_binary_op() {
684 fn f(x: bool) -> i32 {
690 let y = true || false;
693 let minus_forty: isize = -40isize;
694 let h = minus_forty <= CONST_2;
695 let c = f(z || y) + 5;
697 let g = minus_forty ^= i;
699 let ten_is_eleven = ten == some_num;
706 21..33 '{ 0i32 }': i32
708 53..369 '{ ... < 3 }': bool
711 67..73 'a && b': bool
715 87..100 'true || false': bool
716 95..100 'false': bool
719 114..120 'x == y': bool
723 134..140 'x != y': bool
725 150..161 'minus_forty': isize
726 171..179 '-40isize': isize
727 172..179 '40isize': isize
729 193..204 'minus_forty': isize
730 193..215 'minus_...ONST_2': bool
731 208..215 'CONST_2': isize
733 229..230 'f': fn f(bool) -> i32
734 229..238 'f(z || y)': i32
735 229..242 'f(z || y) + 5': i32
737 231..237 'z || y': bool
740 252..253 'd': {unknown}
741 256..257 'b': {unknown}
743 271..282 'minus_forty': isize
744 271..287 'minus_...y ^= i': ()
746 297..300 'ten': usize
748 322..335 'ten_is_eleven': bool
749 338..341 'ten': usize
750 338..353 'ten == some_num': bool
751 345..353 'some_num': usize
752 360..363 'ten': usize
753 360..367 'ten < 3': bool
760 fn infer_shift_op() {
769 10..47 '{ ...5u8; }': ()
771 16..27 '1u32 << 5u8': u32
774 33..44 '1u32 >> 5u8': u32
781 fn infer_field_autoderef() {
798 let a5 = &mut &&mut &&mut a;
802 fn test2(a1: *const A, a2: *mut A) {
809 49..212 '{ ...5.b; }': ()
819 112..114 'a3': &mut A
820 117..123 '&mut a': &mut A
822 129..131 'a3': &mut A
824 143..145 'a4': &&&&&&&A
825 148..156 '&&&&&&&a': &&&&&&&A
826 149..156 '&&&&&&a': &&&&&&A
827 150..156 '&&&&&a': &&&&&A
828 151..156 '&&&&a': &&&&A
829 152..156 '&&&a': &&&A
833 162..164 'a4': &&&&&&&A
835 176..178 'a5': &mut &&mut &&mut A
836 181..199 '&mut &...&mut a': &mut &&mut &&mut A
837 186..199 '&&mut &&mut a': &&mut &&mut A
838 187..199 '&mut &&mut a': &mut &&mut A
839 192..199 '&&mut a': &&mut A
840 193..199 '&mut a': &mut A
842 205..207 'a5': &mut &&mut &&mut A
844 223..225 'a1': *const A
845 237..239 'a2': *mut A
846 249..272 '{ ...2.b; }': ()
847 255..257 'a1': *const A
849 265..267 'a2': *mut A
856 fn infer_argument_autoderef() {
862 fn deref(&self) -> &Self::Target;
868 fn foo(&self) -> &T {
875 impl<T> Deref for B<T> {
877 fn deref(&self) -> &Self::Target {
883 let t = A::foo(&&B(B(A(42))));
888 138..142 'self': &A<T>
889 150..173 '{ ... }': &T
890 160..167 '&self.0': &T
891 161..165 'self': &A<T>
893 254..258 'self': &B<T>
894 277..300 '{ ... }': &T
895 287..294 '&self.0': &T
896 288..292 'self': &B<T>
898 314..352 '{ ...))); }': ()
900 328..334 'A::foo': fn foo<i32>(&A<i32>) -> &i32
901 328..349 'A::foo...42))))': &i32
902 335..348 '&&B(B(A(42)))': &&B<B<A<i32>>>
903 336..348 '&B(B(A(42)))': &B<B<A<i32>>>
904 337..338 'B': B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>>
905 337..348 'B(B(A(42)))': B<B<A<i32>>>
906 339..340 'B': B<A<i32>>(A<i32>) -> B<A<i32>>
907 339..347 'B(A(42))': B<A<i32>>
908 341..342 'A': A<i32>(i32) -> A<i32>
909 341..346 'A(42)': A<i32>
916 fn infer_method_argument_autoderef() {
922 fn deref(&self) -> &Self::Target;
928 fn foo(&self, x: &A<T>) -> &T {
935 impl<T> Deref for B<T> {
937 fn deref(&self) -> &Self::Target {
943 let t = A(0 as *mut _).foo(&&B(B(a)));
948 143..147 'self': &A<T>
950 165..186 '{ ... }': &T
954 177..180 'x.0': *mut T
955 267..271 'self': &B<T>
956 290..313 '{ ... }': &T
957 300..307 '&self.0': &T
958 301..305 'self': &B<T>
961 336..382 '{ ...))); }': ()
963 350..351 'A': A<i32>(*mut i32) -> A<i32>
964 350..364 'A(0 as *mut _)': A<i32>
965 350..379 'A(0 as...B(a)))': &i32
967 352..363 '0 as *mut _': *mut i32
968 369..378 '&&B(B(a))': &&B<B<A<i32>>>
969 370..378 '&B(B(a))': &B<B<A<i32>>>
970 371..372 'B': B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>>
971 371..378 'B(B(a))': B<B<A<i32>>>
972 373..374 'B': B<A<i32>>(A<i32>) -> B<A<i32>>
973 373..377 'B(a)': B<A<i32>>
980 fn infer_in_elseif() {
983 struct Foo { field: i32 }
994 44..108 '{ ... } }': ()
995 50..106 'if tru... }': ()
998 72..106 'if fal... }': i32
1000 81..106 '{ ... }': i32
1002 91..100 'foo.field': i32
1008 fn infer_if_match_with_return() {
1022 let _x3 = match true {
1028 let _x4 = match true {
1034 9..322 '{ ... }; }': ()
1036 25..79 'if tru... }': i32
1038 33..50 '{ ... }': i32
1040 56..79 '{ ... }': i32
1043 95..148 'if tru... }': i32
1044 98..102 'true': bool
1045 103..120 '{ ... }': i32
1047 126..148 '{ ... }': !
1048 136..142 'return': !
1050 164..246 'match ... }': i32
1051 170..174 'true': bool
1052 185..189 'true': bool
1053 185..189 'true': bool
1056 209..240 '{ ... }': i32
1057 223..229 'return': !
1059 262..319 'match ... }': i32
1060 268..272 'true': bool
1061 283..287 'true': bool
1062 283..287 'true': bool
1065 307..313 'return': !
1071 fn infer_inherent_method() {
1077 fn foo(self, x: u32) -> i32 {}
1082 fn bar(&self, x: u64) -> i64 {}
1100 149..197 '{ ...(1); }': ()
1102 155..163 'a.foo(1)': i32
1104 169..180 '(&a).bar(1)': i64
1109 186..194 'a.bar(1)': i64
1116 fn infer_inherent_method_str() {
1121 fn foo(&self) -> i32 {}
1131 68..88 '{ ...o(); }': ()
1132 74..79 '"foo"': &str
1133 74..85 '"foo".foo()': i32
1142 fn test(x: &str, y: isize) {
1143 let a: (u32, &str) = (1, "a");
1154 27..169 '{ ...d"); }': ()
1155 37..38 'a': (u32, &str)
1156 54..62 '(1, "a")': (u32, &str)
1159 72..73 'b': ((u32, &str), &str)
1160 76..82 '(a, x)': ((u32, &str), &str)
1161 77..78 'a': (u32, &str)
1163 92..93 'c': (isize, &str)
1164 96..102 '(y, x)': (isize, &str)
1167 112..113 'd': ((isize, &str), &str)
1168 116..122 '(c, x)': ((isize, &str), &str)
1169 117..118 'c': (isize, &str)
1171 132..133 'e': (i32, &str)
1172 136..144 '(1, "e")': (i32, &str)
1174 140..143 '"e"': &str
1175 154..155 'f': ((i32, &str), &str)
1176 158..166 '(e, "d")': ((i32, &str), &str)
1177 159..160 'e': (i32, &str)
1178 162..165 '"d"': &str
1187 fn test(x: &str, y: isize) {
1192 let d = [y, 1, 2, 3];
1193 let d = [1, y, 2, 3];
1202 let x: [u8; 0] = [];
1208 27..292 '{ ... []; }': ()
1209 37..38 'a': [&str; _]
1210 41..44 '[x]': [&str; _]
1212 54..55 'b': [[&str; _]; _]
1213 58..64 '[a, a]': [[&str; _]; _]
1214 59..60 'a': [&str; _]
1215 62..63 'a': [&str; _]
1216 74..75 'c': [[[&str; _]; _]; _]
1217 78..84 '[b, b]': [[[&str; _]; _]; _]
1218 79..80 'b': [[&str; _]; _]
1219 82..83 'b': [[&str; _]; _]
1220 95..96 'd': [isize; _]
1221 99..111 '[y, 1, 2, 3]': [isize; _]
1226 121..122 'd': [isize; _]
1227 125..137 '[1, y, 2, 3]': [isize; _]
1232 147..148 'e': [isize; _]
1233 151..154 '[y]': [isize; _]
1235 164..165 'f': [[isize; _]; _]
1236 168..174 '[d, d]': [[isize; _]; _]
1237 169..170 'd': [isize; _]
1238 172..173 'd': [isize; _]
1239 184..185 'g': [[isize; _]; _]
1240 188..194 '[e, e]': [[isize; _]; _]
1241 189..190 'e': [isize; _]
1242 192..193 'e': [isize; _]
1243 205..206 'h': [i32; _]
1244 209..215 '[1, 2]': [i32; _]
1247 225..226 'i': [&str; _]
1248 229..239 '["a", "b"]': [&str; _]
1249 230..233 '"a"': &str
1250 235..238 '"b"': &str
1251 250..251 'b': [[&str; _]; _]
1252 254..264 '[a, ["b"]]': [[&str; _]; _]
1253 255..256 'a': [&str; _]
1254 258..263 '["b"]': [&str; _]
1255 259..262 '"b"': &str
1256 274..275 'x': [u8; _]
1257 287..289 '[]': [u8; _]
1263 fn infer_struct_generics() {
1270 fn test(a1: A<u32>, i: i32) {
1272 let a2 = A { x: i };
1274 let a3 = A::<i128> { x: 1 };
1281 55..146 '{ ...3.x; }': ()
1285 80..90 'A { x: i }': A<i32>
1289 110..112 'a3': A<i128>
1290 115..133 'A::<i1...x: 1 }': A<i128>
1292 139..141 'a3': A<i128>
1293 139..143 'a3.x': i128
1299 fn infer_tuple_struct_generics() {
1303 enum Option<T> { Some(T), None }
1312 let x: Option<i64> = None;
1316 75..183 '{ ...one; }': ()
1317 81..82 'A': A<i32>(i32) -> A<i32>
1318 81..86 'A(42)': A<i32>
1320 92..93 'A': A<u128>(u128) -> A<u128>
1321 92..101 'A(42u128)': A<u128>
1322 94..100 '42u128': u128
1323 107..111 'Some': Some<&str>(&str) -> Option<&str>
1324 107..116 'Some("x")': Option<&str>
1325 112..115 '"x"': &str
1326 122..134 'Option::Some': Some<&str>(&str) -> Option<&str>
1327 122..139 'Option...e("x")': Option<&str>
1328 135..138 '"x"': &str
1329 145..149 'None': Option<{unknown}>
1330 159..160 'x': Option<i64>
1331 176..180 'None': Option<i64>
1337 fn infer_function_generics() {
1340 fn id<T>(t: T) -> T { t }
1352 37..97 '{ ...(1); }': ()
1353 43..45 'id': fn id<u32>(u32) -> u32
1354 43..51 'id(1u32)': u32
1356 57..67 'id::<i128>': fn id<i128>(i128) -> i128
1357 57..70 'id::<i128>(1)': i128
1360 89..91 'id': fn id<u64>(u64) -> u64
1368 fn infer_impl_generics_basic() {
1375 impl<Y, X> A<X, Y> {
1382 fn z<T>(self, t: T) -> (X, Y, T) {
1388 let a = A { x: 1u64, y: 1i64 };
1396 73..77 'self': A<X, Y>
1397 84..106 '{ ... }': X
1398 94..98 'self': A<X, Y>
1400 116..120 'self': A<X, Y>
1401 127..149 '{ ... }': Y
1402 137..141 'self': A<X, Y>
1403 137..143 'self.y': Y
1404 162..166 'self': A<X, Y>
1406 187..222 '{ ... }': (X, Y, T)
1407 197..216 '(self.....y, t)': (X, Y, T)
1408 198..202 'self': A<X, Y>
1409 198..204 'self.x': X
1410 206..210 'self': A<X, Y>
1411 206..212 'self.y': Y
1413 244..341 '{ ...(1); }': ()
1414 254..255 'a': A<u64, i64>
1415 258..280 'A { x:...1i64 }': A<u64, i64>
1416 265..269 '1u64': u64
1417 274..278 '1i64': i64
1418 286..287 'a': A<u64, i64>
1419 286..291 'a.x()': u64
1420 297..298 'a': A<u64, i64>
1421 297..302 'a.y()': i64
1422 308..309 'a': A<u64, i64>
1423 308..318 'a.z(1i128)': (u64, i64, i128)
1424 312..317 '1i128': i128
1425 324..325 'a': A<u64, i64>
1426 324..338 'a.z::<u128>(1)': (u64, i64, u128)
1433 fn infer_impl_generics_with_autoderef() {
1441 fn as_ref(&self) -> Option<&T> {}
1443 fn test(o: Option<u32>) {
1449 77..81 'self': &Option<T>
1451 110..111 'o': Option<u32>
1452 126..164 '{ ...f(); }': ()
1453 132..145 '(&o).as_ref()': Option<&u32>
1454 133..135 '&o': &Option<u32>
1455 134..135 'o': Option<u32>
1456 151..152 'o': Option<u32>
1457 151..161 'o.as_ref()': Option<&u32>
1463 fn infer_generic_chain() {
1474 fn id<T>(t: T) -> T { t }
1479 let a = A { x: id(y) };
1486 52..56 'self': A<T2>
1487 64..86 '{ ... }': T2
1488 74..78 'self': A<T2>
1493 134..254 '{ ....x() }': i128
1497 163..165 'id': fn id<i128>(i128) -> i128
1498 163..168 'id(x)': i128
1500 178..179 'a': A<i128>
1501 182..196 'A { x: id(y) }': A<i128>
1502 189..191 'id': fn id<i128>(i128) -> i128
1503 189..194 'id(y)': i128
1506 210..212 'id': fn id<i128>(i128) -> i128
1507 210..217 'id(a.x)': i128
1508 213..214 'a': A<i128>
1509 213..216 'a.x': i128
1510 227..228 'b': A<i128>
1511 231..241 'A { x: z }': A<i128>
1513 247..248 'b': A<i128>
1514 247..252 'b.x()': i128
1520 fn infer_associated_const() {
1541 impl Trait for TraitTest {
1546 let x = Struct::FOO;
1548 let z = TraitTest::ID;
1555 228..306 '{ ...:ID; }': ()
1557 242..253 'Struct::FOO': u32
1559 267..276 'Enum::BAR': u32
1561 290..303 'TraitTest::ID': u32
1567 fn infer_type_alias() {
1570 struct A<X, Y> { x: X, y: Y }
1571 type Foo = A<u32, i128>;
1572 type Bar<T> = A<T, u128>;
1573 type Baz<U, V> = A<V, U>;
1574 fn test(x: Foo, y: Bar<&str>, z: Baz<i8, u8>) {
1584 115..116 'x': A<u32, i128>
1585 123..124 'y': A<&str, u128>
1586 137..138 'z': A<u8, i8>
1587 153..210 '{ ...z.y; }': ()
1588 159..160 'x': A<u32, i128>
1590 168..169 'x': A<u32, i128>
1591 168..171 'x.y': i128
1592 177..178 'y': A<&str, u128>
1593 177..180 'y.x': &str
1594 186..187 'y': A<&str, u128>
1595 186..189 'y.y': u128
1596 195..196 'z': A<u8, i8>
1598 204..205 'z': A<u8, i8>
1605 fn recursive_type_alias() {
1614 58..59 'x': {unknown}
1621 fn infer_type_param() {
1624 fn id<T>(x: T) -> T {
1628 fn clone<T>(x: &T) -> T {
1635 let x: bool = clone(z);
1647 77..157 '{ ...(1); }': ()
1650 102..104 'id': fn id<u32>(u32) -> u32
1651 102..107 'id(y)': u32
1654 127..132 'clone': fn clone<bool>(&bool) -> bool
1655 127..135 'clone(z)': bool
1657 141..151 'id::<i128>': fn id<i128>(i128) -> i128
1658 141..154 'id::<i128>(1)': i128
1669 impl Foo { const ASSOC_CONST: u32 = 0; }
1670 const GLOBAL_CONST: u32 = 101;
1672 const LOCAL_CONST: u32 = 99;
1673 let x = LOCAL_CONST;
1674 let z = GLOBAL_CONST;
1675 let id = Foo::ASSOC_CONST;
1681 94..212 '{ ...NST; }': ()
1683 141..152 'LOCAL_CONST': u32
1685 166..178 'GLOBAL_CONST': u32
1687 193..209 'Foo::A..._CONST': u32
1697 static GLOBAL_STATIC: u32 = 101;
1698 static mut GLOBAL_STATIC_MUT: u32 = 101;
1700 static LOCAL_STATIC: u32 = 99;
1701 static mut LOCAL_STATIC_MUT: u32 = 99;
1702 let x = LOCAL_STATIC;
1703 let y = LOCAL_STATIC_MUT;
1704 let z = GLOBAL_STATIC;
1705 let w = GLOBAL_STATIC_MUT;
1711 84..279 '{ ...MUT; }': ()
1713 176..188 'LOCAL_STATIC': u32
1715 202..218 'LOCAL_...IC_MUT': u32
1717 232..245 'GLOBAL_STATIC': u32
1719 259..276 'GLOBAL...IC_MUT': u32
1727 fn shadowing_primitive() {
1733 impl i32 { fn foo(&self) -> Foo { Foo } }
1744 fn not_shadowing_primitive_by_module() {
1752 fn foo() -> &'static str { "" }
1762 fn not_shadowing_module_by_primitive() {
1770 fn foo() -> &'static str { "" }
1779 // This test is actually testing the shadowing behavior within hir_def. It
1780 // lives here because the testing infrastructure in hir_def isn't currently
1781 // capable of asserting the necessary conditions.
1783 fn should_be_shadowing_imports() {
1787 pub fn foo() -> i8 {0}
1788 pub struct foo { a: i8 }
1790 mod b { pub fn foo () -> u8 {0} }
1791 mod c { pub struct foo { a: u8 } }
1793 pub use super::a::*;
1794 pub use super::c::foo;
1795 pub use super::b::foo;
1808 fn closure_return() {
1812 let x = || -> usize { return 1; };
1816 16..58 '{ ...; }; }': ()
1817 26..27 'x': || -> usize
1818 30..55 '|| -> ...n 1; }': || -> usize
1819 42..55 '{ return 1; }': usize
1820 44..52 'return 1': !
1827 fn closure_return_unit() {
1831 let x = || { return; };
1835 16..47 '{ ...; }; }': ()
1836 26..27 'x': || -> ()
1837 30..44 '|| { return; }': || -> ()
1838 33..44 '{ return; }': ()
1845 fn closure_return_inferred() {
1849 let x = || { "test" };
1853 16..46 '{ ..." }; }': ()
1854 26..27 'x': || -> &str
1855 30..43 '|| { "test" }': || -> &str
1856 33..43 '{ "test" }': &str
1857 35..41 '"test"': &str
1863 fn fn_pointer_return() {
1871 let vtable = Vtable { method: || {} };
1872 let m = vtable.method;
1876 47..120 '{ ...hod; }': ()
1877 57..63 'vtable': Vtable
1878 66..90 'Vtable...| {} }': Vtable
1879 83..88 '|| {}': || -> ()
1882 104..110 'vtable': Vtable
1883 104..117 'vtable.method': fn()
1889 fn effects_smoke_test() {
1893 let x = unsafe { 92 };
1894 let y = async { async { () }.await };
1899 #[prelude_import] use future::*;
1902 #[lang = "future_trait"]
1903 pub trait Future { type Output; }
1907 16..136 '{ ...2 }; }': ()
1909 30..43 'unsafe { 92 }': i32
1910 37..43 '{ 92 }': i32
1912 53..54 'y': impl Future<Output = ()>
1913 57..85 'async ...wait }': impl Future<Output = ()>
1914 63..85 '{ asyn...wait }': ()
1915 65..77 'async { () }': impl Future<Output = ()>
1916 65..83 'async ....await': ()
1919 95..96 'z': {unknown}
1920 99..109 'try { () }': {unknown}
1921 103..109 '{ () }': ()
1924 127..133 '{ 92 }': i32
1931 fn infer_generic_from_later_assignment() {
1934 enum Option<T> { Some(T), None }
1945 59..129 '{ ... } }': ()
1946 69..76 'mut end': Option<bool>
1947 79..83 'None': Option<bool>
1948 89..127 'loop {... }': !
1949 94..127 '{ ... }': ()
1950 104..107 'end': Option<bool>
1951 104..120 'end = ...(true)': ()
1952 110..114 'Some': Some<bool>(bool) -> Option<bool>
1953 110..120 'Some(true)': Option<bool>
1954 115..119 'true': bool
1960 fn infer_loop_break_with_val() {
1963 enum Option<T> { Some(T), None }
1977 59..168 '{ ... }; }': ()
1978 69..70 'x': Option<bool>
1979 73..165 'loop {... }': Option<bool>
1980 78..165 '{ ... }': ()
1981 88..132 'if fal... }': ()
1982 91..96 'false': bool
1983 97..132 '{ ... }': ()
1984 111..121 'break None': !
1985 117..121 'None': Option<bool>
1986 142..158 'break ...(true)': !
1987 148..152 'Some': Some<bool>(bool) -> Option<bool>
1988 148..158 'Some(true)': Option<bool>
1989 153..157 'true': bool
1995 fn infer_loop_break_without_val() {
1998 enum Option<T> { Some(T), None }
2010 59..136 '{ ... }; }': ()
2012 73..133 'loop {... }': ()
2013 78..133 '{ ... }': ()
2014 88..127 'if fal... }': ()
2015 91..96 'false': bool
2016 97..127 '{ ... }': ()
2023 fn infer_labelled_break_with_val() {
2027 let _x = || 'outer: loop {
2028 let inner = 'inner: loop {
2029 let i = Default::default();
2030 if (break 'outer i) {
2031 loop { break 'inner 5i8; };
2042 9..335 '{ ... }; }': ()
2043 19..21 '_x': || -> bool
2044 24..332 '|| 'ou... }': || -> bool
2045 27..332 ''outer... }': bool
2046 40..332 '{ ... }': ()
2048 62..300 ''inner... }': i8
2049 75..300 '{ ... }': ()
2051 97..113 'Defaul...efault': {unknown}
2052 97..115 'Defaul...ault()': bool
2053 129..269 'if (br... }': ()
2054 133..147 'break 'outer i': !
2056 149..208 '{ ... }': ()
2057 167..193 'loop {...5i8; }': !
2058 172..193 '{ brea...5i8; }': ()
2059 174..190 'break ...er 5i8': !
2061 214..269 'if tru... }': ()
2062 217..221 'true': bool
2063 222..269 '{ ... }': ()
2064 240..254 'break 'inner 6': !
2066 282..289 'break 7': !
2068 310..325 'break inner < 8': !
2069 316..321 'inner': i8
2070 316..325 'inner < 8': bool
2077 fn generic_default() {
2080 struct Thing<T = ()> { t: T }
2081 enum OtherThing<T = ()> {
2086 fn test(t1: Thing, t2: OtherThing, t3: Thing<i32>, t4: OtherThing<i32>) {
2090 OtherThing::One { t } => { t; },
2091 OtherThing::Two(t) => { t; },
2094 OtherThing::One { t } => { t; },
2095 OtherThing::Two(t) => { t; },
2100 97..99 't1': Thing<()>
2101 108..110 't2': OtherThing<()>
2102 124..126 't3': Thing<i32>
2103 140..142 't4': OtherThing<i32>
2104 161..384 '{ ... } }': ()
2105 167..169 't1': Thing<()>
2107 177..179 't3': Thing<i32>
2108 177..181 't3.t': i32
2109 187..282 'match ... }': ()
2110 193..195 't2': OtherThing<()>
2111 206..227 'OtherT... { t }': OtherThing<()>
2113 231..237 '{ t; }': ()
2115 247..265 'OtherT...Two(t)': OtherThing<()>
2117 269..275 '{ t; }': ()
2119 287..382 'match ... }': ()
2120 293..295 't4': OtherThing<i32>
2121 306..327 'OtherT... { t }': OtherThing<i32>
2123 331..337 '{ t; }': ()
2125 347..365 'OtherT...Two(t)': OtherThing<i32>
2127 369..375 '{ t; }': ()
2134 fn generic_default_in_struct_literal() {
2137 struct Thing<T = ()> { t: T }
2138 enum OtherThing<T = ()> {
2144 let x = Thing { t: loop {} };
2145 let y = Thing { t: () };
2146 let z = Thing { t: 1i32 };
2147 if let Thing { t } = z {
2151 let a = OtherThing::One { t: 1i32 };
2152 let b = OtherThing::Two(1i32);
2156 99..319 '{ ...32); }': ()
2157 109..110 'x': Thing<!>
2158 113..133 'Thing ...p {} }': Thing<!>
2159 124..131 'loop {}': !
2161 143..144 'y': Thing<()>
2162 147..162 'Thing { t: () }': Thing<()>
2164 172..173 'z': Thing<i32>
2165 176..193 'Thing ...1i32 }': Thing<i32>
2166 187..191 '1i32': i32
2167 199..240 'if let... }': ()
2168 206..217 'Thing { t }': Thing<i32>
2170 220..221 'z': Thing<i32>
2171 222..240 '{ ... }': ()
2173 250..251 'a': OtherThing<i32>
2174 254..281 'OtherT...1i32 }': OtherThing<i32>
2175 275..279 '1i32': i32
2176 291..292 'b': OtherThing<i32>
2177 295..310 'OtherThing::Two': Two<i32>(i32) -> OtherThing<i32>
2178 295..316 'OtherT...(1i32)': OtherThing<i32>
2179 311..315 '1i32': i32
2185 fn generic_default_depending_on_other_type_arg() {
2186 // FIXME: the {unknown} is a bug
2189 struct Thing<T = u128, F = fn() -> T> { t: T }
2191 fn test(t1: Thing<u32>, t2: Thing) {
2194 Thing::<_> { t: 1u32 };
2198 56..58 't1': Thing<u32, fn() -> u32>
2199 72..74 't2': Thing<u128, fn() -> u128>
2200 83..130 '{ ...2 }; }': ()
2201 89..91 't1': Thing<u32, fn() -> u32>
2202 97..99 't2': Thing<u128, fn() -> u128>
2203 105..127 'Thing:...1u32 }': Thing<u32, fn() -> {unknown}>
2204 121..125 '1u32': u32
2210 fn generic_default_depending_on_other_type_arg_forward() {
2211 // the {unknown} here is intentional, as defaults are not allowed to
2212 // refer to type parameters coming later
2215 struct Thing<F = fn() -> T, T = u128> { t: T }
2217 fn test(t1: Thing) {
2222 56..58 't1': Thing<fn() -> {unknown}, u128>
2223 67..78 '{ t1; }': ()
2224 73..75 't1': Thing<fn() -> {unknown}, u128>