1 use expect_test::expect;
2 use test_utils::{bench, bench_fixture, skip_slow_tests};
4 use super::{check_infer, check_types};
10 //- /main.rs crate:main deps:foo cfg:test
16 fn foo1(&self) -> i32 { 0 }
21 fn foo2(&self) -> i32 { 0 }
25 let t = (S.foo1(), S.foo2(), T.foo3(), T.foo4());
27 } //^ (i32, {unknown}, i32, {unknown})
34 fn foo3(&self) -> i32 { 0 }
39 fn foo4(&self) -> i32 { 0 }
46 fn infer_macros_expanded() {
52 ($($item:expr),*) => {
64 !0..17 '{Foo(v...,2,])}': Foo
65 !1..4 'Foo': Foo({unknown}) -> Foo
66 !1..16 'Foo(vec![1,2,])': Foo
67 !5..15 'vec![1,2,]': {unknown}
68 155..181 '{ ...,2); }': ()
75 fn infer_legacy_textual_scoped_macros_expanded() {
83 ($($item:expr),*) => {
93 let y = crate::foo!(1,2);
97 !0..17 '{Foo(v...,2,])}': Foo
98 !1..4 'Foo': Foo({unknown}) -> Foo
99 !1..16 'Foo(vec![1,2,])': Foo
100 !5..15 'vec![1,2,]': {unknown}
101 194..250 '{ ...,2); }': ()
103 227..228 'y': {unknown}
104 231..247 'crate:...!(1,2)': {unknown}
110 fn infer_path_qualified_macros_expanded() {
119 pub use super::foo as bar;
123 let x = crate::foo!();
130 110..163 '{ ...!(); }': ()
138 fn expr_macro_expanded_in_various_places() {
148 spam!().spam(spam!());
155 _ if spam!() => spam!(),
158 Spam { spam: spam!() };
169 !0..6 '1isize': isize
170 !0..6 '1isize': isize
171 !0..6 '1isize': isize
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 53..456 '{ ...!(); }': ()
195 87..108 'spam!(...am!())': {unknown}
196 114..133 'for _ ...!() {}': ()
197 118..119 '_': {unknown}
199 138..148 '|| spam!()': || -> isize
200 154..170 'while ...!() {}': ()
202 175..188 'break spam!()': !
203 194..208 'return spam!()': !
204 214..268 'match ... }': isize
206 273..289 'spam!(...am!())': {unknown}
207 295..317 'Spam {...m!() }': {unknown}
208 323..339 'spam!(...am!()]': {unknown}
209 364..380 'spam!(... usize': usize
210 386..394 '&spam!()': &isize
211 400..408 '-spam!()': isize
212 414..430 'spam!(...pam!()': {unknown}
213 436..453 'spam!(...pam!()': isize
219 fn expr_macro_expanded_in_stmts() {
222 macro_rules! id { ($($es:tt)*) => { $($es)* } }
229 57..84 '{ ...); } }': ()
235 fn infer_type_value_macro_having_same_name() {
253 let foo = foo::foo!(42i32);
258 170..205 '{ ...32); }': ()
265 fn processes_impls_generated_by_macros() {
269 ($ident:ident) => (impl Trait for $ident {})
271 trait Trait { fn foo(self) -> u128 {} }
274 fn test() { S.foo(); }
281 fn infer_assoc_items_generated_by_macros() {
285 () => (fn foo(&self) -> u128 {0})
292 fn test() { S.foo(); }
299 fn infer_assoc_items_generated_by_macros_chain() {
302 macro_rules! m_inner {
303 () => {fn foo(&self) -> u128 {0}}
314 fn test() { S.foo(); }
321 fn infer_macro_with_dollar_crate_is_correct_in_expr() {
324 //- /main.rs crate:main deps:foo
326 let x = (foo::foo!(1), foo::foo!(2));
330 //- /lib.rs crate:foo
333 (1) => { $crate::bar!() };
334 (2) => { 1 + $crate::baz() };
342 pub fn baz() -> usize { 31usize }
348 fn infer_macro_with_dollar_crate_is_correct_in_trait_associate_type() {
351 //- /main.rs crate:main deps:foo
355 let msg = foo::Message(foo::MessageRef);
361 //- /lib.rs crate:foo
362 pub struct MessageRef;
363 pub struct Message(MessageRef);
367 fn deref(&self) -> &Self::Target;
371 macro_rules! expand {
373 impl Trait for Message {
374 type Target = $crate::MessageRef;
375 fn deref(&self) -> &Self::Target {
388 fn infer_macro_with_dollar_crate_in_def_site() {
391 //- /main.rs crate:main deps:foo
395 ($($tt:tt)*) => { $($tt)* }
404 //- /lib.rs crate:foo
406 macro_rules! expand {
407 () => { list!($crate::m!()) };
419 fn infer_type_value_non_legacy_macro_use_as() {
424 ($x:ident) => { type $x = u64; }
426 pub(crate) use _foo as foo;
437 158..163 '{ 0 }': u64
439 174..196 '{ ...f(); }': ()
441 190..191 'f': fn f() -> u64
448 fn infer_local_macro() {
459 !0..6 '1usize': usize
460 10..89 '{ ...!(); }': ()
467 fn infer_local_inner_macros() {
470 //- /main.rs crate:main deps:foo
472 let x = foo::foo!(1);
476 //- /lib.rs crate:foo
477 #[macro_export(local_inner_macros)]
492 fn infer_builtin_macros_line() {
495 #[rustc_builtin_macro]
496 macro_rules! line {() => {}}
504 63..87 '{ ...!(); }': ()
511 fn infer_builtin_macros_file() {
514 #[rustc_builtin_macro]
515 macro_rules! file {() => {}}
523 63..87 '{ ...!(); }': ()
530 fn infer_builtin_macros_column() {
533 #[rustc_builtin_macro]
534 macro_rules! column {() => {}}
542 65..91 '{ ...!(); }': ()
549 fn infer_builtin_macros_concat() {
552 #[rustc_builtin_macro]
553 macro_rules! concat {() => {}}
556 let x = concat!("hello", concat!("world", "!"));
560 !0..13 '"helloworld!"': &str
561 65..121 '{ ...")); }': ()
568 fn infer_builtin_macros_include() {
572 #[rustc_builtin_macro]
573 macro_rules! include {() => {}}
588 fn infer_builtin_macros_include_str() {
592 #[rustc_builtin_macro]
593 macro_rules! include_str {() => {}}
596 let a = include_str!("foo.rs");
607 fn infer_builtin_macros_include_str_with_lazy_nested() {
611 #[rustc_builtin_macro]
612 macro_rules! concat {() => {}}
613 #[rustc_builtin_macro]
614 macro_rules! include_str {() => {}}
623 let a = include_str!(m!(".rs"));
634 fn benchmark_include_macro() {
635 if skip_slow_tests() {
638 let data = bench_fixture::big_struct();
641 #[rustc_builtin_macro]
642 macro_rules! include {() => {}}
651 let fixture = format!("{}\n//- /foo.rs\n{}", fixture, data);
654 let _b = bench("include macro");
655 check_types(&fixture);
660 fn infer_builtin_macros_include_concat() {
664 #[rustc_builtin_macro]
665 macro_rules! include {() => {}}
667 #[rustc_builtin_macro]
668 macro_rules! concat {() => {}}
670 include!(concat!("f", "oo.rs"));
683 fn infer_builtin_macros_include_concat_with_bad_env_should_failed() {
687 #[rustc_builtin_macro]
688 macro_rules! include {() => {}}
690 #[rustc_builtin_macro]
691 macro_rules! concat {() => {}}
693 #[rustc_builtin_macro]
694 macro_rules! env {() => {}}
696 include!(concat!(env!("OUT_DIR"), "/foo.rs"));
709 fn infer_builtin_macros_include_itself_should_failed() {
712 #[rustc_builtin_macro]
713 macro_rules! include {() => {}}
725 fn infer_builtin_macros_concat_with_lazy() {
728 macro_rules! hello {() => {"hello"}}
730 #[rustc_builtin_macro]
731 macro_rules! concat {() => {}}
734 let x = concat!(hello!(), concat!("world", "!"));
738 !0..13 '"helloworld!"': &str
739 103..160 '{ ...")); }': ()
746 fn infer_builtin_macros_env() {
749 //- /main.rs env:foo=bar
750 #[rustc_builtin_macro]
751 macro_rules! env {() => {}}
758 !0..22 '"__RA_...TED__"': &str
759 62..90 '{ ...o"); }': ()
766 fn infer_derive_clone_simple() {
769 //- /main.rs crate:main deps:core
776 //- /lib.rs crate:core
781 fn clone(&self) -> Self;
783 #[rustc_builtin_macro]
791 fn infer_derive_clone_in_core() {
794 //- /lib.rs crate:core
799 fn clone(&self) -> Self;
801 #[rustc_builtin_macro]
807 //- /main.rs crate:main deps:core
817 fn infer_derive_clone_with_params() {
820 //- /main.rs crate:main deps:core
824 struct Wrapper<T>(T);
827 (Wrapper(S).clone(), Wrapper(NonClone).clone());
828 //^ (Wrapper<S>, {unknown})
831 //- /lib.rs crate:core
836 fn clone(&self) -> Self;
838 #[rustc_builtin_macro]
846 fn infer_custom_derive_simple() {
847 // FIXME: this test current now do nothing
850 //- /main.rs crate:main
878 51..110 '{ ... }; }': ()
880 65..107 'match ... }': u32