1 //! Tests for `builtin_fn_macro.rs` from `hir_expand`.
3 use expect_test::expect;
5 use crate::macro_expansion_tests::check;
8 fn test_column_expand() {
11 #[rustc_builtin_macro]
12 macro_rules! column {() => {}}
14 fn main() { column!(); }
17 #[rustc_builtin_macro]
18 macro_rules! column {() => {}}
26 fn test_line_expand() {
29 #[rustc_builtin_macro]
30 macro_rules! line {() => {}}
35 #[rustc_builtin_macro]
36 macro_rules! line {() => {}}
44 fn test_stringify_expand() {
47 #[rustc_builtin_macro]
48 macro_rules! stringify {() => {}}
59 #[rustc_builtin_macro]
60 macro_rules! stringify {() => {}}
70 fn test_env_expand() {
73 #[rustc_builtin_macro]
74 macro_rules! env {() => {}}
76 fn main() { env!("TEST_ENV_VAR"); }
79 #[rustc_builtin_macro]
80 macro_rules! env {() => {}}
82 fn main() { "__RA_UNIMPLEMENTED__"; }
88 fn test_option_env_expand() {
91 #[rustc_builtin_macro]
92 macro_rules! option_env {() => {}}
94 fn main() { option_env!("TEST_ENV_VAR"); }
97 #[rustc_builtin_macro]
98 macro_rules! option_env {() => {}}
100 fn main() { std::option::Option::None:: < &str>; }
106 fn test_file_expand() {
109 #[rustc_builtin_macro]
110 macro_rules! file {() => {}}
112 fn main() { file!(); }
115 #[rustc_builtin_macro]
116 macro_rules! file {() => {}}
124 fn test_assert_expand() {
127 #[rustc_builtin_macro]
128 macro_rules! assert {
129 ($cond:expr) => ({ /* compiler built-in */ });
130 ($cond:expr, $($args:tt)*) => ({ /* compiler built-in */ })
134 assert!(true, "{} {:?}", arg1(a, b, c), arg2);
138 #[rustc_builtin_macro]
139 macro_rules! assert {
140 ($cond:expr) => ({ /* compiler built-in */ });
141 ($cond:expr, $($args:tt)*) => ({ /* compiler built-in */ })
147 $crate::panic!("{} {:?}", arg1(a, b, c), arg2);
156 fn test_compile_error_expand() {
159 #[rustc_builtin_macro]
160 macro_rules! compile_error {
161 ($msg:expr) => ({ /* compiler built-in */ });
162 ($msg:expr,) => ({ /* compiler built-in */ })
165 // This expands to nothing (since it's in item position), but emits an error.
166 compile_error!("error!");
169 #[rustc_builtin_macro]
170 macro_rules! compile_error {
171 ($msg:expr) => ({ /* compiler built-in */ });
172 ($msg:expr,) => ({ /* compiler built-in */ })
181 fn test_format_args_expand() {
184 #[rustc_builtin_macro]
185 macro_rules! format_args {
186 ($fmt:expr) => ({ /* compiler built-in */ });
187 ($fmt:expr, $($args:tt)*) => ({ /* compiler built-in */ })
191 format_args!("{} {:?}", arg1(a, b, c), arg2);
195 #[rustc_builtin_macro]
196 macro_rules! format_args {
197 ($fmt:expr) => ({ /* compiler built-in */ });
198 ($fmt:expr, $($args:tt)*) => ({ /* compiler built-in */ })
203 std::fmt::Arguments::new_v1(&[], &[std::fmt::ArgumentV1::new(&(arg1(a, b, c)), std::fmt::Display::fmt), std::fmt::ArgumentV1::new(&(arg2), std::fmt::Display::fmt), ])
211 fn test_format_args_expand_with_comma_exprs() {
214 #[rustc_builtin_macro]
215 macro_rules! format_args {
216 ($fmt:expr) => ({ /* compiler built-in */ });
217 ($fmt:expr, $($args:tt)*) => ({ /* compiler built-in */ })
221 format_args!("{} {:?}", a::<A,B>(), b);
225 #[rustc_builtin_macro]
226 macro_rules! format_args {
227 ($fmt:expr) => ({ /* compiler built-in */ });
228 ($fmt:expr, $($args:tt)*) => ({ /* compiler built-in */ })
233 std::fmt::Arguments::new_v1(&[], &[std::fmt::ArgumentV1::new(&(a::<A, B>()), std::fmt::Display::fmt), std::fmt::ArgumentV1::new(&(b), std::fmt::Display::fmt), ])
241 fn test_format_args_expand_with_broken_member_access() {
244 #[rustc_builtin_macro]
245 macro_rules! format_args {
246 ($fmt:expr) => ({ /* compiler built-in */ });
247 ($fmt:expr, $($args:tt)*) => ({ /* compiler built-in */ })
253 format_args!("{} {:?}", a.);
257 #[rustc_builtin_macro]
258 macro_rules! format_args {
259 ($fmt:expr) => ({ /* compiler built-in */ });
260 ($fmt:expr, $($args:tt)*) => ({ /* compiler built-in */ })
265 /* parse error: expected field name or number */
267 std::fmt::Arguments::new_v1(&[], &[std::fmt::ArgumentV1::new(&(a.), std::fmt::Display::fmt), ])
275 fn test_include_bytes_expand() {
278 #[rustc_builtin_macro]
279 macro_rules! include_bytes {
280 ($file:expr) => {{ /* compiler built-in */ }};
281 ($file:expr,) => {{ /* compiler built-in */ }};
284 fn main() { include_bytes("foo"); }
287 #[rustc_builtin_macro]
288 macro_rules! include_bytes {
289 ($file:expr) => {{ /* compiler built-in */ }};
290 ($file:expr,) => {{ /* compiler built-in */ }};
293 fn main() { include_bytes("foo"); }
299 fn test_concat_expand() {
302 #[rustc_builtin_macro]
303 macro_rules! concat {}
305 fn main() { concat!("foo", "r", 0, r#"bar"#, "\n", false); }
308 #[rustc_builtin_macro]
309 macro_rules! concat {}
311 fn main() { "foor0bar\nfalse"; }
317 fn test_concat_with_captured_expr() {
320 #[rustc_builtin_macro]
321 macro_rules! concat {}
323 macro_rules! surprise {
328 ($string:expr) => { concat!($string) };
331 fn main() { concat!(surprise!()); }
334 #[rustc_builtin_macro]
335 macro_rules! concat {}
337 macro_rules! surprise {
342 ($string:expr) => { concat!($string) };
351 fn test_concat_idents_expand() {
354 #[rustc_builtin_macro]
355 macro_rules! concat_idents {}
357 fn main() { concat_idents!(foo, bar); }
360 #[rustc_builtin_macro]
361 macro_rules! concat_idents {}
363 fn main() { foobar; }