1 use expect_test
::expect
;
2 use test_utils
::{bench, bench_fixture, skip_slow_tests}
;
4 use crate::tests
::check_infer_with_mismatches
;
6 use super::{check_infer, check_types}
;
12 //- /main.rs crate:main deps:foo cfg:test
18 fn foo1(&self) -> i32 { 0 }
23 fn foo2(&self) -> i32 { 0 }
27 let t = (S.foo1(), S.foo2(), T.foo3(), T.foo4());
29 } //^ (i32, {unknown}, i32, {unknown})
36 pub fn foo3(&self) -> i32 { 0 }
41 pub fn foo4(&self) -> i32 { 0 }
48 fn infer_macros_expanded() {
54 ($($item:expr),*) => {
66 !0..17 '{Foo(v...,2,])}': Foo
67 !1..4 'Foo': Foo({unknown}) -> Foo
68 !1..16 'Foo(vec![1,2,])': Foo
69 !5..15 'vec![1,2,]': {unknown}
70 155..181 '{ ...,2); }': ()
77 fn infer_legacy_textual_scoped_macros_expanded() {
85 ($($item:expr),*) => {
95 let y = crate::foo!(1,2);
99 !0..17 '{Foo(v...,2,])}': Foo
100 !1..4 'Foo': Foo({unknown}) -> Foo
101 !1..16 'Foo(vec![1,2,])': Foo
102 !5..15 'vec![1,2,]': {unknown}
103 194..250 '{ ...,2); }': ()
105 227..228 'y': {unknown}
106 231..247 'crate:...!(1,2)': {unknown}
112 fn infer_path_qualified_macros_expanded() {
121 pub use super::foo as bar;
125 let x = crate::foo!();
132 110..163 '{ ...!(); }': ()
140 fn expr_macro_def_expanded_in_various_places() {
143 //- minicore: iterator
151 spam!().spam(spam!());
158 _ if spam!() => spam!(),
161 Spam { spam: spam!() };
172 !0..6 '1isize': isize
173 !0..6 '1isize': isize
174 !0..6 '1isize': isize
175 !0..6 '1isize': isize
176 !0..6 '1isize': isize
177 !0..6 '1isize': isize
178 !0..6 '1isize': isize
179 !0..6 '1isize': isize
180 !0..6 '1isize': isize
181 !0..6 '1isize': isize
182 !0..6 '1isize': isize
183 !0..6 '1isize': isize
184 !0..6 '1isize': isize
185 !0..6 '1isize': isize
186 !0..6 '1isize': isize
187 !0..6 '1isize': isize
188 !0..6 '1isize': isize
189 !0..6 '1isize': isize
190 !0..6 '1isize': isize
191 !0..6 '1isize': isize
192 !0..6 '1isize': isize
193 !0..6 '1isize': isize
194 !0..6 '1isize': isize
195 !0..6 '1isize': isize
196 !0..6 '1isize': isize
197 39..442 '{ ...!(); }': ()
198 73..94 'spam!(...am!())': {unknown}
199 100..119 'for _ ...!() {}': fn into_iter<isize>(isize) -> <isize as IntoIterator>::IntoIter
200 100..119 'for _ ...!() {}': IntoIterator::IntoIter<isize>
201 100..119 'for _ ...!() {}': !
202 100..119 'for _ ...!() {}': IntoIterator::IntoIter<isize>
203 100..119 'for _ ...!() {}': &mut IntoIterator::IntoIter<isize>
204 100..119 'for _ ...!() {}': fn next<IntoIterator::IntoIter<isize>>(&mut IntoIterator::IntoIter<isize>) -> Option<<IntoIterator::IntoIter<isize> as Iterator>::Item>
205 100..119 'for _ ...!() {}': Option<IntoIterator::Item<isize>>
206 100..119 'for _ ...!() {}': ()
207 100..119 'for _ ...!() {}': ()
208 100..119 'for _ ...!() {}': ()
209 104..105 '_': IntoIterator::Item<isize>
211 124..134 '|| spam!()': impl Fn() -> isize
212 140..156 'while ...!() {}': !
213 140..156 'while ...!() {}': ()
214 140..156 'while ...!() {}': ()
216 161..174 'break spam!()': !
217 180..194 'return spam!()': !
218 200..254 'match ... }': isize
220 259..275 'spam!(...am!())': {unknown}
221 281..303 'Spam {...m!() }': {unknown}
222 309..325 'spam!(...am!()]': {unknown}
223 350..366 'spam!(... usize': usize
224 372..380 '&spam!()': &isize
225 386..394 '-spam!()': isize
226 400..416 'spam!(...pam!()': {unknown}
227 422..439 'spam!(...pam!()': isize
233 fn expr_macro_rules_expanded_in_various_places() {
236 //- minicore: iterator
244 spam!().spam(spam!());
251 _ if spam!() => spam!(),
254 Spam { spam: spam!() };
265 !0..6 '1isize': isize
266 !0..6 '1isize': isize
267 !0..6 '1isize': isize
268 !0..6 '1isize': isize
269 !0..6 '1isize': isize
270 !0..6 '1isize': isize
271 !0..6 '1isize': isize
272 !0..6 '1isize': isize
273 !0..6 '1isize': isize
274 !0..6 '1isize': isize
275 !0..6 '1isize': isize
276 !0..6 '1isize': isize
277 !0..6 '1isize': isize
278 !0..6 '1isize': isize
279 !0..6 '1isize': isize
280 !0..6 '1isize': isize
281 !0..6 '1isize': isize
282 !0..6 '1isize': isize
283 !0..6 '1isize': isize
284 !0..6 '1isize': isize
285 !0..6 '1isize': isize
286 !0..6 '1isize': isize
287 !0..6 '1isize': isize
288 !0..6 '1isize': isize
289 !0..6 '1isize': isize
290 53..456 '{ ...!(); }': ()
291 87..108 'spam!(...am!())': {unknown}
292 114..133 'for _ ...!() {}': fn into_iter<isize>(isize) -> <isize as IntoIterator>::IntoIter
293 114..133 'for _ ...!() {}': IntoIterator::IntoIter<isize>
294 114..133 'for _ ...!() {}': !
295 114..133 'for _ ...!() {}': IntoIterator::IntoIter<isize>
296 114..133 'for _ ...!() {}': &mut IntoIterator::IntoIter<isize>
297 114..133 'for _ ...!() {}': fn next<IntoIterator::IntoIter<isize>>(&mut IntoIterator::IntoIter<isize>) -> Option<<IntoIterator::IntoIter<isize> as Iterator>::Item>
298 114..133 'for _ ...!() {}': Option<IntoIterator::Item<isize>>
299 114..133 'for _ ...!() {}': ()
300 114..133 'for _ ...!() {}': ()
301 114..133 'for _ ...!() {}': ()
302 118..119 '_': IntoIterator::Item<isize>
304 138..148 '|| spam!()': impl Fn() -> isize
305 154..170 'while ...!() {}': !
306 154..170 'while ...!() {}': ()
307 154..170 'while ...!() {}': ()
309 175..188 'break spam!()': !
310 194..208 'return spam!()': !
311 214..268 'match ... }': isize
313 273..289 'spam!(...am!())': {unknown}
314 295..317 'Spam {...m!() }': {unknown}
315 323..339 'spam!(...am!()]': {unknown}
316 364..380 'spam!(... usize': usize
317 386..394 '&spam!()': &isize
318 400..408 '-spam!()': isize
319 414..430 'spam!(...pam!()': {unknown}
320 436..453 'spam!(...pam!()': isize
326 fn expr_macro_expanded_in_stmts() {
329 macro_rules! id { ($($es:tt)*) => { $($es)* } }
337 57..84 '{ ...); } }': ()
343 fn recursive_macro_expanded_in_stmts() {
350 ([$($tts:tt)*] $head:tt $($rest:tt)*) => {
352 [$($tts)* $head] $($rest)*
364 196..237 '{ ...= a; }': ()
372 fn recursive_inner_item_macro_rules() {
377 ($x:tt) => { macro_rules! blub { () => { 1 }; } };
386 107..143 '{ ...!(); }': ()
393 fn infer_macro_defining_block_with_items() {
398 fn bar() -> usize { 0 }
409 !0..24 '{fnbar...bar()}': usize
410 !18..21 'bar': fn bar() -> usize
411 !18..23 'bar()': usize
412 98..122 '{ ...!(); }': ()
419 fn infer_type_value_macro_having_same_name() {
437 let foo = foo::foo!(42i32);
442 170..205 '{ ...32); }': ()
449 fn processes_impls_generated_by_macros() {
453 ($ident:ident) => (impl Trait for $ident {})
455 trait Trait { fn foo(self) -> u128 { 0 } }
458 fn test() { S.foo(); }
465 fn infer_assoc_items_generated_by_macros() {
469 () => (fn foo(&self) -> u128 {0})
476 fn test() { S.foo(); }
483 fn infer_assoc_items_generated_by_macros_chain() {
486 macro_rules! m_inner {
487 () => {fn foo(&self) -> u128 {0}}
498 fn test() { S.foo(); }
505 fn infer_macro_with_dollar_crate_is_correct_in_expr() {
508 //- /main.rs crate:main deps:foo
510 let x = (foo::foo!(1), foo::foo!(2));
514 //- /lib.rs crate:foo
517 (1) => { $crate::bar!() };
518 (2) => { 1 + $crate::baz() };
526 pub fn baz() -> usize { 31usize }
532 fn infer_macro_with_dollar_crate_is_correct_in_trait_associate_type() {
535 //- /main.rs crate:main deps:foo
539 let msg = foo::Message(foo::MessageRef);
545 //- /lib.rs crate:foo
546 pub struct MessageRef;
547 pub struct Message(MessageRef);
551 fn deref(&self) -> &Self::Target;
555 macro_rules! expand {
557 impl Trait for Message {
558 type Target = $crate::MessageRef;
559 fn deref(&self) -> &Self::Target {
572 fn infer_macro_with_dollar_crate_in_def_site() {
575 //- /main.rs crate:main deps:foo
579 ($($tt:tt)*) => { $($tt)* }
588 //- /lib.rs crate:foo
590 macro_rules! expand {
591 () => { list!($crate::m!()) };
603 fn infer_type_value_non_legacy_macro_use_as() {
608 ($x:ident) => { type $x = u64; }
610 pub(crate) use _foo as foo;
621 158..163 '{ 0 }': u64
623 174..196 '{ ...f(); }': ()
625 190..191 'f': fn f() -> u64
632 fn infer_local_macro() {
643 !0..6 '1usize': usize
644 10..89 '{ ...!(); }': ()
651 fn infer_local_inner_macros() {
654 //- /main.rs crate:main deps:foo
656 let x = foo::foo!(1);
660 //- /lib.rs crate:foo
661 #[macro_export(local_inner_macros)]
676 fn infer_builtin_macros_line() {
679 #[rustc_builtin_macro]
680 macro_rules! line {() => {}}
688 63..87 '{ ...!(); }': ()
695 fn infer_builtin_macros_file() {
698 #[rustc_builtin_macro]
699 macro_rules! file {() => {}}
707 63..87 '{ ...!(); }': ()
714 fn infer_builtin_macros_column() {
717 #[rustc_builtin_macro]
718 macro_rules! column {() => {}}
726 65..91 '{ ...!(); }': ()
733 fn infer_builtin_macros_concat() {
736 #[rustc_builtin_macro]
737 macro_rules! concat {() => {}}
740 let x = concat!("hello", concat!("world", "!"));
744 !0..13 '"helloworld!"': &str
745 65..121 '{ ...")); }': ()
752 fn infer_builtin_macros_include() {
756 #[rustc_builtin_macro]
757 macro_rules! include {() => {}}
772 fn infer_builtin_macros_include_expression() {
776 #[rustc_builtin_macro]
777 macro_rules! include {() => {}}
779 let i = include!("bla.rs");
790 fn infer_builtin_macros_include_child_mod() {
794 #[rustc_builtin_macro]
795 macro_rules! include {() => {}}
797 include!("f/foo.rs");
807 pub fn bar() -> u32 {0}
813 fn infer_builtin_macros_include_str() {
817 #[rustc_builtin_macro]
818 macro_rules! include_str {() => {}}
821 let a = include_str!("foo.rs");
832 fn infer_builtin_macros_include_str_with_lazy_nested() {
836 #[rustc_builtin_macro]
837 macro_rules! concat {() => {}}
838 #[rustc_builtin_macro]
839 macro_rules! include_str {() => {}}
848 let a = include_str!(m!(".rs"));
859 fn benchmark_include_macro() {
860 if skip_slow_tests() {
863 let data
= bench_fixture
::big_struct();
866 #[rustc_builtin_macro]
867 macro_rules! include {() => {}}
873 //^^^^^^^^^^^^^^^^^ RegisterBlock
876 let fixture
= format
!("{fixture}\n//- /foo.rs\n{data}");
879 let _b
= bench("include macro");
880 check_types(&fixture
);
885 fn infer_builtin_macros_include_concat() {
889 #[rustc_builtin_macro]
890 macro_rules! include {() => {}}
892 #[rustc_builtin_macro]
893 macro_rules! concat {() => {}}
895 include!(concat!("f", "oo.rs"));
908 fn infer_builtin_macros_include_concat_with_bad_env_should_failed() {
912 #[rustc_builtin_macro]
913 macro_rules! include {() => {}}
915 #[rustc_builtin_macro]
916 macro_rules! concat {() => {}}
918 #[rustc_builtin_macro]
919 macro_rules! env {() => {}}
921 include!(concat!(env!("OUT_DIR"), "/foo.rs"));
934 fn infer_builtin_macros_include_itself_should_failed() {
937 #[rustc_builtin_macro]
938 macro_rules! include {() => {}}
950 fn infer_builtin_macros_concat_with_lazy() {
953 macro_rules! hello {() => {"hello"}}
955 #[rustc_builtin_macro]
956 macro_rules! concat {() => {}}
959 let x = concat!(hello!(), concat!("world", "!"));
963 !0..13 '"helloworld!"': &str
964 103..160 '{ ...")); }': ()
971 fn infer_builtin_macros_env() {
974 //- /main.rs env:foo=bar
975 #[rustc_builtin_macro]
976 macro_rules! env {() => {}}
987 fn infer_builtin_macros_option_env() {
991 //- /main.rs env:foo=bar
992 #[rustc_builtin_macro]
993 macro_rules! option_env {() => {}}
996 let x = option_env!("foo");
1004 fn infer_derive_clone_simple() {
1007 //- minicore: derive, clone
1018 fn infer_derive_clone_with_params() {
1021 //- minicore: clone, derive
1025 struct Wrapper<T>(T);
1028 let x = (Wrapper(S).clone(), Wrapper(NonClone).clone());
1030 //^ (Wrapper<S>, {unknown})
1037 fn infer_custom_derive_simple() {
1038 // FIXME: this test current now do nothing
1041 //- minicore: derive
1070 51..110 '{ ... }; }': ()
1072 65..107 'match ... }': u32
1074 95..100 '92u32': u32
1080 fn macro_in_type_alias_position() {
1095 type TayTo = U32!();
1098 let a: <() as Foo>::Ty;
1103 147..196 '{ ...yTo; }': ()
1111 fn nested_macro_in_type_alias_position() {
1114 macro_rules! U32Inner2 {
1118 macro_rules! U32Inner1 {
1119 () => { U32Inner2!() };
1123 () => { U32Inner1!() };
1134 type TayTo = U32!();
1137 let a: <() as Foo>::Ty;
1142 259..308 '{ ...yTo; }': ()
1150 fn macros_in_type_alias_position_generics() {
1153 struct Foo<A, B>(A, B);
1160 () => { Foo<U32!(), U32!()> };
1171 type TayTo = Bar!();
1174 let a: <() as Moo>::Ty;
1179 228..277 '{ ...yTo; }': ()
1180 238..239 'a': Foo<u32, u32>
1181 266..267 'b': Foo<u32, u32>
1187 fn macros_in_type_position() {
1190 struct Foo<A, B>(A, B);
1197 () => { Foo<U32!(), U32!()> };
1205 133..155 '{ ...!(); }': ()
1206 143..144 'a': Foo<u32, u32>
1212 fn macros_in_type_generics() {
1215 struct Foo<A, B>(A, B);
1222 () => { Foo<U32!(), U32!()> };
1230 type Ty = Foo<Bar!(), Bar!()>;
1233 type TayTo = Foo<Bar!(), U32!()>;
1236 let a: <() as Moo>::Ty;
1241 254..303 '{ ...yTo; }': ()
1242 264..265 'a': Foo<Foo<u32, u32>, Foo<u32, u32>>
1243 292..293 'b': Foo<Foo<u32, u32>, u32>
1249 fn infinitely_recursive_macro_type() {
1252 struct Bar<T, X>(T, X);
1263 type B = Bar<Foo!(), U32!()>;
1271 166..197 '{ ...: B; }': ()
1272 176..177 'a': {unknown}
1273 190..191 'b': Bar<{unknown}, u32>
1280 check_infer_with_mismatches(
1282 //- /lib.rs crate:foo cfg:feature=foo
1286 fn new2(bar: u32) -> Self {
1287 #[cfg(feature = "foo")]
1289 #[cfg(not(feature = "foo"))]
1296 52..170 '{ ... }': S
1297 62..106 '#[cfg(... { } }': S
1298 96..104 'Self { }': S
1304 fn infer_in_unexpandable_attr_proc_macro_1() {
1307 //- /main.rs crate:main deps:mac
1314 //- /mac.rs crate:mac
1315 #![crate_type="proc-macro"]
1316 #[proc_macro_attribute]
1317 pub fn attr_macro() {}
1323 fn infer_in_unexpandable_attr_proc_macro_in_impl() {
1326 //- /main.rs crate:main deps:mac
1336 //- /mac.rs crate:mac
1337 #![crate_type="proc-macro"]
1338 #[proc_macro_attribute]
1339 pub fn attr_macro() {}
1345 fn infer_in_unexpandable_attr_proc_macro_in_trait() {
1348 //- /main.rs crate:main deps:mac
1357 //- /mac.rs crate:mac
1358 #![crate_type="proc-macro"]
1359 #[proc_macro_attribute]
1360 pub fn attr_macro() {}