1 use expect_test::expect;
4 use super::{check_infer, check_types};
10 //- /main.rs crate:main deps:std
13 let t = (x, box x, box &1, box [1]);
15 } //^ (Box<i32>, Box<Box<i32>>, Box<&i32>, Box<[i32; _]>)
18 #[prelude_import] use prelude::*;
23 pub struct Box<T: ?Sized> {
35 enum Nat { Succ(Self), Demo(Nat), Zero }
38 let foo: Nat = Nat::Zero;
39 if let Nat::Succ(x) = foo {
48 fn self_in_struct_lit() {
62 59..72 'Self { x: 1 }': S<u32>
69 fn type_alias_in_struct_lit() {
82 50..70 '{ ...1 }; }': ()
83 56..67 'SS { x: 1 }': S<u32>
93 //- /main.rs crate:main deps:core
102 let t = (a, b, c, d, e, f);
104 } //^ (RangeFull, RangeFrom<i32>, RangeTo<u32>, Range<usize>, RangeToInclusive<i32>, RangeInclusive<char>)
106 //- /core.rs crate:core
107 #[prelude_import] use prelude::*;
111 pub struct Range<Idx> {
115 pub struct RangeFrom<Idx> {
119 pub struct RangeInclusive<Idx> {
124 pub struct RangeTo<Idx> {
127 pub struct RangeToInclusive<Idx> {
136 fn infer_while_let() {
139 enum Option<T> { Some(T), None }
142 let foo: Option<f32> = None;
143 while let Option::Some(x) = foo {
155 fn test(a: u32, b: isize, c: !, d: &str) {
170 41..120 '{ ...f32; }': ()
175 75..81 '1usize': usize
176 87..93 '1isize': isize
177 99..105 '"test"': &str
178 111..117 '1.0f32': f32
197 10..117 '{ ...= e; }': ()
199 24..30 '1isize': isize
232 66..90 '{ ...c(); }': ()
233 72..73 'a': fn a() -> u32
235 81..85 'b::c': fn c() -> u32
242 fn infer_path_type() {
248 fn foo() -> i32 { 1 }
259 59..92 '{ ...o(); }': ()
260 65..71 'S::foo': fn foo() -> i32
261 65..73 'S::foo()': i32
262 79..87 '<S>::foo': fn foo() -> i32
263 79..89 '<S>::foo()': i32
282 let a: A = A { b: B, c: C(1) };
288 71..153 '{ ...a.c; }': ()
290 85..86 'C': C(usize) -> C
295 113..132 'A { b:...C(1) }': A
297 126..127 'C': C(usize) -> C
321 51..89 '{ ...:V2; }': ()
322 57..75 'E::V1 ...d: 1 }': E
339 let u = MyUnion { foo: 0 };
341 let u = MyUnion { bar: 0.0 };
345 unsafe fn baz(u: MyUnion) {
351 57..172 '{ ...); } }': ()
353 71..89 'MyUnio...o: 0 }': MyUnion
355 95..113 'unsafe...(u); }': ()
356 102..113 '{ baz(u); }': ()
357 104..107 'baz': fn baz(MyUnion)
358 104..110 'baz(u)': ()
359 108..109 'u': MyUnion
360 122..123 'u': MyUnion
361 126..146 'MyUnio... 0.0 }': MyUnion
363 152..170 'unsafe...(u); }': ()
364 159..170 '{ baz(u); }': ()
365 161..164 'baz': fn baz(MyUnion)
366 161..167 'baz(u)': ()
367 165..166 'u': MyUnion
368 188..189 'u': MyUnion
369 200..249 '{ ...bar; }': ()
370 210..215 'inner': u32
371 218..219 'u': MyUnion
372 218..223 'u.foo': u32
373 233..238 'inner': f32
374 241..242 'u': MyUnion
375 241..246 'u.bar': f32
384 fn test(a: &u32, b: &mut u32, c: *const u32, d: *mut u32) {
401 30..31 'c': *const u32
403 58..149 '{ ... *d; }': ()
409 87..93 '&mut a': &mut &u32
411 99..100 'b': &mut u32
413 107..108 'b': &mut u32
414 114..116 '&b': &&mut u32
415 115..116 'b': &mut u32
416 122..123 'c': *const u32
418 130..131 'c': *const u32
419 137..138 'd': *mut u32
421 145..146 'd': *mut u32
437 16..53 '{ ...t a; }': ()
438 22..32 '&raw mut a': *mut i32
440 38..50 '&raw const a': *const i32
447 fn infer_literals() {
471 10..216 '{ ...o"#; }': ()
475 46..53 '"hello"': &str
476 59..67 'b"bytes"': &[u8; _]
481 112..117 'false': bool
482 123..127 'true': bool
483 133..197 'r#" ... "#': &str
484 203..213 'br#"yolo"#': &[u8; _]
490 fn infer_unary_op() {
495 fn test(x: SomeType) {
515 39..271 '{ ...lo"; }': ()
530 145..152 '!!!true': bool
531 146..152 '!!true': bool
532 147..152 '!true': bool
533 148..152 'true': bool
538 183..189 '!10u32': u32
539 184..189 '10u32': u32
543 211..216 '-3.14': f64
547 230..232 '-x': {unknown}
548 231..232 'x': SomeType
549 238..240 '!x': {unknown}
550 239..240 'x': SomeType
551 246..254 '-"hello"': {unknown}
552 247..254 '"hello"': &str
553 260..268 '!"hello"': {unknown}
554 261..268 '"hello"': &str
560 fn infer_backwards() {
563 fn takes_u32(x: u32) {}
565 struct S { i32_field: i32 }
567 fn test() -> &mut &f64 {
568 let a = unknown_function();
570 let b = unknown_function();
572 let c = unknown_function();
579 77..230 '{ ...t &c }': &mut &f64
581 91..107 'unknow...nction': {unknown}
582 91..109 'unknow...tion()': u32
583 115..124 'takes_u32': fn takes_u32(u32)
584 115..127 'takes_u32(a)': ()
587 141..157 'unknow...nction': {unknown}
588 141..159 'unknow...tion()': i32
589 165..183 'S { i3...d: b }': S
592 197..213 'unknow...nction': {unknown}
593 197..215 'unknow...tion()': f64
594 221..228 '&mut &c': &mut &f64
611 fn test2(self: &Self) {
627 87..108 '{ ... }': ()
629 132..152 '{ ... }': S
631 176..199 '{ ... }': S
632 186..193 'Self {}': S
638 fn infer_self_as_path() {
666 86..107 '{ ... }': ()
668 134..158 '{ ... }': ()
669 144..148 'Self': S2(isize) -> S2
670 144..151 'Self(1)': S2
672 184..230 '{ ... }': ()
673 194..202 'Self::V1': E
674 212..220 'Self::V2': V2(u32) -> E
675 212..223 'Self::V2(1)': E
682 fn infer_binary_op() {
685 fn f(x: bool) -> i32 {
691 let y = true || false;
694 let minus_forty: isize = -40isize;
695 let h = minus_forty <= CONST_2;
696 let c = f(z || y) + 5;
698 let g = minus_forty ^= i;
700 let ten_is_eleven = ten == some_num;
707 21..33 '{ 0i32 }': i32
709 53..369 '{ ... < 3 }': bool
712 67..73 'a && b': bool
716 87..100 'true || false': bool
717 95..100 'false': bool
720 114..120 'x == y': bool
724 134..140 'x != y': bool
726 150..161 'minus_forty': isize
727 171..179 '-40isize': isize
728 172..179 '40isize': isize
730 193..204 'minus_forty': isize
731 193..215 'minus_...ONST_2': bool
732 208..215 'CONST_2': isize
734 229..230 'f': fn f(bool) -> i32
735 229..238 'f(z || y)': i32
736 229..242 'f(z || y) + 5': i32
738 231..237 'z || y': bool
741 252..253 'd': {unknown}
742 256..257 'b': {unknown}
744 271..282 'minus_forty': isize
745 271..287 'minus_...y ^= i': ()
747 297..300 'ten': usize
749 322..335 'ten_is_eleven': bool
750 338..341 'ten': usize
751 338..353 'ten == some_num': bool
752 345..353 'some_num': usize
753 360..363 'ten': usize
754 360..367 'ten < 3': bool
761 fn infer_shift_op() {
770 10..47 '{ ...5u8; }': ()
772 16..27 '1u32 << 5u8': u32
775 33..44 '1u32 >> 5u8': u32
782 fn infer_field_autoderef() {
799 let a5 = &mut &&mut &&mut a;
803 fn test2(a1: *const A, a2: *mut A) {
810 49..212 '{ ...5.b; }': ()
820 112..114 'a3': &mut A
821 117..123 '&mut a': &mut A
823 129..131 'a3': &mut A
825 143..145 'a4': &&&&&&&A
826 148..156 '&&&&&&&a': &&&&&&&A
827 149..156 '&&&&&&a': &&&&&&A
828 150..156 '&&&&&a': &&&&&A
829 151..156 '&&&&a': &&&&A
830 152..156 '&&&a': &&&A
834 162..164 'a4': &&&&&&&A
836 176..178 'a5': &mut &&mut &&mut A
837 181..199 '&mut &...&mut a': &mut &&mut &&mut A
838 186..199 '&&mut &&mut a': &&mut &&mut A
839 187..199 '&mut &&mut a': &mut &&mut A
840 192..199 '&&mut a': &&mut A
841 193..199 '&mut a': &mut A
843 205..207 'a5': &mut &&mut &&mut A
845 223..225 'a1': *const A
846 237..239 'a2': *mut A
847 249..272 '{ ...2.b; }': ()
848 255..257 'a1': *const A
850 265..267 'a2': *mut A
857 fn infer_argument_autoderef() {
863 fn deref(&self) -> &Self::Target;
869 fn foo(&self) -> &T {
876 impl<T> Deref for B<T> {
878 fn deref(&self) -> &Self::Target {
884 let t = A::foo(&&B(B(A(42))));
889 138..142 'self': &A<T>
890 150..173 '{ ... }': &T
891 160..167 '&self.0': &T
892 161..165 'self': &A<T>
894 254..258 'self': &B<T>
895 277..300 '{ ... }': &T
896 287..294 '&self.0': &T
897 288..292 'self': &B<T>
899 314..352 '{ ...))); }': ()
901 328..334 'A::foo': fn foo<i32>(&A<i32>) -> &i32
902 328..349 'A::foo...42))))': &i32
903 335..348 '&&B(B(A(42)))': &&B<B<A<i32>>>
904 336..348 '&B(B(A(42)))': &B<B<A<i32>>>
905 337..338 'B': B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>>
906 337..348 'B(B(A(42)))': B<B<A<i32>>>
907 339..340 'B': B<A<i32>>(A<i32>) -> B<A<i32>>
908 339..347 'B(A(42))': B<A<i32>>
909 341..342 'A': A<i32>(i32) -> A<i32>
910 341..346 'A(42)': A<i32>
917 fn infer_method_argument_autoderef() {
923 fn deref(&self) -> &Self::Target;
929 fn foo(&self, x: &A<T>) -> &T {
936 impl<T> Deref for B<T> {
938 fn deref(&self) -> &Self::Target {
944 let t = A(0 as *mut _).foo(&&B(B(a)));
949 143..147 'self': &A<T>
951 165..186 '{ ... }': &T
955 177..180 'x.0': *mut T
956 267..271 'self': &B<T>
957 290..313 '{ ... }': &T
958 300..307 '&self.0': &T
959 301..305 'self': &B<T>
962 336..382 '{ ...))); }': ()
964 350..351 'A': A<i32>(*mut i32) -> A<i32>
965 350..364 'A(0 as *mut _)': A<i32>
966 350..379 'A(0 as...B(a)))': &i32
968 352..363 '0 as *mut _': *mut i32
969 369..378 '&&B(B(a))': &&B<B<A<i32>>>
970 370..378 '&B(B(a))': &B<B<A<i32>>>
971 371..372 'B': B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>>
972 371..378 'B(B(a))': B<B<A<i32>>>
973 373..374 'B': B<A<i32>>(A<i32>) -> B<A<i32>>
974 373..377 '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 {
1035 9..322 '{ ... }; }': ()
1037 25..79 'if tru... }': i32
1039 33..50 '{ ... }': i32
1041 56..79 '{ ... }': i32
1044 95..148 'if tru... }': i32
1045 98..102 'true': bool
1046 103..120 '{ ... }': i32
1048 126..148 '{ ... }': !
1049 136..142 'return': !
1051 164..246 'match ... }': i32
1052 170..174 'true': bool
1053 185..189 'true': bool
1054 185..189 'true': bool
1057 209..240 '{ ... }': i32
1058 223..229 'return': !
1060 262..319 'match ... }': i32
1061 268..272 'true': bool
1062 283..287 'true': bool
1063 283..287 'true': bool
1066 307..313 'return': !
1072 fn infer_inherent_method() {
1078 fn foo(self, x: u32) -> i32 {}
1083 fn bar(&self, x: u64) -> i64 {}
1101 149..197 '{ ...(1); }': ()
1103 155..163 'a.foo(1)': i32
1105 169..180 '(&a).bar(1)': i64
1110 186..194 'a.bar(1)': i64
1117 fn infer_inherent_method_str() {
1122 fn foo(&self) -> i32 {}
1132 68..88 '{ ...o(); }': ()
1133 74..79 '"foo"': &str
1134 74..85 '"foo".foo()': i32
1143 fn test(x: &str, y: isize) {
1144 let a: (u32, &str) = (1, "a");
1155 27..169 '{ ...d"); }': ()
1156 37..38 'a': (u32, &str)
1157 54..62 '(1, "a")': (u32, &str)
1160 72..73 'b': ((u32, &str), &str)
1161 76..82 '(a, x)': ((u32, &str), &str)
1162 77..78 'a': (u32, &str)
1164 92..93 'c': (isize, &str)
1165 96..102 '(y, x)': (isize, &str)
1168 112..113 'd': ((isize, &str), &str)
1169 116..122 '(c, x)': ((isize, &str), &str)
1170 117..118 'c': (isize, &str)
1172 132..133 'e': (i32, &str)
1173 136..144 '(1, "e")': (i32, &str)
1175 140..143 '"e"': &str
1176 154..155 'f': ((i32, &str), &str)
1177 158..166 '(e, "d")': ((i32, &str), &str)
1178 159..160 'e': (i32, &str)
1179 162..165 '"d"': &str
1188 fn test(x: &str, y: isize) {
1193 let d = [y, 1, 2, 3];
1194 let d = [1, y, 2, 3];
1203 let x: [u8; 0] = [];
1209 27..292 '{ ... []; }': ()
1210 37..38 'a': [&str; _]
1211 41..44 '[x]': [&str; _]
1213 54..55 'b': [[&str; _]; _]
1214 58..64 '[a, a]': [[&str; _]; _]
1215 59..60 'a': [&str; _]
1216 62..63 'a': [&str; _]
1217 74..75 'c': [[[&str; _]; _]; _]
1218 78..84 '[b, b]': [[[&str; _]; _]; _]
1219 79..80 'b': [[&str; _]; _]
1220 82..83 'b': [[&str; _]; _]
1221 95..96 'd': [isize; _]
1222 99..111 '[y, 1, 2, 3]': [isize; _]
1227 121..122 'd': [isize; _]
1228 125..137 '[1, y, 2, 3]': [isize; _]
1233 147..148 'e': [isize; _]
1234 151..154 '[y]': [isize; _]
1236 164..165 'f': [[isize; _]; _]
1237 168..174 '[d, d]': [[isize; _]; _]
1238 169..170 'd': [isize; _]
1239 172..173 'd': [isize; _]
1240 184..185 'g': [[isize; _]; _]
1241 188..194 '[e, e]': [[isize; _]; _]
1242 189..190 'e': [isize; _]
1243 192..193 'e': [isize; _]
1244 205..206 'h': [i32; _]
1245 209..215 '[1, 2]': [i32; _]
1248 225..226 'i': [&str; _]
1249 229..239 '["a", "b"]': [&str; _]
1250 230..233 '"a"': &str
1251 235..238 '"b"': &str
1252 250..251 'b': [[&str; _]; _]
1253 254..264 '[a, ["b"]]': [[&str; _]; _]
1254 255..256 'a': [&str; _]
1255 258..263 '["b"]': [&str; _]
1256 259..262 '"b"': &str
1257 274..275 'x': [u8; _]
1258 287..289 '[]': [u8; _]
1264 fn infer_struct_generics() {
1271 fn test(a1: A<u32>, i: i32) {
1273 let a2 = A { x: i };
1275 let a3 = A::<i128> { x: 1 };
1282 55..146 '{ ...3.x; }': ()
1286 80..90 'A { x: i }': A<i32>
1290 110..112 'a3': A<i128>
1291 115..133 'A::<i1...x: 1 }': A<i128>
1293 139..141 'a3': A<i128>
1294 139..143 'a3.x': i128
1300 fn infer_tuple_struct_generics() {
1304 enum Option<T> { Some(T), None }
1313 let x: Option<i64> = None;
1317 75..183 '{ ...one; }': ()
1318 81..82 'A': A<i32>(i32) -> A<i32>
1319 81..86 'A(42)': A<i32>
1321 92..93 'A': A<u128>(u128) -> A<u128>
1322 92..101 'A(42u128)': A<u128>
1323 94..100 '42u128': u128
1324 107..111 'Some': Some<&str>(&str) -> Option<&str>
1325 107..116 'Some("x")': Option<&str>
1326 112..115 '"x"': &str
1327 122..134 'Option::Some': Some<&str>(&str) -> Option<&str>
1328 122..139 'Option...e("x")': Option<&str>
1329 135..138 '"x"': &str
1330 145..149 'None': Option<{unknown}>
1331 159..160 'x': Option<i64>
1332 176..180 'None': Option<i64>
1338 fn infer_function_generics() {
1341 fn id<T>(t: T) -> T { t }
1353 37..97 '{ ...(1); }': ()
1354 43..45 'id': fn id<u32>(u32) -> u32
1355 43..51 'id(1u32)': u32
1357 57..67 'id::<i128>': fn id<i128>(i128) -> i128
1358 57..70 'id::<i128>(1)': i128
1361 89..91 'id': fn id<u64>(u64) -> u64
1369 fn infer_impl_generics_basic() {
1376 impl<Y, X> A<X, Y> {
1383 fn z<T>(self, t: T) -> (X, Y, T) {
1389 let a = A { x: 1u64, y: 1i64 };
1397 73..77 'self': A<X, Y>
1398 84..106 '{ ... }': X
1399 94..98 'self': A<X, Y>
1401 116..120 'self': A<X, Y>
1402 127..149 '{ ... }': Y
1403 137..141 'self': A<X, Y>
1404 137..143 'self.y': Y
1405 162..166 'self': A<X, Y>
1407 187..222 '{ ... }': (X, Y, T)
1408 197..216 '(self.....y, t)': (X, Y, T)
1409 198..202 'self': A<X, Y>
1410 198..204 'self.x': X
1411 206..210 'self': A<X, Y>
1412 206..212 'self.y': Y
1414 244..341 '{ ...(1); }': ()
1415 254..255 'a': A<u64, i64>
1416 258..280 'A { x:...1i64 }': A<u64, i64>
1417 265..269 '1u64': u64
1418 274..278 '1i64': i64
1419 286..287 'a': A<u64, i64>
1420 286..291 'a.x()': u64
1421 297..298 'a': A<u64, i64>
1422 297..302 'a.y()': i64
1423 308..309 'a': A<u64, i64>
1424 308..318 'a.z(1i128)': (u64, i64, i128)
1425 312..317 '1i128': i128
1426 324..325 'a': A<u64, i64>
1427 324..338 'a.z::<u128>(1)': (u64, i64, u128)
1434 fn infer_impl_generics_with_autoderef() {
1442 fn as_ref(&self) -> Option<&T> {}
1444 fn test(o: Option<u32>) {
1450 77..81 'self': &Option<T>
1452 110..111 'o': Option<u32>
1453 126..164 '{ ...f(); }': ()
1454 132..145 '(&o).as_ref()': Option<&u32>
1455 133..135 '&o': &Option<u32>
1456 134..135 'o': Option<u32>
1457 151..152 'o': Option<u32>
1458 151..161 'o.as_ref()': Option<&u32>
1464 fn infer_generic_chain() {
1475 fn id<T>(t: T) -> T { t }
1480 let a = A { x: id(y) };
1487 52..56 'self': A<T2>
1488 64..86 '{ ... }': T2
1489 74..78 'self': A<T2>
1494 134..254 '{ ....x() }': i128
1498 163..165 'id': fn id<i128>(i128) -> i128
1499 163..168 'id(x)': i128
1501 178..179 'a': A<i128>
1502 182..196 'A { x: id(y) }': A<i128>
1503 189..191 'id': fn id<i128>(i128) -> i128
1504 189..194 'id(y)': i128
1507 210..212 'id': fn id<i128>(i128) -> i128
1508 210..217 'id(a.x)': i128
1509 213..214 'a': A<i128>
1510 213..216 'a.x': i128
1511 227..228 'b': A<i128>
1512 231..241 'A { x: z }': A<i128>
1514 247..248 'b': A<i128>
1515 247..252 'b.x()': i128
1521 fn infer_associated_const() {
1542 impl Trait for TraitTest {
1547 let x = Struct::FOO;
1549 let z = TraitTest::ID;
1556 228..306 '{ ...:ID; }': ()
1558 242..253 'Struct::FOO': u32
1560 267..276 'Enum::BAR': u32
1562 290..303 'TraitTest::ID': u32
1568 fn infer_type_alias() {
1571 struct A<X, Y> { x: X, y: Y }
1572 type Foo = A<u32, i128>;
1573 type Bar<T> = A<T, u128>;
1574 type Baz<U, V> = A<V, U>;
1575 fn test(x: Foo, y: Bar<&str>, z: Baz<i8, u8>) {
1585 115..116 'x': A<u32, i128>
1586 123..124 'y': A<&str, u128>
1587 137..138 'z': A<u8, i8>
1588 153..210 '{ ...z.y; }': ()
1589 159..160 'x': A<u32, i128>
1591 168..169 'x': A<u32, i128>
1592 168..171 'x.y': i128
1593 177..178 'y': A<&str, u128>
1594 177..180 'y.x': &str
1595 186..187 'y': A<&str, u128>
1596 186..189 'y.y': u128
1597 195..196 'z': A<u8, i8>
1599 204..205 'z': A<u8, i8>
1606 fn recursive_type_alias() {
1615 58..59 'x': {unknown}
1622 fn infer_type_param() {
1625 fn id<T>(x: T) -> T {
1629 fn clone<T>(x: &T) -> T {
1636 let x: bool = clone(z);
1648 77..157 '{ ...(1); }': ()
1651 102..104 'id': fn id<u32>(u32) -> u32
1652 102..107 'id(y)': u32
1655 127..132 'clone': fn clone<bool>(&bool) -> bool
1656 127..135 'clone(z)': bool
1658 141..151 'id::<i128>': fn id<i128>(i128) -> i128
1659 141..154 'id::<i128>(1)': i128
1670 impl Foo { const ASSOC_CONST: u32 = 0; }
1671 const GLOBAL_CONST: u32 = 101;
1673 const LOCAL_CONST: u32 = 99;
1674 let x = LOCAL_CONST;
1675 let z = GLOBAL_CONST;
1676 let id = Foo::ASSOC_CONST;
1682 94..212 '{ ...NST; }': ()
1684 141..152 'LOCAL_CONST': u32
1686 166..178 'GLOBAL_CONST': u32
1688 193..209 'Foo::A..._CONST': u32
1698 static GLOBAL_STATIC: u32 = 101;
1699 static mut GLOBAL_STATIC_MUT: u32 = 101;
1701 static LOCAL_STATIC: u32 = 99;
1702 static mut LOCAL_STATIC_MUT: u32 = 99;
1703 let x = LOCAL_STATIC;
1704 let y = LOCAL_STATIC_MUT;
1705 let z = GLOBAL_STATIC;
1706 let w = GLOBAL_STATIC_MUT;
1712 84..279 '{ ...MUT; }': ()
1714 176..188 'LOCAL_STATIC': u32
1716 202..218 'LOCAL_...IC_MUT': u32
1718 232..245 'GLOBAL_STATIC': u32
1720 259..276 'GLOBAL...IC_MUT': u32
1728 fn shadowing_primitive() {
1734 impl i32 { fn foo(&self) -> Foo { Foo } }
1745 fn not_shadowing_primitive_by_module() {
1753 fn foo() -> &'static str { "" }
1763 fn not_shadowing_module_by_primitive() {
1771 fn foo() -> &'static str { "" }
1780 // This test is actually testing the shadowing behavior within hir_def. It
1781 // lives here because the testing infrastructure in hir_def isn't currently
1782 // capable of asserting the necessary conditions.
1784 fn should_be_shadowing_imports() {
1788 pub fn foo() -> i8 {0}
1789 pub struct foo { a: i8 }
1791 mod b { pub fn foo () -> u8 {0} }
1792 mod c { pub struct foo { a: u8 } }
1794 pub use super::a::*;
1795 pub use super::c::foo;
1796 pub use super::b::foo;
1809 fn closure_return() {
1813 let x = || -> usize { return 1; };
1817 16..58 '{ ...; }; }': ()
1818 26..27 'x': || -> usize
1819 30..55 '|| -> ...n 1; }': || -> usize
1820 42..55 '{ return 1; }': usize
1821 44..52 'return 1': !
1828 fn closure_return_unit() {
1832 let x = || { return; };
1836 16..47 '{ ...; }; }': ()
1837 26..27 'x': || -> ()
1838 30..44 '|| { return; }': || -> ()
1839 33..44 '{ return; }': ()
1846 fn closure_return_inferred() {
1850 let x = || { "test" };
1854 16..46 '{ ..." }; }': ()
1855 26..27 'x': || -> &str
1856 30..43 '|| { "test" }': || -> &str
1857 33..43 '{ "test" }': &str
1858 35..41 '"test"': &str
1864 fn fn_pointer_return() {
1872 let vtable = Vtable { method: || {} };
1873 let m = vtable.method;
1877 47..120 '{ ...hod; }': ()
1878 57..63 'vtable': Vtable
1879 66..90 'Vtable...| {} }': Vtable
1880 83..88 '|| {}': || -> ()
1883 104..110 'vtable': Vtable
1884 104..117 'vtable.method': fn()
1890 fn effects_smoke_test() {
1894 let x = unsafe { 92 };
1895 let y = async { async { () }.await };
1897 let w = const { 92 };
1901 #[prelude_import] use future::*;
1904 #[lang = "future_trait"]
1905 pub trait Future { type Output; }
1909 16..162 '{ ...2 }; }': ()
1911 30..43 'unsafe { 92 }': i32
1912 37..43 '{ 92 }': i32
1914 53..54 'y': impl Future<Output = ()>
1915 57..85 'async ...wait }': impl Future<Output = ()>
1916 63..85 '{ asyn...wait }': ()
1917 65..77 'async { () }': impl Future<Output = ()>
1918 65..83 'async ....await': ()
1921 95..96 'z': {unknown}
1922 99..109 'try { () }': {unknown}
1923 103..109 '{ () }': ()
1926 123..135 'const { 92 }': i32
1927 129..135 '{ 92 }': i32
1930 153..159 '{ 92 }': i32
1937 fn infer_generic_from_later_assignment() {
1940 enum Option<T> { Some(T), None }
1951 59..129 '{ ... } }': ()
1952 69..76 'mut end': Option<bool>
1953 79..83 'None': Option<bool>
1954 89..127 'loop {... }': !
1955 94..127 '{ ... }': ()
1956 104..107 'end': Option<bool>
1957 104..120 'end = ...(true)': ()
1958 110..114 'Some': Some<bool>(bool) -> Option<bool>
1959 110..120 'Some(true)': Option<bool>
1960 115..119 'true': bool
1966 fn infer_loop_break_with_val() {
1969 enum Option<T> { Some(T), None }
1983 59..168 '{ ... }; }': ()
1984 69..70 'x': Option<bool>
1985 73..165 'loop {... }': Option<bool>
1986 78..165 '{ ... }': ()
1987 88..132 'if fal... }': ()
1988 91..96 'false': bool
1989 97..132 '{ ... }': ()
1990 111..121 'break None': !
1991 117..121 'None': Option<bool>
1992 142..158 'break ...(true)': !
1993 148..152 'Some': Some<bool>(bool) -> Option<bool>
1994 148..158 'Some(true)': Option<bool>
1995 153..157 'true': bool
2001 fn infer_loop_break_without_val() {
2004 enum Option<T> { Some(T), None }
2016 59..136 '{ ... }; }': ()
2018 73..133 'loop {... }': ()
2019 78..133 '{ ... }': ()
2020 88..127 'if fal... }': ()
2021 91..96 'false': bool
2022 97..127 '{ ... }': ()
2029 fn infer_labelled_break_with_val() {
2033 let _x = || 'outer: loop {
2034 let inner = 'inner: loop {
2035 let i = Default::default();
2036 if (break 'outer i) {
2037 loop { break 'inner 5i8; };
2048 9..335 '{ ... }; }': ()
2049 19..21 '_x': || -> bool
2050 24..332 '|| 'ou... }': || -> bool
2051 27..332 ''outer... }': bool
2052 40..332 '{ ... }': ()
2054 62..300 ''inner... }': i8
2055 75..300 '{ ... }': ()
2057 97..113 'Defaul...efault': {unknown}
2058 97..115 'Defaul...ault()': bool
2059 129..269 'if (br... }': ()
2060 133..147 'break 'outer i': !
2062 149..208 '{ ... }': ()
2063 167..193 'loop {...5i8; }': !
2064 172..193 '{ brea...5i8; }': ()
2065 174..190 'break ...er 5i8': !
2067 214..269 'if tru... }': ()
2068 217..221 'true': bool
2069 222..269 '{ ... }': ()
2070 240..254 'break 'inner 6': !
2072 282..289 'break 7': !
2074 310..325 'break inner < 8': !
2075 316..321 'inner': i8
2076 316..325 'inner < 8': bool
2083 fn infer_labelled_block_break_with_val() {
2086 fn default<T>() -> T { loop {} }
2089 let inner = 'inner: {
2091 if (break 'outer i) {
2096 break 'inner 'innermost: { 0 };
2099 break 'outer inner < 8;
2104 21..32 '{ loop {} }': T
2107 42..381 '{ ... }; }': ()
2109 65..378 '{ ... }': bool
2111 95..339 '{ ... }': i8
2113 117..124 'default': fn default<bool>() -> bool
2114 117..126 'default()': bool
2115 140..270 'if (br... }': ()
2116 144..158 'break 'outer i': !
2118 160..209 '{ ... }': ()
2119 178..194 'break ...er 5i8': !
2121 215..270 'if tru... }': ()
2122 218..222 'true': bool
2123 223..270 '{ ... }': ()
2124 241..255 'break 'inner 6': !
2126 283..313 'break ... { 0 }': !
2127 308..313 '{ 0 }': i8
2130 349..371 'break ...er < 8': !
2131 362..367 'inner': i8
2132 362..371 'inner < 8': bool
2139 fn generic_default() {
2142 struct Thing<T = ()> { t: T }
2143 enum OtherThing<T = ()> {
2148 fn test(t1: Thing, t2: OtherThing, t3: Thing<i32>, t4: OtherThing<i32>) {
2152 OtherThing::One { t } => { t; },
2153 OtherThing::Two(t) => { t; },
2156 OtherThing::One { t } => { t; },
2157 OtherThing::Two(t) => { t; },
2162 97..99 't1': Thing<()>
2163 108..110 't2': OtherThing<()>
2164 124..126 't3': Thing<i32>
2165 140..142 't4': OtherThing<i32>
2166 161..384 '{ ... } }': ()
2167 167..169 't1': Thing<()>
2169 177..179 't3': Thing<i32>
2170 177..181 't3.t': i32
2171 187..282 'match ... }': ()
2172 193..195 't2': OtherThing<()>
2173 206..227 'OtherT... { t }': OtherThing<()>
2175 231..237 '{ t; }': ()
2177 247..265 'OtherT...Two(t)': OtherThing<()>
2179 269..275 '{ t; }': ()
2181 287..382 'match ... }': ()
2182 293..295 't4': OtherThing<i32>
2183 306..327 'OtherT... { t }': OtherThing<i32>
2185 331..337 '{ t; }': ()
2187 347..365 'OtherT...Two(t)': OtherThing<i32>
2189 369..375 '{ t; }': ()
2196 fn generic_default_in_struct_literal() {
2199 struct Thing<T = ()> { t: T }
2200 enum OtherThing<T = ()> {
2206 let x = Thing { t: loop {} };
2207 let y = Thing { t: () };
2208 let z = Thing { t: 1i32 };
2209 if let Thing { t } = z {
2213 let a = OtherThing::One { t: 1i32 };
2214 let b = OtherThing::Two(1i32);
2218 99..319 '{ ...32); }': ()
2219 109..110 'x': Thing<!>
2220 113..133 'Thing ...p {} }': Thing<!>
2221 124..131 'loop {}': !
2223 143..144 'y': Thing<()>
2224 147..162 'Thing { t: () }': Thing<()>
2226 172..173 'z': Thing<i32>
2227 176..193 'Thing ...1i32 }': Thing<i32>
2228 187..191 '1i32': i32
2229 199..240 'if let... }': ()
2230 206..217 'Thing { t }': Thing<i32>
2232 220..221 'z': Thing<i32>
2233 222..240 '{ ... }': ()
2235 250..251 'a': OtherThing<i32>
2236 254..281 'OtherT...1i32 }': OtherThing<i32>
2237 275..279 '1i32': i32
2238 291..292 'b': OtherThing<i32>
2239 295..310 'OtherThing::Two': Two<i32>(i32) -> OtherThing<i32>
2240 295..316 'OtherT...(1i32)': OtherThing<i32>
2241 311..315 '1i32': i32
2247 fn generic_default_depending_on_other_type_arg() {
2248 // FIXME: the {unknown} is a bug
2251 struct Thing<T = u128, F = fn() -> T> { t: T }
2253 fn test(t1: Thing<u32>, t2: Thing) {
2256 Thing::<_> { t: 1u32 };
2260 56..58 't1': Thing<u32, fn() -> u32>
2261 72..74 't2': Thing<u128, fn() -> u128>
2262 83..130 '{ ...2 }; }': ()
2263 89..91 't1': Thing<u32, fn() -> u32>
2264 97..99 't2': Thing<u128, fn() -> u128>
2265 105..127 'Thing:...1u32 }': Thing<u32, fn() -> {unknown}>
2266 121..125 '1u32': u32
2272 fn generic_default_depending_on_other_type_arg_forward() {
2273 // the {unknown} here is intentional, as defaults are not allowed to
2274 // refer to type parameters coming later
2277 struct Thing<F = fn() -> T, T = u128> { t: T }
2279 fn test(t1: Thing) {
2284 56..58 't1': Thing<fn() -> {unknown}, u128>
2285 67..78 '{ t1; }': ()
2286 73..75 't1': Thing<fn() -> {unknown}, u128>
2292 fn infer_operator_overload() {
2293 mark::check!(infer_expr_inner_binary_operator_overload);
2297 struct V2([f32; 2]);
2300 pub trait Add<Rhs = Self> {
2301 /// The resulting type after applying the `+` operator.
2304 /// Performs the `+` operation.
2306 fn add(self, rhs: Rhs) -> Self::Output;
2309 impl Add<V2> for V2 {
2312 fn add(self, rhs: V2) -> V2 {
2313 let x = self.0[0] + rhs.0[0];
2314 let y = self.0[1] + rhs.0[1];
2320 let va = V2([0.0, 1.0]);
2321 let vb = V2([0.0, 1.0]);
2328 207..211 'self': Self
2332 320..422 '{ ... }': V2
2335 338..344 'self.0': [f32; _]
2336 338..347 'self.0[0]': {unknown}
2337 338..358 'self.0...s.0[0]': f32
2340 350..355 'rhs.0': [f32; _]
2341 350..358 'rhs.0[0]': {unknown}
2345 376..382 'self.0': [f32; _]
2346 376..385 'self.0[1]': {unknown}
2347 376..396 'self.0...s.0[1]': f32
2350 388..393 'rhs.0': [f32; _]
2351 388..396 'rhs.0[1]': {unknown}
2353 406..408 'V2': V2([f32; _]) -> V2
2354 406..416 'V2([x, y])': V2
2355 409..415 '[x, y]': [f32; _]
2358 436..519 '{ ... vb; }': ()
2360 451..453 'V2': V2([f32; _]) -> V2
2361 451..465 'V2([0.0, 1.0])': V2
2362 454..464 '[0.0, 1.0]': [f32; _]
2366 480..482 'V2': V2([f32; _]) -> V2
2367 480..494 'V2([0.0, 1.0])': V2
2368 483..493 '[0.0, 1.0]': [f32; _]
2373 509..516 'va + vb': V2
2381 fn infer_const_params() {
2384 fn foo<const FOO: usize>() {
2389 27..49 '{ ...FOO; }': ()