From 00303284b5cc3a82e32dc3ecbbcfeb2f99de6818 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 13 Jun 2021 18:41:04 +0300 Subject: internal: refactor macro error --- crates/hir_def/src/body/tests.rs | 88 ------------------------- crates/hir_def/src/nameres/tests.rs | 1 - crates/hir_def/src/nameres/tests/diagnostics.rs | 76 --------------------- 3 files changed, 165 deletions(-) delete mode 100644 crates/hir_def/src/nameres/tests/diagnostics.rs (limited to 'crates/hir_def') diff --git a/crates/hir_def/src/body/tests.rs b/crates/hir_def/src/body/tests.rs index 075dcc6d2..0dccabcfd 100644 --- a/crates/hir_def/src/body/tests.rs +++ b/crates/hir_def/src/body/tests.rs @@ -88,67 +88,6 @@ mod m { ); } -#[test] -fn macro_diag_builtin() { - check_diagnostics( - r#" -#[rustc_builtin_macro] -macro_rules! env {} - -#[rustc_builtin_macro] -macro_rules! include {} - -#[rustc_builtin_macro] -macro_rules! compile_error {} - -#[rustc_builtin_macro] -macro_rules! format_args { - () => {} -} - -fn f() { - // Test a handful of built-in (eager) macros: - - include!(invalid); - //^^^^^^^^^^^^^^^^^ could not convert tokens - include!("does not exist"); - //^^^^^^^^^^^^^^^^^^^^^^^^^^ failed to load file `does not exist` - - env!(invalid); - //^^^^^^^^^^^^^ could not convert tokens - - env!("OUT_DIR"); - //^^^^^^^^^^^^^^^ `OUT_DIR` not set, enable "run build scripts" to fix - - compile_error!("compile_error works"); - //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ compile_error works - - // Lazy: - - format_args!(); - //^^^^^^^^^^^^^^ no rule matches input tokens -} - "#, - ); -} - -#[test] -fn macro_rules_diag() { - check_diagnostics( - r#" -macro_rules! m { - () => {}; -} -fn f() { - m!(); - - m!(hi); - //^^^^^^ leftover tokens -} - "#, - ); -} - #[test] fn unresolved_macro_diag() { check_diagnostics( @@ -161,30 +100,3 @@ fn f() { ); } -#[test] -fn dollar_crate_in_builtin_macro() { - check_diagnostics( - r#" -#[macro_export] -#[rustc_builtin_macro] -macro_rules! format_args {} - -#[macro_export] -macro_rules! arg { - () => {} -} - -#[macro_export] -macro_rules! outer { - () => { - $crate::format_args!( "", $crate::arg!(1) ) - }; -} - -fn f() { - outer!(); - //^^^^^^^^ leftover tokens -} - "#, - ) -} diff --git a/crates/hir_def/src/nameres/tests.rs b/crates/hir_def/src/nameres/tests.rs index 58c01354a..cf43f2a96 100644 --- a/crates/hir_def/src/nameres/tests.rs +++ b/crates/hir_def/src/nameres/tests.rs @@ -2,7 +2,6 @@ mod globs; mod incremental; mod macros; mod mod_resolution; -mod diagnostics; mod primitives; use std::sync::Arc; diff --git a/crates/hir_def/src/nameres/tests/diagnostics.rs b/crates/hir_def/src/nameres/tests/diagnostics.rs deleted file mode 100644 index f1ee03d4d..000000000 --- a/crates/hir_def/src/nameres/tests/diagnostics.rs +++ /dev/null @@ -1,76 +0,0 @@ -use base_db::fixture::WithFixture; - -use crate::test_db::TestDB; - -fn check_diagnostics(ra_fixture: &str) { - let db: TestDB = TestDB::with_files(ra_fixture); - db.check_diagnostics(); -} - -fn check_no_diagnostics(ra_fixture: &str) { - let db: TestDB = TestDB::with_files(ra_fixture); - db.check_no_diagnostics(); -} - -#[test] -fn builtin_macro_fails_expansion() { - check_diagnostics( - r#" - //- /lib.rs - #[rustc_builtin_macro] - macro_rules! include { () => {} } - - include!("doesntexist"); - //^^^^^^^^^^^^^^^^^^^^^^^^ failed to load file `doesntexist` - "#, - ); -} - -#[test] -fn include_macro_should_allow_empty_content() { - check_no_diagnostics( - r#" - //- /lib.rs - #[rustc_builtin_macro] - macro_rules! include { () => {} } - - include!("bar.rs"); - //- /bar.rs - // empty - "#, - ); -} - -#[test] -fn good_out_dir_diagnostic() { - check_diagnostics( - r#" - #[rustc_builtin_macro] - macro_rules! include { () => {} } - #[rustc_builtin_macro] - macro_rules! env { () => {} } - #[rustc_builtin_macro] - macro_rules! concat { () => {} } - - include!(concat!(env!("OUT_DIR"), "/out.rs")); - //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `OUT_DIR` not set, enable "run build scripts" to fix - "#, - ); -} - -#[test] -fn register_attr_and_tool() { - cov_mark::check!(register_attr); - cov_mark::check!(register_tool); - check_no_diagnostics( - r#" -#![register_tool(tool)] -#![register_attr(attr)] - -#[tool::path] -#[attr] -struct S; - "#, - ); - // NB: we don't currently emit diagnostics here -} -- cgit v1.2.3