]> git.lizzy.rs Git - rust.git/blobdiff - crates/ide_diagnostics/src/handlers/macro_error.rs
Merge #11354
[rust.git] / crates / ide_diagnostics / src / handlers / macro_error.rs
index d4d928ad105c5c02aedad7be9fc5a336ac7f03b1..a5bfb302d5ebce2284783a3d2130ad924f375972 100644 (file)
@@ -26,8 +26,53 @@ fn builtin_macro_fails_expansion() {
 #[rustc_builtin_macro]
 macro_rules! include { () => {} }
 
+#[rustc_builtin_macro]
+macro_rules! compile_error { () => {} }
+
   include!("doesntexist");
-//^^^^^^^^^^^^^^^^^^^^^^^^ failed to load file `doesntexist`
+//^^^^^^^^^^^^^^^^^^^^^^^^ error: failed to load file `doesntexist`
+
+  compile_error!("compile_error macro works");
+//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: compile_error macro works
+            "#,
+        );
+    }
+
+    #[test]
+    fn eager_macro_concat() {
+        // FIXME: this is incorrectly handling `$crate`, resulting in a wrong diagnostic.
+        // See: https://github.com/rust-analyzer/rust-analyzer/issues/10300
+
+        check_diagnostics(
+            r#"
+//- /lib.rs crate:lib deps:core
+use core::{panic, concat};
+
+mod private {
+    pub use core::concat;
+}
+
+macro_rules! m {
+    () => {
+        panic!(concat!($crate::private::concat!("")));
+    };
+}
+
+fn f() {
+    m!();
+  //^^^^ error: unresolved macro `$crate::private::concat!`
+}
+
+//- /core.rs crate:core
+#[macro_export]
+#[rustc_builtin_macro]
+macro_rules! concat { () => {} }
+
+pub macro panic {
+    ($msg:expr) => (
+        $crate::panicking::panic_str($msg)
+    ),
+}
             "#,
         );
     }
@@ -66,7 +111,7 @@ macro_rules! env { () => {} }
 macro_rules! concat { () => {} }
 
   include!(concat!(env!("OUT_DIR"), "/out.rs"));
-//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `OUT_DIR` not set, enable "run build scripts" to fix
+//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `OUT_DIR` not set, enable "run build scripts" to fix
 "#,
         );
     }
@@ -108,23 +153,23 @@ fn main() {
     // Test a handful of built-in (eager) macros:
 
     include!(invalid);
-  //^^^^^^^^^^^^^^^^^ could not convert tokens
+  //^^^^^^^^^^^^^^^^^ error: could not convert tokens
     include!("does not exist");
-  //^^^^^^^^^^^^^^^^^^^^^^^^^^ failed to load file `does not exist`
+  //^^^^^^^^^^^^^^^^^^^^^^^^^^ error: failed to load file `does not exist`
 
     env!(invalid);
-  //^^^^^^^^^^^^^ could not convert tokens
+  //^^^^^^^^^^^^^ error: could not convert tokens
 
     env!("OUT_DIR");
-  //^^^^^^^^^^^^^^^ `OUT_DIR` not set, enable "run build scripts" to fix
+  //^^^^^^^^^^^^^^^ error: `OUT_DIR` not set, enable "run build scripts" to fix
 
     compile_error!("compile_error works");
-  //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ compile_error works
+  //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: compile_error works
 
     // Lazy:
 
     format_args!();
-  //^^^^^^^^^^^^^^ no rule matches input tokens
+  //^^^^^^^^^^^^^^ error: no rule matches input tokens
 }
 "#,
         );
@@ -141,7 +186,7 @@ fn f() {
     m!();
 
     m!(hi);
-  //^^^^^^ leftover tokens
+  //^^^^^^ error: leftover tokens
 }
       "#,
         );
@@ -166,7 +211,7 @@ macro_rules! outer {
 
 fn f() {
     outer!();
-} //^^^^^^^^ leftover tokens
+} //^^^^^^^^ error: leftover tokens
 "#,
         )
     }