1 use crate::{Diagnostic, DiagnosticsContext};
3 // Diagnostic: macro-error
5 // This diagnostic is shown for macro expansion errors.
6 pub(crate) fn macro_error(ctx: &DiagnosticsContext<'_>, d: &hir::MacroError) -> Diagnostic {
10 ctx.sema.diagnostics_display_range(d.node.clone()).range,
18 tests::{check_diagnostics, check_diagnostics_with_config},
23 fn builtin_macro_fails_expansion() {
26 #[rustc_builtin_macro]
27 macro_rules! include { () => {} }
29 include!("doesntexist");
30 //^^^^^^^^^^^^^^^^^^^^^^^^ error: failed to load file `doesntexist`
36 fn include_macro_should_allow_empty_content() {
37 let mut config = DiagnosticsConfig::default();
39 // FIXME: This is a false-positive, the file is actually linked in via
41 config.disabled.insert("unlinked-file".to_string());
43 check_diagnostics_with_config(
47 #[rustc_builtin_macro]
48 macro_rules! include { () => {} }
50 include!("foo/bar.rs");
58 fn good_out_dir_diagnostic() {
61 #[rustc_builtin_macro]
62 macro_rules! include { () => {} }
63 #[rustc_builtin_macro]
64 macro_rules! env { () => {} }
65 #[rustc_builtin_macro]
66 macro_rules! concat { () => {} }
68 include!(concat!(env!("OUT_DIR"), "/out.rs"));
69 //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `OUT_DIR` not set, enable "run build scripts" to fix
75 fn register_attr_and_tool() {
76 cov_mark::check!(register_attr);
77 cov_mark::check!(register_tool);
80 #![register_tool(tool)]
81 #![register_attr(attr)]
88 // NB: we don't currently emit diagnostics here
92 fn macro_diag_builtin() {
95 #[rustc_builtin_macro]
98 #[rustc_builtin_macro]
99 macro_rules! include {}
101 #[rustc_builtin_macro]
102 macro_rules! compile_error {}
104 #[rustc_builtin_macro]
105 macro_rules! format_args { () => {} }
108 // Test a handful of built-in (eager) macros:
111 //^^^^^^^^^^^^^^^^^ error: could not convert tokens
112 include!("does not exist");
113 //^^^^^^^^^^^^^^^^^^^^^^^^^^ error: failed to load file `does not exist`
116 //^^^^^^^^^^^^^ error: could not convert tokens
119 //^^^^^^^^^^^^^^^ error: `OUT_DIR` not set, enable "run build scripts" to fix
121 compile_error!("compile_error works");
122 //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: compile_error works
127 //^^^^^^^^^^^^^^ error: no rule matches input tokens
134 fn macro_rules_diag() {
144 //^^^^^^ error: leftover tokens
150 fn dollar_crate_in_builtin_macro() {
154 #[rustc_builtin_macro]
155 macro_rules! format_args {}
158 macro_rules! arg { () => {} }
163 $crate::format_args!( "", $crate::arg!(1) )
169 } //^^^^^^^^ error: leftover tokens