3 use base_db::{fixture::WithFixture, SourceDatabase};
4 use expect_test::Expect;
6 use crate::{test_db::TestDB, ModuleDefId};
10 fn lower(ra_fixture: &str) -> Arc<Body> {
11 let db = crate::test_db::TestDB::with_files(ra_fixture);
13 let krate = db.crate_graph().iter().next().unwrap();
14 let def_map = db.crate_def_map(krate);
15 let mut fn_def = None;
16 'outer: for (_, module) in def_map.modules() {
17 for decl in module.scope.declarations() {
19 ModuleDefId::FunctionId(it) => {
28 db.body(fn_def.unwrap().into())
31 fn check_diagnostics(ra_fixture: &str) {
32 let db: TestDB = TestDB::with_files(ra_fixture);
33 db.check_diagnostics();
36 fn block_def_map_at(ra_fixture: &str) -> String {
37 let (db, position) = crate::test_db::TestDB::with_position(ra_fixture);
39 let module = db.module_at_position(position);
40 module.def_map(&db).dump(&db)
43 fn check_block_scopes_at(ra_fixture: &str, expect: Expect) {
44 let (db, position) = crate::test_db::TestDB::with_position(ra_fixture);
46 let module = db.module_at_position(position);
47 let actual = module.def_map(&db).dump_block_scopes(&db);
48 expect.assert_eq(&actual);
51 fn check_at(ra_fixture: &str, expect: Expect) {
52 let actual = block_def_map_at(ra_fixture);
53 expect.assert_eq(&actual);
57 fn your_stack_belongs_to_me() {
58 cov_mark::check!(your_stack_belongs_to_me);
61 macro_rules! n_nuple {
64 (n_nuple!($($rest)*)None,)
67 fn main() { n_nuple!(1,2,3); }
74 // Regression test for a path resolution bug introduced with inner item handling.
79 ($elem:expr; $n:expr) => { () };
80 ($($x:expr),+ $(,)?) => { () };
84 let _ = vec![FileSet::default(); self.len()];
92 fn cfg_diagnostics() {
96 // The three g̶e̶n̶d̶e̶r̶s̶ statements:
98 #[cfg(a)] fn f() {} // Item statement
99 //^^^^^^^^^^^^^^^^^^^ code is inactive due to #[cfg] directives: a is disabled
100 #[cfg(a)] {} // Expression statement
101 //^^^^^^^^^^^^ code is inactive due to #[cfg] directives: a is disabled
102 #[cfg(a)] let x = 0; // let statement
103 //^^^^^^^^^^^^^^^^^^^^ code is inactive due to #[cfg] directives: a is disabled
106 //^^^^^^^^^^^ code is inactive due to #[cfg] directives: a is disabled
109 //^^^^^^^^^^^^^^ code is inactive due to #[cfg] directives: a is disabled
114 //^^^^^^^^^^^^^^^^^^ code is inactive due to #[cfg] directives: a is disabled
117 #[cfg(a)] 0 // Trailing expression of block
118 //^^^^^^^^^^^ code is inactive due to #[cfg] directives: a is disabled
125 fn macro_diag_builtin() {
128 #[rustc_builtin_macro]
131 #[rustc_builtin_macro]
132 macro_rules! include {}
134 #[rustc_builtin_macro]
135 macro_rules! compile_error {}
137 #[rustc_builtin_macro]
138 macro_rules! format_args {
143 // Test a handful of built-in (eager) macros:
146 //^^^^^^^^^^^^^^^^^ could not convert tokens
147 include!("does not exist");
148 //^^^^^^^^^^^^^^^^^^^^^^^^^^ failed to load file `does not exist`
151 //^^^^^^^^^^^^^ could not convert tokens
154 //^^^^^^^^^^^^^^^ `OUT_DIR` not set, enable "run build scripts" to fix
156 compile_error!("compile_error works");
157 //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ compile_error works
162 //^^^^^^^^^^^^^^ no rule matches input tokens
169 fn macro_rules_diag() {
179 //^^^^^^ leftover tokens
186 fn unresolved_macro_diag() {
191 //^^^^ unresolved macro `m!`
198 fn dollar_crate_in_builtin_macro() {
202 #[rustc_builtin_macro]
203 macro_rules! format_args {}
213 $crate::format_args!( "", $crate::arg!(1) )
219 //^^^^^^^^ leftover tokens