Unnamed repository; edit this file 'description' to name the repository.
internal: fix bugs in tests by simplifying code
| -rw-r--r-- | crates/parser/src/grammar.rs | 10 | ||||
| -rw-r--r-- | crates/parser/src/grammar/expressions.rs | 1 | ||||
| -rw-r--r-- | crates/sourcegen/src/lib.rs | 26 | ||||
| -rw-r--r-- | crates/syntax/test_data/parser/inline/ok/0110_use_path.rast | 74 | ||||
| -rw-r--r-- | crates/syntax/test_data/parser/inline/ok/0110_use_path.rs | 5 | ||||
| -rw-r--r-- | crates/syntax/test_data/parser/inline/ok/0115_tuple_field_attrs.rast | 47 | ||||
| -rw-r--r-- | crates/syntax/test_data/parser/inline/ok/0115_tuple_field_attrs.rs | 4 |
7 files changed, 144 insertions, 23 deletions
diff --git a/crates/parser/src/grammar.rs b/crates/parser/src/grammar.rs index 382cc4fcc5..7243b89583 100644 --- a/crates/parser/src/grammar.rs +++ b/crates/parser/src/grammar.rs @@ -194,10 +194,12 @@ fn opt_visibility(p: &mut Parser) -> bool { // crate fn main() { } // struct S { crate field: u32 } // struct T(crate u32); - // - // test crate_keyword_path - // fn foo() { crate::foo(); } - T![crate] if !p.nth_at(1, T![::]) => { + T![crate] => { + if p.nth_at(1, T![::]) { + // test crate_keyword_path + // fn foo() { crate::foo(); } + return false; + } let m = p.start(); p.bump(T![crate]); m.complete(p, VISIBILITY); diff --git a/crates/parser/src/grammar/expressions.rs b/crates/parser/src/grammar/expressions.rs index 686a643456..001be099e6 100644 --- a/crates/parser/src/grammar/expressions.rs +++ b/crates/parser/src/grammar/expressions.rs @@ -374,7 +374,6 @@ fn lhs(p: &mut Parser, r: Restrictions) -> Option<(CompletedMarker, BlockLike)> // let mut p = F{x: 5}; // {p}.x = 10; // } - // let (lhs, blocklike) = atom::atom_expr(p, r)?; return Some(postfix_expr(p, lhs, blocklike, !(r.prefer_stmt && blocklike.is_block()))); } diff --git a/crates/sourcegen/src/lib.rs b/crates/sourcegen/src/lib.rs index 7d179e00e7..d9226d0681 100644 --- a/crates/sourcegen/src/lib.rs +++ b/crates/sourcegen/src/lib.rs @@ -55,22 +55,20 @@ impl CommentBlock { assert!(tag.starts_with(char::is_uppercase)); let tag = format!("{}:", tag); - let mut res = Vec::new(); - for mut block in CommentBlock::do_extract(text, true) { - let first = block.contents.remove(0); - if let Some(id) = first.strip_prefix(&tag) { - block.id = id.trim().to_string(); - res.push(block); - } - } - res + // Would be nice if we had `.retain_mut` here! + CommentBlock::extract_untagged(text) + .into_iter() + .filter_map(|mut block| { + let first = block.contents.remove(0); + first.strip_prefix(&tag).map(|id| { + block.id = id.trim().to_string(); + block + }) + }) + .collect() } pub fn extract_untagged(text: &str) -> Vec<CommentBlock> { - CommentBlock::do_extract(text, false) - } - - fn do_extract(text: &str, allow_blocks_with_empty_lines: bool) -> Vec<CommentBlock> { let mut res = Vec::new(); let prefix = "// "; @@ -79,7 +77,7 @@ impl CommentBlock { let dummy_block = CommentBlock { id: String::new(), line: 0, contents: Vec::new() }; let mut block = dummy_block.clone(); for (line_num, line) in lines.enumerate() { - if line == "//" && allow_blocks_with_empty_lines { + if line == "//" { block.contents.push(String::new()); continue; } diff --git a/crates/syntax/test_data/parser/inline/ok/0110_use_path.rast b/crates/syntax/test_data/parser/inline/ok/0110_use_path.rast index c9fad5f8c5..ac51eb91d2 100644 --- a/crates/syntax/test_data/parser/inline/ok/0110_use_path.rast +++ b/crates/syntax/test_data/parser/inline/ok/0110_use_path.rast @@ -1,4 +1,4 @@ [email protected] "use" @@ -35,4 +35,74 @@ [email protected] [email protected] "// Rust 2018 - Unifor ..." - [email protected] "\n" + [email protected] "\n\n" + [email protected] "use" + [email protected] " " + [email protected] "self" + [email protected] "::" + [email protected] "module" + [email protected] "::" + [email protected] "Item" + [email protected] ";" + [email protected] "\n" + [email protected] "use" + [email protected] " " + [email protected] "crate" + [email protected] "::" + [email protected] "Item" + [email protected] ";" + [email protected] "\n" + [email protected] "use" + [email protected] " " + [email protected] "self" + [email protected] "::" + [email protected] "some" + [email protected] "::" + [email protected] "Struct" + [email protected] ";" + [email protected] "\n" + [email protected] "use" + [email protected] " " + [email protected] "crate_name" + [email protected] "::" + [email protected] "some_item" + [email protected] ";" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0110_use_path.rs b/crates/syntax/test_data/parser/inline/ok/0110_use_path.rs index 328e947360..1e436a6bc2 100644 --- a/crates/syntax/test_data/parser/inline/ok/0110_use_path.rs +++ b/crates/syntax/test_data/parser/inline/ok/0110_use_path.rs @@ -1,3 +1,8 @@ use ::crate_name; // Rust 2018 - All flavours use crate_name; // Rust 2018 - Anchored paths use item_in_scope_or_crate_name; // Rust 2018 - Uniform Paths + +use self::module::Item; +use crate::Item; +use self::some::Struct; +use crate_name::some_item; diff --git a/crates/syntax/test_data/parser/inline/ok/0115_tuple_field_attrs.rast b/crates/syntax/test_data/parser/inline/ok/0115_tuple_field_attrs.rast index db2b645b06..533f738e15 100644 --- a/crates/syntax/test_data/parser/inline/ok/0115_tuple_field_attrs.rast +++ b/crates/syntax/test_data/parser/inline/ok/0115_tuple_field_attrs.rast @@ -1,4 +1,4 @@ [email protected] "struct" @@ -39,4 +39,47 @@ [email protected] [email protected] "\n" - [email protected] "\n" + [email protected] "\n\n" + [email protected] "enum" + [email protected] " " + [email protected] "S" + [email protected] " " + [email protected] "{" + [email protected] "\n " + [email protected] "Uri" + [email protected] "(" + [email protected] "#" + [email protected] "[" + [email protected] "serde" + [email protected] "(" + [email protected] "with" + [email protected] " " + [email protected] "=" + [email protected] " " + [email protected] "\"url_serde\"" + [email protected] ")" + [email protected] "]" + [email protected] " " + [email protected] "Uri" + [email protected] ")" + [email protected] "," + [email protected] "\n" + [email protected] "}" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0115_tuple_field_attrs.rs b/crates/syntax/test_data/parser/inline/ok/0115_tuple_field_attrs.rs index 635b9ac21a..4da379d0ed 100644 --- a/crates/syntax/test_data/parser/inline/ok/0115_tuple_field_attrs.rs +++ b/crates/syntax/test_data/parser/inline/ok/0115_tuple_field_attrs.rs @@ -2,3 +2,7 @@ struct S ( #[serde(with = "url_serde")] pub Uri, ); + +enum S { + Uri(#[serde(with = "url_serde")] Uri), +} |