mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Allow include! an empty content file
This commit is contained in:
parent
b5804296dd
commit
20d55ce44d
3 changed files with 33 additions and 3 deletions
|
@ -7,6 +7,11 @@ fn check_diagnostics(ra_fixture: &str) {
|
||||||
db.check_diagnostics();
|
db.check_diagnostics();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn check_no_diagnostics(ra_fixture: &str) {
|
||||||
|
let db: TestDB = TestDB::with_files(ra_fixture);
|
||||||
|
db.check_no_diagnostics();
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unresolved_import() {
|
fn unresolved_import() {
|
||||||
check_diagnostics(
|
check_diagnostics(
|
||||||
|
@ -201,6 +206,21 @@ fn builtin_macro_fails_expansion() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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]
|
#[test]
|
||||||
fn good_out_dir_diagnostic() {
|
fn good_out_dir_diagnostic() {
|
||||||
check_diagnostics(
|
check_diagnostics(
|
||||||
|
|
|
@ -265,4 +265,17 @@ impl TestDB {
|
||||||
|
|
||||||
assert_eq!(annotations, actual);
|
assert_eq!(annotations, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn check_no_diagnostics(&self) {
|
||||||
|
let db: &TestDB = self;
|
||||||
|
let annotations = db.extract_annotations();
|
||||||
|
assert!(annotations.is_empty());
|
||||||
|
|
||||||
|
let mut has_diagnostics = false;
|
||||||
|
db.diagnostics(|_| {
|
||||||
|
has_diagnostics = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert!(!has_diagnostics);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -325,9 +325,6 @@ trait TokenConvertor {
|
||||||
while self.peek().is_some() {
|
while self.peek().is_some() {
|
||||||
self.collect_leaf(&mut subtree.token_trees);
|
self.collect_leaf(&mut subtree.token_trees);
|
||||||
}
|
}
|
||||||
if subtree.token_trees.is_empty() {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
if subtree.token_trees.len() == 1 {
|
if subtree.token_trees.len() == 1 {
|
||||||
if let tt::TokenTree::Subtree(first) = &subtree.token_trees[0] {
|
if let tt::TokenTree::Subtree(first) = &subtree.token_trees[0] {
|
||||||
return Some(first.clone());
|
return Some(first.clone());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue