internal: fix bugs in tests by simplifying code
This commit is contained in:
parent
80991356e1
commit
940b3afd00
@ -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);
|
||||
|
@ -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())));
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
SOURCE_FILE@0..154
|
||||
SOURCE_FILE@0..247
|
||||
USE@0..17
|
||||
USE_KW@0..3 "use"
|
||||
WHITESPACE@3..4 " "
|
||||
@ -35,4 +35,74 @@ SOURCE_FILE@0..154
|
||||
SEMICOLON@123..124 ";"
|
||||
WHITESPACE@124..125 " "
|
||||
COMMENT@125..153 "// Rust 2018 - Unifor ..."
|
||||
WHITESPACE@153..154 "\n"
|
||||
WHITESPACE@153..155 "\n\n"
|
||||
USE@155..178
|
||||
USE_KW@155..158 "use"
|
||||
WHITESPACE@158..159 " "
|
||||
USE_TREE@159..177
|
||||
PATH@159..177
|
||||
PATH@159..171
|
||||
PATH@159..163
|
||||
PATH_SEGMENT@159..163
|
||||
NAME_REF@159..163
|
||||
SELF_KW@159..163 "self"
|
||||
COLON2@163..165 "::"
|
||||
PATH_SEGMENT@165..171
|
||||
NAME_REF@165..171
|
||||
IDENT@165..171 "module"
|
||||
COLON2@171..173 "::"
|
||||
PATH_SEGMENT@173..177
|
||||
NAME_REF@173..177
|
||||
IDENT@173..177 "Item"
|
||||
SEMICOLON@177..178 ";"
|
||||
WHITESPACE@178..179 "\n"
|
||||
USE@179..195
|
||||
USE_KW@179..182 "use"
|
||||
WHITESPACE@182..183 " "
|
||||
USE_TREE@183..194
|
||||
PATH@183..194
|
||||
PATH@183..188
|
||||
PATH_SEGMENT@183..188
|
||||
NAME_REF@183..188
|
||||
CRATE_KW@183..188 "crate"
|
||||
COLON2@188..190 "::"
|
||||
PATH_SEGMENT@190..194
|
||||
NAME_REF@190..194
|
||||
IDENT@190..194 "Item"
|
||||
SEMICOLON@194..195 ";"
|
||||
WHITESPACE@195..196 "\n"
|
||||
USE@196..219
|
||||
USE_KW@196..199 "use"
|
||||
WHITESPACE@199..200 " "
|
||||
USE_TREE@200..218
|
||||
PATH@200..218
|
||||
PATH@200..210
|
||||
PATH@200..204
|
||||
PATH_SEGMENT@200..204
|
||||
NAME_REF@200..204
|
||||
SELF_KW@200..204 "self"
|
||||
COLON2@204..206 "::"
|
||||
PATH_SEGMENT@206..210
|
||||
NAME_REF@206..210
|
||||
IDENT@206..210 "some"
|
||||
COLON2@210..212 "::"
|
||||
PATH_SEGMENT@212..218
|
||||
NAME_REF@212..218
|
||||
IDENT@212..218 "Struct"
|
||||
SEMICOLON@218..219 ";"
|
||||
WHITESPACE@219..220 "\n"
|
||||
USE@220..246
|
||||
USE_KW@220..223 "use"
|
||||
WHITESPACE@223..224 " "
|
||||
USE_TREE@224..245
|
||||
PATH@224..245
|
||||
PATH@224..234
|
||||
PATH_SEGMENT@224..234
|
||||
NAME_REF@224..234
|
||||
IDENT@224..234 "crate_name"
|
||||
COLON2@234..236 "::"
|
||||
PATH_SEGMENT@236..245
|
||||
NAME_REF@236..245
|
||||
IDENT@236..245 "some_item"
|
||||
SEMICOLON@245..246 ";"
|
||||
WHITESPACE@246..247 "\n"
|
||||
|
@ -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;
|
||||
|
@ -1,4 +1,4 @@
|
||||
SOURCE_FILE@0..60
|
||||
SOURCE_FILE@0..115
|
||||
STRUCT@0..59
|
||||
STRUCT_KW@0..6 "struct"
|
||||
WHITESPACE@6..7 " "
|
||||
@ -39,4 +39,47 @@ SOURCE_FILE@0..60
|
||||
WHITESPACE@56..57 "\n"
|
||||
R_PAREN@57..58 ")"
|
||||
SEMICOLON@58..59 ";"
|
||||
WHITESPACE@59..60 "\n"
|
||||
WHITESPACE@59..61 "\n\n"
|
||||
ENUM@61..114
|
||||
ENUM_KW@61..65 "enum"
|
||||
WHITESPACE@65..66 " "
|
||||
NAME@66..67
|
||||
IDENT@66..67 "S"
|
||||
WHITESPACE@67..68 " "
|
||||
VARIANT_LIST@68..114
|
||||
L_CURLY@68..69 "{"
|
||||
WHITESPACE@69..74 "\n "
|
||||
VARIANT@74..111
|
||||
NAME@74..77
|
||||
IDENT@74..77 "Uri"
|
||||
TUPLE_FIELD_LIST@77..111
|
||||
L_PAREN@77..78 "("
|
||||
TUPLE_FIELD@78..110
|
||||
ATTR@78..106
|
||||
POUND@78..79 "#"
|
||||
L_BRACK@79..80 "["
|
||||
META@80..105
|
||||
PATH@80..85
|
||||
PATH_SEGMENT@80..85
|
||||
NAME_REF@80..85
|
||||
IDENT@80..85 "serde"
|
||||
TOKEN_TREE@85..105
|
||||
L_PAREN@85..86 "("
|
||||
IDENT@86..90 "with"
|
||||
WHITESPACE@90..91 " "
|
||||
EQ@91..92 "="
|
||||
WHITESPACE@92..93 " "
|
||||
STRING@93..104 "\"url_serde\""
|
||||
R_PAREN@104..105 ")"
|
||||
R_BRACK@105..106 "]"
|
||||
WHITESPACE@106..107 " "
|
||||
PATH_TYPE@107..110
|
||||
PATH@107..110
|
||||
PATH_SEGMENT@107..110
|
||||
NAME_REF@107..110
|
||||
IDENT@107..110 "Uri"
|
||||
R_PAREN@110..111 ")"
|
||||
COMMA@111..112 ","
|
||||
WHITESPACE@112..113 "\n"
|
||||
R_CURLY@113..114 "}"
|
||||
WHITESPACE@114..115 "\n"
|
||||
|
@ -2,3 +2,7 @@ struct S (
|
||||
#[serde(with = "url_serde")]
|
||||
pub Uri,
|
||||
);
|
||||
|
||||
enum S {
|
||||
Uri(#[serde(with = "url_serde")] Uri),
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user