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>
116 //- /main.rs crate:main deps:core
125 let t = (a, b, c, d, e, f);
127 } //^ (RangeFull, RangeFrom<i32>, RangeTo<u32>, Range<usize>, RangeToInclusive<i32>, RangeInclusive<char>)
129 //- /core.rs crate:core
130 #[prelude_import] use prelude::*;
134 pub struct Range<Idx> {
138 pub struct RangeFrom<Idx> {
142 pub struct RangeInclusive<Idx> {
147 pub struct RangeTo<Idx> {
150 pub struct RangeToInclusive<Idx> {
159 fn infer_while_let() {
162 enum Option<T> { Some(T), None }
165 let foo: Option<f32> = None;
166 while let Option::Some(x) = foo {
178 fn test(a: u32, b: isize, c: !, d: &str) {
194 41..120 '{ ...f32; }': ()
199 75..81 '1usize': usize
200 87..93 '1isize': isize
201 99..105 '"test"': &str
202 111..117 '1.0f32': f32
221 10..117 '{ ...= e; }': ()
223 24..30 '1isize': isize
256 66..90 '{ ...c(); }': ()
257 72..73 'a': fn a() -> u32
259 81..85 'b::c': fn c() -> u32
266 fn infer_path_type() {
272 fn foo() -> i32 { 1 }
283 59..92 '{ ...o(); }': ()
284 65..71 'S::foo': fn foo() -> i32
285 65..73 'S::foo()': i32
286 79..87 '<S>::foo': fn foo() -> i32
287 79..89 '<S>::foo()': i32
306 let a: A = A { b: B, c: C(1) };
312 71..153 '{ ...a.c; }': ()
314 85..86 'C': C(usize) -> C
319 113..132 'A { b:...C(1) }': A
321 126..127 'C': C(usize) -> C
346 51..89 '{ ...:V2; }': ()
347 57..75 'E::V1 ...d: 1 }': E
364 let u = MyUnion { foo: 0 };
366 let u = MyUnion { bar: 0.0 };
370 unsafe fn baz(u: MyUnion) {
376 57..172 '{ ...); } }': ()
378 71..89 'MyUnio...o: 0 }': MyUnion
380 95..113 'unsafe...(u); }': ()
381 102..113 '{ baz(u); }': ()
382 104..107 'baz': fn baz(MyUnion)
383 104..110 'baz(u)': ()
384 108..109 'u': MyUnion
385 122..123 'u': MyUnion
386 126..146 'MyUnio... 0.0 }': MyUnion
388 152..170 'unsafe...(u); }': ()
389 159..170 '{ baz(u); }': ()
390 161..164 'baz': fn baz(MyUnion)
391 161..167 'baz(u)': ()
392 165..166 'u': MyUnion
393 188..189 'u': MyUnion
394 200..249 '{ ...bar; }': ()
395 210..215 'inner': u32
396 218..219 'u': MyUnion
397 218..223 'u.foo': u32
398 233..238 'inner': f32
399 241..242 'u': MyUnion
400 241..246 'u.bar': f32
409 fn test(a: &u32, b: &mut u32, c: *const u32, d: *mut u32) {
426 30..31 'c': *const u32
428 58..149 '{ ... *d; }': ()
434 87..93 '&mut a': &mut &u32
436 99..100 'b': &mut u32
438 107..108 'b': &mut u32
439 114..116 '&b': &&mut u32
440 115..116 'b': &mut u32
441 122..123 'c': *const u32
443 130..131 'c': *const u32
444 137..138 'd': *mut u32
446 145..146 'd': *mut u32
462 16..53 '{ ...t a; }': ()
463 22..32 '&raw mut a': *mut i32
465 38..50 '&raw const a': *const i32
472 fn infer_literals() {
497 let c = br#"x"\"yb"#;
501 18..478 '{ ... }': ()
505 86..93 '"hello"': &str
506 107..115 'b"bytes"': &[u8; 5]
511 200..205 'false': bool
512 219..223 'true': bool
513 237..333 'r#" ... "#': &str
514 347..357 'br#"yolo"#': &[u8; 4]
515 375..376 'a': &[u8; 4]
516 379..403 'b"a\x2... c"': &[u8; 4]
517 421..422 'b': &[u8; 4]
518 425..433 'br"g\ h"': &[u8; 4]
519 451..452 'c': &[u8; 6]
520 455..467 'br#"x"\"yb"#': &[u8; 6]
526 fn infer_unary_op() {
531 fn test(x: SomeType) {
551 39..271 '{ ...lo"; }': ()
566 145..152 '!!!true': bool
567 146..152 '!!true': bool
568 147..152 '!true': bool
569 148..152 'true': bool
574 183..189 '!10u32': u32
575 184..189 '10u32': u32
579 211..216 '-3.14': f64
583 230..232 '-x': {unknown}
584 231..232 'x': SomeType
585 238..240 '!x': {unknown}
586 239..240 'x': SomeType
587 246..254 '-"hello"': {unknown}
588 247..254 '"hello"': &str
589 260..268 '!"hello"': {unknown}
590 261..268 '"hello"': &str
596 fn infer_backwards() {
599 fn takes_u32(x: u32) {}
601 struct S { i32_field: i32 }
603 fn test() -> &mut &f64 {
604 let a = unknown_function();
606 let b = unknown_function();
608 let c = unknown_function();
615 77..230 '{ ...t &c }': &mut &f64
617 91..107 'unknow...nction': {unknown}
618 91..109 'unknow...tion()': u32
619 115..124 'takes_u32': fn takes_u32(u32)
620 115..127 'takes_u32(a)': ()
623 141..157 'unknow...nction': {unknown}
624 141..159 'unknow...tion()': i32
625 165..183 'S { i3...d: b }': S
628 197..213 'unknow...nction': {unknown}
629 197..215 'unknow...tion()': f64
630 221..228 '&mut &c': &mut &f64
647 fn test2(self: &Self) {
663 87..108 '{ ... }': ()
665 132..152 '{ ... }': S
667 176..199 '{ ... }': S
668 186..193 'Self {}': S
674 fn infer_self_as_path() {
702 86..107 '{ ... }': ()
704 134..158 '{ ... }': ()
705 144..148 'Self': S2(isize) -> S2
706 144..151 'Self(1)': S2
708 184..230 '{ ... }': ()
709 194..202 'Self::V1': E
710 212..220 'Self::V2': V2(u32) -> E
711 212..223 'Self::V2(1)': E
718 fn infer_binary_op() {
721 fn f(x: bool) -> i32 {
727 let y = true || false;
730 let minus_forty: isize = -40isize;
731 let h = minus_forty <= CONST_2;
732 let c = f(z || y) + 5;
734 let g = minus_forty ^= i;
736 let ten_is_eleven = ten == some_num;
743 21..33 '{ 0i32 }': i32
745 53..369 '{ ... < 3 }': bool
748 67..73 'a && b': bool
752 87..100 'true || false': bool
753 95..100 'false': bool
756 114..120 'x == y': bool
760 134..140 'x != y': bool
762 150..161 'minus_forty': isize
763 171..179 '-40isize': isize
764 172..179 '40isize': isize
766 193..204 'minus_forty': isize
767 193..215 'minus_...ONST_2': bool
768 208..215 'CONST_2': isize
770 229..230 'f': fn f(bool) -> i32
771 229..238 'f(z || y)': i32
772 229..242 'f(z || y) + 5': i32
774 231..237 'z || y': bool
777 252..253 'd': {unknown}
778 256..257 'b': {unknown}
780 271..282 'minus_forty': isize
781 271..287 'minus_...y ^= i': ()
783 297..300 'ten': usize
785 322..335 'ten_is_eleven': bool
786 338..341 'ten': usize
787 338..353 'ten == some_num': bool
788 345..353 'some_num': usize
789 360..363 'ten': usize
790 360..367 'ten < 3': bool
797 fn infer_shift_op() {
806 10..47 '{ ...5u8; }': ()
808 16..27 '1u32 << 5u8': u32
811 33..44 '1u32 >> 5u8': u32
818 fn infer_field_autoderef() {
835 let a5 = &mut &&mut &&mut a;
839 fn test2(a1: *const A, a2: *mut A) {
846 49..212 '{ ...5.b; }': ()
856 112..114 'a3': &mut A
857 117..123 '&mut a': &mut A
859 129..131 'a3': &mut A
861 143..145 'a4': &&&&&&&A
862 148..156 '&&&&&&&a': &&&&&&&A
863 149..156 '&&&&&&a': &&&&&&A
864 150..156 '&&&&&a': &&&&&A
865 151..156 '&&&&a': &&&&A
866 152..156 '&&&a': &&&A
870 162..164 'a4': &&&&&&&A
872 176..178 'a5': &mut &&mut &&mut A
873 181..199 '&mut &...&mut a': &mut &&mut &&mut A
874 186..199 '&&mut &&mut a': &&mut &&mut A
875 187..199 '&mut &&mut a': &mut &&mut A
876 192..199 '&&mut a': &&mut A
877 193..199 '&mut a': &mut A
879 205..207 'a5': &mut &&mut &&mut A
881 223..225 'a1': *const A
882 237..239 'a2': *mut A
883 249..272 '{ ...2.b; }': ()
884 255..257 'a1': *const A
886 265..267 'a2': *mut A
893 fn infer_argument_autoderef() {
897 use core::ops::Deref;
901 fn foo(&self) -> &T {
908 impl<T> Deref for B<T> {
910 fn deref(&self) -> &Self::Target {
916 let t = A::foo(&&B(B(A(42))));
921 78..101 '{ ... }': &T
925 182..186 'self': &B<T>
926 205..228 '{ ... }': &T
927 215..222 '&self.0': &T
928 216..220 'self': &B<T>
930 242..280 '{ ...))); }': ()
932 256..262 'A::foo': fn foo<i32>(&A<i32>) -> &i32
933 256..277 'A::foo...42))))': &i32
934 263..276 '&&B(B(A(42)))': &&B<B<A<i32>>>
935 264..276 '&B(B(A(42)))': &B<B<A<i32>>>
936 265..266 'B': B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>>
937 265..276 'B(B(A(42)))': B<B<A<i32>>>
938 267..268 'B': B<A<i32>>(A<i32>) -> B<A<i32>>
939 267..275 'B(A(42))': B<A<i32>>
940 269..270 'A': A<i32>(i32) -> A<i32>
941 269..274 'A(42)': A<i32>
948 fn infer_method_argument_autoderef() {
952 use core::ops::Deref;
956 fn foo(&self, x: &A<T>) -> &T {
963 impl<T> Deref for B<T> {
965 fn deref(&self) -> &Self::Target {
971 let t = A(0 as *mut _).foo(&&B(B(a)));
977 93..114 '{ ... }': &T
981 105..108 'x.0': *mut T
982 195..199 'self': &B<T>
983 218..241 '{ ... }': &T
984 228..235 '&self.0': &T
985 229..233 'self': &B<T>
988 264..310 '{ ...))); }': ()
990 278..279 'A': A<i32>(*mut i32) -> A<i32>
991 278..292 'A(0 as *mut _)': A<i32>
992 278..307 'A(0 as...B(a)))': &i32
994 280..291 '0 as *mut _': *mut i32
995 297..306 '&&B(B(a))': &&B<B<A<i32>>>
996 298..306 '&B(B(a))': &B<B<A<i32>>>
997 299..300 'B': B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>>
998 299..306 'B(B(a))': B<B<A<i32>>>
999 301..302 'B': B<A<i32>>(A<i32>) -> B<A<i32>>
1000 301..305 'B(a)': B<A<i32>>
1001 303..304 'a': A<i32>
1007 fn infer_in_elseif() {
1010 struct Foo { field: i32 }
1021 44..108 '{ ... } }': ()
1022 50..106 'if tru... }': ()
1025 72..106 'if fal... }': i32
1026 75..80 'false': bool
1027 81..106 '{ ... }': i32
1029 91..100 'foo.field': i32
1035 fn infer_if_match_with_return() {
1049 let _x3 = match true {
1055 let _x4 = match true {
1062 9..322 '{ ... }; }': ()
1064 25..79 'if tru... }': i32
1066 33..50 '{ ... }': i32
1068 56..79 '{ ... }': i32
1071 95..148 'if tru... }': i32
1072 98..102 'true': bool
1073 103..120 '{ ... }': i32
1075 126..148 '{ ... }': !
1076 136..142 'return': !
1078 164..246 'match ... }': i32
1079 170..174 'true': bool
1080 185..189 'true': bool
1081 185..189 'true': bool
1084 209..240 '{ ... }': i32
1085 223..229 'return': !
1087 262..319 'match ... }': i32
1088 268..272 'true': bool
1089 283..287 'true': bool
1090 283..287 'true': bool
1093 307..313 'return': !
1099 fn infer_inherent_method() {
1105 fn foo(self, x: u32) -> i32 {}
1110 pub fn bar(&self, x: u64) -> i64 {}
1128 153..201 '{ ...(1); }': ()
1130 159..167 'a.foo(1)': i32
1132 173..184 '(&a).bar(1)': i64
1137 190..198 'a.bar(1)': i64
1144 fn infer_inherent_method_str() {
1149 fn foo(&self) -> i32 {}
1159 68..88 '{ ...o(); }': ()
1160 74..79 '"foo"': &str
1161 74..85 '"foo".foo()': i32
1170 fn test(x: &str, y: isize) {
1171 let a: (u32, &str) = (1, "a");
1182 27..169 '{ ...d"); }': ()
1183 37..38 'a': (u32, &str)
1184 54..62 '(1, "a")': (u32, &str)
1187 72..73 'b': ((u32, &str), &str)
1188 76..82 '(a, x)': ((u32, &str), &str)
1189 77..78 'a': (u32, &str)
1191 92..93 'c': (isize, &str)
1192 96..102 '(y, x)': (isize, &str)
1195 112..113 'd': ((isize, &str), &str)
1196 116..122 '(c, x)': ((isize, &str), &str)
1197 117..118 'c': (isize, &str)
1199 132..133 'e': (i32, &str)
1200 136..144 '(1, "e")': (i32, &str)
1202 140..143 '"e"': &str
1203 154..155 'f': ((i32, &str), &str)
1204 158..166 '(e, "d")': ((i32, &str), &str)
1205 159..160 'e': (i32, &str)
1206 162..165 '"d"': &str
1215 fn test(x: &str, y: isize) {
1220 let d = [y, 1, 2, 3];
1221 let d = [1, y, 2, 3];
1230 let x: [u8; 0] = [];
1231 // FIXME: requires const evaluation/taking type from rhs somehow
1232 let y: [u8; 2+2] = [1,2,3,4];
1238 27..395 '{ ...,4]; }': ()
1239 37..38 'a': [&str; 1]
1240 41..44 '[x]': [&str; 1]
1242 54..55 'b': [[&str; 1]; 2]
1243 58..64 '[a, a]': [[&str; 1]; 2]
1244 59..60 'a': [&str; 1]
1245 62..63 'a': [&str; 1]
1246 74..75 'c': [[[&str; 1]; 2]; 2]
1247 78..84 '[b, b]': [[[&str; 1]; 2]; 2]
1248 79..80 'b': [[&str; 1]; 2]
1249 82..83 'b': [[&str; 1]; 2]
1250 95..96 'd': [isize; 4]
1251 99..111 '[y, 1, 2, 3]': [isize; 4]
1256 121..122 'd': [isize; 4]
1257 125..137 '[1, y, 2, 3]': [isize; 4]
1262 147..148 'e': [isize; 1]
1263 151..154 '[y]': [isize; 1]
1265 164..165 'f': [[isize; 4]; 2]
1266 168..174 '[d, d]': [[isize; 4]; 2]
1267 169..170 'd': [isize; 4]
1268 172..173 'd': [isize; 4]
1269 184..185 'g': [[isize; 1]; 2]
1270 188..194 '[e, e]': [[isize; 1]; 2]
1271 189..190 'e': [isize; 1]
1272 192..193 'e': [isize; 1]
1273 205..206 'h': [i32; 2]
1274 209..215 '[1, 2]': [i32; 2]
1277 225..226 'i': [&str; 2]
1278 229..239 '["a", "b"]': [&str; 2]
1279 230..233 '"a"': &str
1280 235..238 '"b"': &str
1281 250..251 'b': [[&str; 1]; 2]
1282 254..264 '[a, ["b"]]': [[&str; 1]; 2]
1283 255..256 'a': [&str; 1]
1284 258..263 '["b"]': [&str; 1]
1285 259..262 '"b"': &str
1286 274..275 'x': [u8; 0]
1287 287..289 '[]': [u8; 0]
1288 368..369 'y': [u8; _]
1289 383..392 '[1,2,3,4]': [u8; 4]
1299 fn infer_struct_generics() {
1306 fn test(a1: A<u32>, i: i32) {
1308 let a2 = A { x: i };
1310 let a3 = A::<i128> { x: 1 };
1317 55..146 '{ ...3.x; }': ()
1321 80..90 'A { x: i }': A<i32>
1325 110..112 'a3': A<i128>
1326 115..133 'A::<i1...x: 1 }': A<i128>
1328 139..141 'a3': A<i128>
1329 139..143 'a3.x': i128
1335 fn infer_tuple_struct_generics() {
1339 enum Option<T> { Some(T), None }
1348 let x: Option<i64> = None;
1352 75..183 '{ ...one; }': ()
1353 81..82 'A': A<i32>(i32) -> A<i32>
1354 81..86 'A(42)': A<i32>
1356 92..93 'A': A<u128>(u128) -> A<u128>
1357 92..101 'A(42u128)': A<u128>
1358 94..100 '42u128': u128
1359 107..111 'Some': Some<&str>(&str) -> Option<&str>
1360 107..116 'Some("x")': Option<&str>
1361 112..115 '"x"': &str
1362 122..134 'Option::Some': Some<&str>(&str) -> Option<&str>
1363 122..139 'Option...e("x")': Option<&str>
1364 135..138 '"x"': &str
1365 145..149 'None': Option<{unknown}>
1366 159..160 'x': Option<i64>
1367 176..180 'None': Option<i64>
1373 fn infer_function_generics() {
1376 fn id<T>(t: T) -> T { t }
1388 37..97 '{ ...(1); }': ()
1389 43..45 'id': fn id<u32>(u32) -> u32
1390 43..51 'id(1u32)': u32
1392 57..67 'id::<i128>': fn id<i128>(i128) -> i128
1393 57..70 'id::<i128>(1)': i128
1396 89..91 'id': fn id<u64>(u64) -> u64
1404 fn infer_impl_generics_basic() {
1411 impl<Y, X> A<X, Y> {
1418 fn z<T>(self, t: T) -> (X, Y, T) {
1424 let a = A { x: 1u64, y: 1i64 };
1432 73..77 'self': A<X, Y>
1433 84..106 '{ ... }': X
1434 94..98 'self': A<X, Y>
1436 116..120 'self': A<X, Y>
1437 127..149 '{ ... }': Y
1438 137..141 'self': A<X, Y>
1439 137..143 'self.y': Y
1440 162..166 'self': A<X, Y>
1442 187..222 '{ ... }': (X, Y, T)
1443 197..216 '(self.....y, t)': (X, Y, T)
1444 198..202 'self': A<X, Y>
1445 198..204 'self.x': X
1446 206..210 'self': A<X, Y>
1447 206..212 'self.y': Y
1449 244..341 '{ ...(1); }': ()
1450 254..255 'a': A<u64, i64>
1451 258..280 'A { x:...1i64 }': A<u64, i64>
1452 265..269 '1u64': u64
1453 274..278 '1i64': i64
1454 286..287 'a': A<u64, i64>
1455 286..291 'a.x()': u64
1456 297..298 'a': A<u64, i64>
1457 297..302 'a.y()': i64
1458 308..309 'a': A<u64, i64>
1459 308..318 'a.z(1i128)': (u64, i64, i128)
1460 312..317 '1i128': i128
1461 324..325 'a': A<u64, i64>
1462 324..338 'a.z::<u128>(1)': (u64, i64, u128)
1469 fn infer_impl_generics_with_autoderef() {
1477 fn as_ref(&self) -> Option<&T> {}
1479 fn test(o: Option<u32>) {
1485 77..81 'self': &Option<T>
1487 110..111 'o': Option<u32>
1488 126..164 '{ ...f(); }': ()
1489 132..145 '(&o).as_ref()': Option<&u32>
1490 133..135 '&o': &Option<u32>
1491 134..135 'o': Option<u32>
1492 151..152 'o': Option<u32>
1493 151..161 'o.as_ref()': Option<&u32>
1499 fn infer_generic_chain() {
1510 fn id<T>(t: T) -> T { t }
1515 let a = A { x: id(y) };
1522 52..56 'self': A<T2>
1523 64..86 '{ ... }': T2
1524 74..78 'self': A<T2>
1529 134..254 '{ ....x() }': i128
1533 163..165 'id': fn id<i128>(i128) -> i128
1534 163..168 'id(x)': i128
1536 178..179 'a': A<i128>
1537 182..196 'A { x: id(y) }': A<i128>
1538 189..191 'id': fn id<i128>(i128) -> i128
1539 189..194 'id(y)': i128
1542 210..212 'id': fn id<i128>(i128) -> i128
1543 210..217 'id(a.x)': i128
1544 213..214 'a': A<i128>
1545 213..216 'a.x': i128
1546 227..228 'b': A<i128>
1547 231..241 'A { x: z }': A<i128>
1549 247..248 'b': A<i128>
1550 247..252 'b.x()': i128
1556 fn infer_associated_const() {
1577 impl Trait for TraitTest {
1582 let x = Struct::FOO;
1584 let z = TraitTest::ID;
1591 228..306 '{ ...:ID; }': ()
1593 242..253 'Struct::FOO': u32
1595 267..276 'Enum::BAR': u32
1597 290..303 'TraitTest::ID': u32
1603 fn infer_type_alias() {
1606 struct A<X, Y> { x: X, y: Y }
1607 type Foo = A<u32, i128>;
1608 type Bar<T> = A<T, u128>;
1609 type Baz<U, V> = A<V, U>;
1610 fn test(x: Foo, y: Bar<&str>, z: Baz<i8, u8>) {
1620 115..116 'x': A<u32, i128>
1621 123..124 'y': A<&str, u128>
1622 137..138 'z': A<u8, i8>
1623 153..210 '{ ...z.y; }': ()
1624 159..160 'x': A<u32, i128>
1626 168..169 'x': A<u32, i128>
1627 168..171 'x.y': i128
1628 177..178 'y': A<&str, u128>
1629 177..180 'y.x': &str
1630 186..187 'y': A<&str, u128>
1631 186..189 'y.y': u128
1632 195..196 'z': A<u8, i8>
1634 204..205 'z': A<u8, i8>
1641 fn recursive_type_alias() {
1650 58..59 'x': {unknown}
1657 fn infer_type_param() {
1660 fn id<T>(x: T) -> T {
1664 fn clone<T>(x: &T) -> T {
1671 let x: bool = clone(z);
1683 77..157 '{ ...(1); }': ()
1686 102..104 'id': fn id<u32>(u32) -> u32
1687 102..107 'id(y)': u32
1690 127..132 'clone': fn clone<bool>(&bool) -> bool
1691 127..135 'clone(z)': bool
1693 141..151 'id::<i128>': fn id<i128>(i128) -> i128
1694 141..154 'id::<i128>(1)': i128
1705 impl Foo { const ASSOC_CONST: u32 = 0; }
1706 const GLOBAL_CONST: u32 = 101;
1708 const LOCAL_CONST: u32 = 99;
1709 let x = LOCAL_CONST;
1710 let z = GLOBAL_CONST;
1711 let id = Foo::ASSOC_CONST;
1717 94..212 '{ ...NST; }': ()
1719 141..152 'LOCAL_CONST': u32
1721 166..178 'GLOBAL_CONST': u32
1723 193..209 'Foo::A..._CONST': u32
1733 static GLOBAL_STATIC: u32 = 101;
1734 static mut GLOBAL_STATIC_MUT: u32 = 101;
1736 static LOCAL_STATIC: u32 = 99;
1737 static mut LOCAL_STATIC_MUT: u32 = 99;
1738 let x = LOCAL_STATIC;
1739 let y = LOCAL_STATIC_MUT;
1740 let z = GLOBAL_STATIC;
1741 let w = GLOBAL_STATIC_MUT;
1747 84..279 '{ ...MUT; }': ()
1749 176..188 'LOCAL_STATIC': u32
1751 202..218 'LOCAL_...IC_MUT': u32
1753 232..245 'GLOBAL_STATIC': u32
1755 259..276 'GLOBAL...IC_MUT': u32
1763 fn shadowing_primitive() {
1769 impl i32 { fn foo(&self) -> Foo { Foo } }
1780 fn shadowing_primitive_with_inner_items() {
1786 impl i32 { fn foo(&self) -> Foo { Foo } }
1798 fn not_shadowing_primitive_by_module() {
1806 fn foo() -> &'static str { "" }
1816 fn not_shadowing_module_by_primitive() {
1824 fn foo() -> &'static str { "" }
1833 // This test is actually testing the shadowing behavior within hir_def. It
1834 // lives here because the testing infrastructure in hir_def isn't currently
1835 // capable of asserting the necessary conditions.
1837 fn should_be_shadowing_imports() {
1841 pub fn foo() -> i8 {0}
1842 pub struct foo { a: i8 }
1844 mod b { pub fn foo () -> u8 {0} }
1845 mod c { pub struct foo { a: u8 } }
1847 pub use super::a::*;
1848 pub use super::c::foo;
1849 pub use super::b::foo;
1862 fn closure_return() {
1866 let x = || -> usize { return 1; };
1870 16..58 '{ ...; }; }': ()
1871 26..27 'x': || -> usize
1872 30..55 '|| -> ...n 1; }': || -> usize
1873 42..55 '{ return 1; }': usize
1874 44..52 'return 1': !
1881 fn closure_return_unit() {
1885 let x = || { return; };
1889 16..47 '{ ...; }; }': ()
1890 26..27 'x': || -> ()
1891 30..44 '|| { return; }': || -> ()
1892 33..44 '{ return; }': ()
1899 fn closure_return_inferred() {
1903 let x = || { "test" };
1907 16..46 '{ ..." }; }': ()
1908 26..27 'x': || -> &str
1909 30..43 '|| { "test" }': || -> &str
1910 33..43 '{ "test" }': &str
1911 35..41 '"test"': &str
1917 fn fn_pointer_return() {
1925 let vtable = Vtable { method: || {} };
1926 let m = vtable.method;
1930 47..120 '{ ...hod; }': ()
1931 57..63 'vtable': Vtable
1932 66..90 'Vtable...| {} }': Vtable
1933 83..88 '|| {}': || -> ()
1936 104..110 'vtable': Vtable
1937 104..117 'vtable.method': fn()
1943 fn effects_smoke_test() {
1947 let x = unsafe { 92 };
1948 let y = async { async { () }.await };
1950 let w = const { 92 };
1954 #[prelude_import] use future::*;
1957 #[lang = "future_trait"]
1958 pub trait Future { type Output; }
1962 16..162 '{ ...2 }; }': ()
1964 30..43 'unsafe { 92 }': i32
1965 37..43 '{ 92 }': i32
1967 53..54 'y': impl Future<Output = ()>
1968 57..85 'async ...wait }': impl Future<Output = ()>
1969 63..85 '{ asyn...wait }': ()
1970 65..77 'async { () }': impl Future<Output = ()>
1971 65..83 'async ....await': ()
1974 95..96 'z': {unknown}
1975 99..109 'try { () }': {unknown}
1976 103..109 '{ () }': ()
1979 123..135 'const { 92 }': i32
1980 129..135 '{ 92 }': i32
1983 153..159 '{ 92 }': i32
1990 fn infer_generic_from_later_assignment() {
1993 enum Option<T> { Some(T), None }
2004 59..129 '{ ... } }': ()
2005 69..76 'mut end': Option<bool>
2006 79..83 'None': Option<bool>
2007 89..127 'loop {... }': !
2008 94..127 '{ ... }': ()
2009 104..107 'end': Option<bool>
2010 104..120 'end = ...(true)': ()
2011 110..114 'Some': Some<bool>(bool) -> Option<bool>
2012 110..120 'Some(true)': Option<bool>
2013 115..119 'true': bool
2019 fn infer_loop_break_with_val() {
2022 enum Option<T> { Some(T), None }
2036 59..168 '{ ... }; }': ()
2037 69..70 'x': Option<bool>
2038 73..165 'loop {... }': Option<bool>
2039 78..165 '{ ... }': ()
2040 88..132 'if fal... }': ()
2041 91..96 'false': bool
2042 97..132 '{ ... }': ()
2043 111..121 'break None': !
2044 117..121 'None': Option<bool>
2045 142..158 'break ...(true)': !
2046 148..152 'Some': Some<bool>(bool) -> Option<bool>
2047 148..158 'Some(true)': Option<bool>
2048 153..157 'true': bool
2054 fn infer_loop_break_without_val() {
2057 enum Option<T> { Some(T), None }
2069 59..136 '{ ... }; }': ()
2071 73..133 'loop {... }': ()
2072 78..133 '{ ... }': ()
2073 88..127 'if fal... }': ()
2074 91..96 'false': bool
2075 97..127 '{ ... }': ()
2082 fn infer_labelled_break_with_val() {
2086 let _x = || 'outer: loop {
2087 let inner = 'inner: loop {
2088 let i = Default::default();
2089 if (break 'outer i) {
2090 loop { break 'inner 5i8; };
2101 9..335 '{ ... }; }': ()
2102 19..21 '_x': || -> bool
2103 24..332 '|| 'ou... }': || -> bool
2104 27..332 ''outer... }': bool
2105 40..332 '{ ... }': ()
2107 62..300 ''inner... }': i8
2108 75..300 '{ ... }': ()
2110 97..113 'Defaul...efault': {unknown}
2111 97..115 'Defaul...ault()': bool
2112 129..269 'if (br... }': ()
2113 133..147 'break 'outer i': !
2115 149..208 '{ ... }': ()
2116 167..193 'loop {...5i8; }': !
2117 172..193 '{ brea...5i8; }': ()
2118 174..190 'break ...er 5i8': !
2120 214..269 'if tru... }': ()
2121 217..221 'true': bool
2122 222..269 '{ ... }': ()
2123 240..254 'break 'inner 6': !
2125 282..289 'break 7': !
2127 310..325 'break inner < 8': !
2128 316..321 'inner': i8
2129 316..325 'inner < 8': bool
2136 fn infer_labelled_block_break_with_val() {
2139 fn default<T>() -> T { loop {} }
2142 let inner = 'inner: {
2144 if (break 'outer i) {
2149 break 'inner 'innermost: { 0 };
2152 break 'outer inner < 8;
2157 21..32 '{ loop {} }': T
2160 42..381 '{ ... }; }': ()
2162 65..378 '{ ... }': bool
2164 95..339 '{ ... }': i8
2166 117..124 'default': fn default<bool>() -> bool
2167 117..126 'default()': bool
2168 140..270 'if (br... }': ()
2169 144..158 'break 'outer i': !
2171 160..209 '{ ... }': ()
2172 178..194 'break ...er 5i8': !
2174 215..270 'if tru... }': ()
2175 218..222 'true': bool
2176 223..270 '{ ... }': ()
2177 241..255 'break 'inner 6': !
2179 283..313 'break ... { 0 }': !
2180 308..313 '{ 0 }': i8
2183 349..371 'break ...er < 8': !
2184 362..367 'inner': i8
2185 362..371 'inner < 8': bool
2192 fn generic_default() {
2195 struct Thing<T = ()> { t: T }
2196 enum OtherThing<T = ()> {
2201 fn test(t1: Thing, t2: OtherThing, t3: Thing<i32>, t4: OtherThing<i32>) {
2205 OtherThing::One { t } => { t; },
2206 OtherThing::Two(t) => { t; },
2209 OtherThing::One { t } => { t; },
2210 OtherThing::Two(t) => { t; },
2215 97..99 't1': Thing<()>
2216 108..110 't2': OtherThing<()>
2217 124..126 't3': Thing<i32>
2218 140..142 't4': OtherThing<i32>
2219 161..384 '{ ... } }': ()
2220 167..169 't1': Thing<()>
2222 177..179 't3': Thing<i32>
2223 177..181 't3.t': i32
2224 187..282 'match ... }': ()
2225 193..195 't2': OtherThing<()>
2226 206..227 'OtherT... { t }': OtherThing<()>
2228 231..237 '{ t; }': ()
2230 247..265 'OtherT...Two(t)': OtherThing<()>
2232 269..275 '{ t; }': ()
2234 287..382 'match ... }': ()
2235 293..295 't4': OtherThing<i32>
2236 306..327 'OtherT... { t }': OtherThing<i32>
2238 331..337 '{ t; }': ()
2240 347..365 'OtherT...Two(t)': OtherThing<i32>
2242 369..375 '{ t; }': ()
2249 fn generic_default_in_struct_literal() {
2252 struct Thing<T = ()> { t: T }
2253 enum OtherThing<T = ()> {
2259 let x = Thing { t: loop {} };
2260 let y = Thing { t: () };
2261 let z = Thing { t: 1i32 };
2262 if let Thing { t } = z {
2266 let a = OtherThing::One { t: 1i32 };
2267 let b = OtherThing::Two(1i32);
2271 99..319 '{ ...32); }': ()
2272 109..110 'x': Thing<!>
2273 113..133 'Thing ...p {} }': Thing<!>
2274 124..131 'loop {}': !
2276 143..144 'y': Thing<()>
2277 147..162 'Thing { t: () }': Thing<()>
2279 172..173 'z': Thing<i32>
2280 176..193 'Thing ...1i32 }': Thing<i32>
2281 187..191 '1i32': i32
2282 199..240 'if let... }': ()
2283 206..217 'Thing { t }': Thing<i32>
2285 220..221 'z': Thing<i32>
2286 222..240 '{ ... }': ()
2288 250..251 'a': OtherThing<i32>
2289 254..281 'OtherT...1i32 }': OtherThing<i32>
2290 275..279 '1i32': i32
2291 291..292 'b': OtherThing<i32>
2292 295..310 'OtherThing::Two': Two<i32>(i32) -> OtherThing<i32>
2293 295..316 'OtherT...(1i32)': OtherThing<i32>
2294 311..315 '1i32': i32
2300 fn generic_default_depending_on_other_type_arg() {
2301 // FIXME: the {unknown} is a bug
2304 struct Thing<T = u128, F = fn() -> T> { t: T }
2306 fn test(t1: Thing<u32>, t2: Thing) {
2309 Thing::<_> { t: 1u32 };
2313 56..58 't1': Thing<u32, fn() -> u32>
2314 72..74 't2': Thing<u128, fn() -> u128>
2315 83..130 '{ ...2 }; }': ()
2316 89..91 't1': Thing<u32, fn() -> u32>
2317 97..99 't2': Thing<u128, fn() -> u128>
2318 105..127 'Thing:...1u32 }': Thing<u32, fn() -> {unknown}>
2319 121..125 '1u32': u32
2325 fn generic_default_depending_on_other_type_arg_forward() {
2326 // the {unknown} here is intentional, as defaults are not allowed to
2327 // refer to type parameters coming later
2330 struct Thing<F = fn() -> T, T = u128> { t: T }
2332 fn test(t1: Thing) {
2337 56..58 't1': Thing<fn() -> {unknown}, u128>
2338 67..78 '{ t1; }': ()
2339 73..75 't1': Thing<fn() -> {unknown}, u128>
2345 fn infer_operator_overload() {
2346 cov_mark::check!(infer_expr_inner_binary_operator_overload);
2350 struct V2([f32; 2]);
2353 pub trait Add<Rhs = Self> {
2354 /// The resulting type after applying the `+` operator.
2357 /// Performs the `+` operation.
2359 fn add(self, rhs: Rhs) -> Self::Output;
2362 impl Add<V2> for V2 {
2365 fn add(self, rhs: V2) -> V2 {
2366 let x = self.0[0] + rhs.0[0];
2367 let y = self.0[1] + rhs.0[1];
2373 let va = V2([0.0, 1.0]);
2374 let vb = V2([0.0, 1.0]);
2381 207..211 'self': Self
2385 320..422 '{ ... }': V2
2388 338..344 'self.0': [f32; 2]
2389 338..347 'self.0[0]': {unknown}
2390 338..358 'self.0...s.0[0]': f32
2393 350..355 'rhs.0': [f32; 2]
2394 350..358 'rhs.0[0]': {unknown}
2398 376..382 'self.0': [f32; 2]
2399 376..385 'self.0[1]': {unknown}
2400 376..396 'self.0...s.0[1]': f32
2403 388..393 'rhs.0': [f32; 2]
2404 388..396 'rhs.0[1]': {unknown}
2406 406..408 'V2': V2([f32; 2]) -> V2
2407 406..416 'V2([x, y])': V2
2408 409..415 '[x, y]': [f32; 2]
2411 436..519 '{ ... vb; }': ()
2413 451..453 'V2': V2([f32; 2]) -> V2
2414 451..465 'V2([0.0, 1.0])': V2
2415 454..464 '[0.0, 1.0]': [f32; 2]
2419 480..482 'V2': V2([f32; 2]) -> V2
2420 480..494 'V2([0.0, 1.0])': V2
2421 483..493 '[0.0, 1.0]': [f32; 2]
2426 509..516 'va + vb': V2
2433 fn infer_const_params() {
2436 fn foo<const FOO: usize>() {
2441 27..49 '{ ...FOO; }': ()
2449 fn infer_inner_type() {
2453 struct S { field: u32 }
2454 let s = S { field: 0 };
2459 9..89 '{ ...eld; }': ()
2461 51..65 'S { field: 0 }': S
2465 79..86 's.field': u32
2471 fn infer_nested_inner_type() {
2476 let s = S { field: 0 };
2479 struct S { field: u32 }
2483 9..109 '{ ...32 } }': ()
2484 15..79 '{ ... }': ()
2486 33..47 'S { field: 0 }': S
2490 65..72 's.field': u32
2496 fn inner_use_enum_rename() {
2513 34..123 '{ ... } }': ()
2515 71..78 'R::Info': Request
2516 84..121 'match ... }': ()
2518 102..109 'R::Info': Request
2532 pub trait Unsize<T: ?Sized> {}
2534 #[lang = "coerce_unsized"]
2535 pub trait CoerceUnsized<T> {}
2537 pub unsafe trait Allocator {}
2540 unsafe impl Allocator for Global {}
2542 #[lang = "owned_box"]
2544 pub struct Box<T: ?Sized, A: Allocator = Global>;
2546 impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<Box<U, A>> for Box<T, A> {}
2548 pub struct Vec<T, A: Allocator = Global> {}
2553 #[lang = "slice_alloc"]
2555 pub fn into_vec<A: Allocator>(self: Box<Self, A>) -> Vec<T, A> {
2561 let vec = <[_]>::into_vec(box [1i32]);
2565 569..573 'self': Box<[T], A>
2566 602..634 '{ ... }': Vec<T, A>
2567 612..628 'unimpl...ted!()': Vec<T, A>
2568 648..694 '{ ...2]); }': ()
2569 658..661 'vec': Vec<i32, Global>
2570 664..679 '<[_]>::into_vec': fn into_vec<i32, Global>(Box<[i32], Global>) -> Vec<i32, Global>
2571 664..691 '<[_]>:...1i32])': Vec<i32, Global>
2572 680..690 'box [1i32]': Box<[i32; 1], Global>
2573 684..690 '[1i32]': [i32; 1]
2574 685..689 '1i32': i32
2580 fn cfgd_out_assoc_items() {
2599 fn infer_type_alias_variant() {
2610 Qux::Bar(bar) => (),
2611 Qux::Baz { baz } => (),
2616 72..166 '{ ... } }': ()
2617 78..164 'match ... }': ()
2618 84..92 'Foo::Bar': Bar(i32) -> Foo
2619 84..95 'Foo::Bar(3)': Foo
2621 106..119 'Qux::Bar(bar)': Foo
2624 135..151 'Qux::B... baz }': Foo
2632 fn infer_boxed_self_receiver() {
2638 fn deref(&self) -> &Self::Target;
2643 impl<T> Deref for Box<T> {
2645 fn deref(&self) -> &Self::Target;
2651 fn get_inner<'a>(self: &'a Box<Self>) -> &'a T {}
2653 fn get_self<'a>(self: &'a Box<Self>) -> &'a Self {}
2655 fn into_inner(self: Box<Self>) -> Self {}
2659 let boxed = Box(Foo(0_i32));
2661 let bad1 = boxed.get_inner();
2662 let good1 = Foo::get_inner(&boxed);
2664 let bad2 = boxed.get_self();
2665 let good2 = Foo::get_self(&boxed);
2667 let inner = boxed.into_inner();
2671 67..71 'self': &Self
2672 175..179 'self': &Box<T>
2673 259..263 'self': &Box<Foo<T>>
2675 313..317 'self': &Box<Foo<T>>
2677 368..372 'self': Box<Foo<T>>
2679 409..630 '{ ...r(); }': ()
2680 419..424 'boxed': Box<Foo<i32>>
2681 427..430 'Box': Box<Foo<i32>>(Foo<i32>) -> Box<Foo<i32>>
2682 427..442 'Box(Foo(0_i32))': Box<Foo<i32>>
2683 431..434 'Foo': Foo<i32>(i32) -> Foo<i32>
2684 431..441 'Foo(0_i32)': Foo<i32>
2685 435..440 '0_i32': i32
2686 453..457 'bad1': &i32
2687 460..465 'boxed': Box<Foo<i32>>
2688 460..477 'boxed....nner()': &i32
2689 487..492 'good1': &i32
2690 495..509 'Foo::get_inner': fn get_inner<i32>(&Box<Foo<i32>>) -> &i32
2691 495..517 'Foo::g...boxed)': &i32
2692 510..516 '&boxed': &Box<Foo<i32>>
2693 511..516 'boxed': Box<Foo<i32>>
2694 528..532 'bad2': &Foo<i32>
2695 535..540 'boxed': Box<Foo<i32>>
2696 535..551 'boxed....self()': &Foo<i32>
2697 561..566 'good2': &Foo<i32>
2698 569..582 'Foo::get_self': fn get_self<i32>(&Box<Foo<i32>>) -> &Foo<i32>
2699 569..590 'Foo::g...boxed)': &Foo<i32>
2700 583..589 '&boxed': &Box<Foo<i32>>
2701 584..589 'boxed': Box<Foo<i32>>
2702 601..606 'inner': Foo<i32>
2703 609..614 'boxed': Box<Foo<i32>>
2704 609..627 'boxed....nner()': Foo<i32>
2713 //- /main.rs edition:2015 crate:main deps:core
2719 //- /core.rs crate:core