From f4866bb05cca51b4c50ae8fdcd07dc71543d56c7 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 2 Dec 2020 14:54:25 +0100 Subject: Test macro diagnostics in body lowering --- crates/hir_def/src/body/tests.rs | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/crates/hir_def/src/body/tests.rs b/crates/hir_def/src/body/tests.rs index f07df5cee..baf1179f1 100644 --- a/crates/hir_def/src/body/tests.rs +++ b/crates/hir_def/src/body/tests.rs @@ -73,3 +73,44 @@ fn f() { ", ); } + +#[test] +fn macro_diag_builtin() { + check_diagnostics( + r#" +fn f() { + // Test a handful of built-in (eager) macros: + + include!(invalid); + //^^^^^^^^^^^^^^^^^ failed to parse or resolve macro invocation + include!("does not exist"); + //^^^^^^^^^^^^^^^^^^^^^^^^^^ failed to parse or resolve macro invocation + + env!(invalid); + //^^^^^^^^^^^^^ failed to parse or resolve macro invocation + + // Lazy: + + format_args!(); + //^^^^^^^^^^^^^^ failed to parse or resolve macro invocation +} + "#, + ); +} + +#[test] +fn macro_rules_diag() { + check_diagnostics( + r#" +macro_rules! m { + () => {}; +} +fn f() { + m!(); + + m!(hi); + //^^^^^^ leftover tokens +} + "#, + ); +} -- cgit v1.2.3