Skip to content

Commit 327f3a0

Browse files
Merge #8307
8307: Allow include! an empty content file r=edwin0cheng a=edwin0cheng fixes #8306 bors r+ Co-authored-by: Edwin Cheng <[email protected]>
2 parents b580429 + 20d55ce commit 327f3a0

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

crates/hir_def/src/nameres/tests/diagnostics.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ fn check_diagnostics(ra_fixture: &str) {
77
db.check_diagnostics();
88
}
99

10+
fn check_no_diagnostics(ra_fixture: &str) {
11+
let db: TestDB = TestDB::with_files(ra_fixture);
12+
db.check_no_diagnostics();
13+
}
14+
1015
#[test]
1116
fn unresolved_import() {
1217
check_diagnostics(
@@ -201,6 +206,21 @@ fn builtin_macro_fails_expansion() {
201206
);
202207
}
203208

209+
#[test]
210+
fn include_macro_should_allow_empty_content() {
211+
check_no_diagnostics(
212+
r#"
213+
//- /lib.rs
214+
#[rustc_builtin_macro]
215+
macro_rules! include { () => {} }
216+
217+
include!("bar.rs");
218+
//- /bar.rs
219+
// empty
220+
"#,
221+
);
222+
}
223+
204224
#[test]
205225
fn good_out_dir_diagnostic() {
206226
check_diagnostics(

crates/hir_def/src/test_db.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,17 @@ impl TestDB {
265265

266266
assert_eq!(annotations, actual);
267267
}
268+
269+
pub(crate) fn check_no_diagnostics(&self) {
270+
let db: &TestDB = self;
271+
let annotations = db.extract_annotations();
272+
assert!(annotations.is_empty());
273+
274+
let mut has_diagnostics = false;
275+
db.diagnostics(|_| {
276+
has_diagnostics = true;
277+
});
278+
279+
assert!(!has_diagnostics);
280+
}
268281
}

crates/mbe/src/syntax_bridge.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,6 @@ trait TokenConvertor {
325325
while self.peek().is_some() {
326326
self.collect_leaf(&mut subtree.token_trees);
327327
}
328-
if subtree.token_trees.is_empty() {
329-
return None;
330-
}
331328
if subtree.token_trees.len() == 1 {
332329
if let tt::TokenTree::Subtree(first) = &subtree.token_trees[0] {
333330
return Some(first.clone());

0 commit comments

Comments
 (0)