]> git.lizzy.rs Git - rust.git/commitdiff
Allow include! an empty content file
authorEdwin Cheng <edwin0cheng@gmail.com>
Sat, 3 Apr 2021 04:50:55 +0000 (12:50 +0800)
committerEdwin Cheng <edwin0cheng@gmail.com>
Sat, 3 Apr 2021 04:50:55 +0000 (12:50 +0800)
crates/hir_def/src/nameres/tests/diagnostics.rs
crates/hir_def/src/test_db.rs
crates/mbe/src/syntax_bridge.rs

index a89061c2e800736099a84d9189c27d1610f2c48c..fefdadb225d902a8dad37d985475f50e757fa321 100644 (file)
@@ -7,6 +7,11 @@ fn check_diagnostics(ra_fixture: &str) {
     db.check_diagnostics();
 }
 
+fn check_no_diagnostics(ra_fixture: &str) {
+    let db: TestDB = TestDB::with_files(ra_fixture);
+    db.check_no_diagnostics();
+}
+
 #[test]
 fn unresolved_import() {
     check_diagnostics(
@@ -201,6 +206,21 @@ macro_rules! include { () => {} }
     );
 }
 
+#[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(
index 10977761c93cfae3880c094e99d6a35dbe8b9f10..dd36106f8d21a291e63c7fc9f2a04daab8911613 100644 (file)
@@ -265,4 +265,17 @@ pub(crate) fn check_diagnostics(&self) {
 
         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);
+    }
 }
index 9d433b3b0bd20775c2776e4d572e912230947b95..ae0780072a52633d71a5548f56cc19dfa4ebbe3d 100644 (file)
@@ -325,9 +325,6 @@ fn go(&mut self) -> Option<tt::Subtree> {
         while self.peek().is_some() {
             self.collect_leaf(&mut subtree.token_trees);
         }
-        if subtree.token_trees.is_empty() {
-            return None;
-        }
         if subtree.token_trees.len() == 1 {
             if let tt::TokenTree::Subtree(first) = &subtree.token_trees[0] {
                 return Some(first.clone());