Remove crate
visibility modifier
This commit is contained in:
parent
789dfd2a25
commit
004971f3f0
@ -211,70 +211,54 @@ impl BlockLike {
|
|||||||
const VISIBILITY_FIRST: TokenSet = TokenSet::new(&[T![pub], T![crate]]);
|
const VISIBILITY_FIRST: TokenSet = TokenSet::new(&[T![pub], T![crate]]);
|
||||||
|
|
||||||
fn opt_visibility(p: &mut Parser<'_>, in_tuple_field: bool) -> bool {
|
fn opt_visibility(p: &mut Parser<'_>, in_tuple_field: bool) -> bool {
|
||||||
match p.current() {
|
if !p.at(T![pub]) {
|
||||||
T![pub] => {
|
return false;
|
||||||
let m = p.start();
|
}
|
||||||
p.bump(T![pub]);
|
|
||||||
if p.at(T!['(']) {
|
|
||||||
match p.nth(1) {
|
|
||||||
// test crate_visibility
|
|
||||||
// pub(crate) struct S;
|
|
||||||
// pub(self) struct S;
|
|
||||||
// pub(super) struct S;
|
|
||||||
|
|
||||||
// test_err crate_visibility_empty_recover
|
let m = p.start();
|
||||||
// pub() struct S;
|
p.bump(T![pub]);
|
||||||
|
if p.at(T!['(']) {
|
||||||
|
match p.nth(1) {
|
||||||
|
// test crate_visibility
|
||||||
|
// pub(crate) struct S;
|
||||||
|
// pub(self) struct S;
|
||||||
|
// pub(super) struct S;
|
||||||
|
|
||||||
// test pub_parens_typepath
|
// test_err crate_visibility_empty_recover
|
||||||
// struct B(pub (super::A));
|
// pub() struct S;
|
||||||
// struct B(pub (crate::A,));
|
|
||||||
T![crate] | T![self] | T![super] | T![ident] | T![')'] if p.nth(2) != T![:] => {
|
|
||||||
// If we are in a tuple struct, then the parens following `pub`
|
|
||||||
// might be an tuple field, not part of the visibility. So in that
|
|
||||||
// case we don't want to consume an identifier.
|
|
||||||
|
|
||||||
// test pub_tuple_field
|
// test pub_parens_typepath
|
||||||
// struct MyStruct(pub (u32, u32));
|
// struct B(pub (super::A));
|
||||||
// struct MyStruct(pub (u32));
|
// struct B(pub (crate::A,));
|
||||||
// struct MyStruct(pub ());
|
T![crate] | T![self] | T![super] | T![ident] | T![')'] if p.nth(2) != T![:] => {
|
||||||
if !(in_tuple_field && matches!(p.nth(1), T![ident] | T![')'])) {
|
// If we are in a tuple struct, then the parens following `pub`
|
||||||
p.bump(T!['(']);
|
// might be an tuple field, not part of the visibility. So in that
|
||||||
paths::use_path(p);
|
// case we don't want to consume an identifier.
|
||||||
p.expect(T![')']);
|
|
||||||
}
|
// test pub_tuple_field
|
||||||
}
|
// struct MyStruct(pub (u32, u32));
|
||||||
// test crate_visibility_in
|
// struct MyStruct(pub (u32));
|
||||||
// pub(in super::A) struct S;
|
// struct MyStruct(pub ());
|
||||||
// pub(in crate) struct S;
|
if !(in_tuple_field && matches!(p.nth(1), T![ident] | T![')'])) {
|
||||||
T![in] => {
|
p.bump(T!['(']);
|
||||||
p.bump(T!['(']);
|
paths::use_path(p);
|
||||||
p.bump(T![in]);
|
p.expect(T![')']);
|
||||||
paths::use_path(p);
|
|
||||||
p.expect(T![')']);
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.complete(p, VISIBILITY);
|
// test crate_visibility_in
|
||||||
true
|
// pub(in super::A) struct S;
|
||||||
}
|
// pub(in crate) struct S;
|
||||||
// test crate_keyword_vis
|
T![in] => {
|
||||||
// crate fn main() { }
|
p.bump(T!['(']);
|
||||||
// struct S { crate field: u32 }
|
p.bump(T![in]);
|
||||||
// struct T(crate u32);
|
paths::use_path(p);
|
||||||
T![crate] => {
|
p.expect(T![')']);
|
||||||
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);
|
|
||||||
true
|
|
||||||
}
|
}
|
||||||
_ => false,
|
|
||||||
}
|
}
|
||||||
|
m.complete(p, VISIBILITY);
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn opt_rename(p: &mut Parser<'_>) {
|
fn opt_rename(p: &mut Parser<'_>) {
|
||||||
|
@ -6,7 +6,6 @@ fn vis() {
|
|||||||
check(PrefixEntryPoint::Vis, "fn foo() {}", "");
|
check(PrefixEntryPoint::Vis, "fn foo() {}", "");
|
||||||
check(PrefixEntryPoint::Vis, "pub(fn foo() {}", "pub");
|
check(PrefixEntryPoint::Vis, "pub(fn foo() {}", "pub");
|
||||||
check(PrefixEntryPoint::Vis, "pub(crate fn foo() {}", "pub(crate");
|
check(PrefixEntryPoint::Vis, "pub(crate fn foo() {}", "pub(crate");
|
||||||
check(PrefixEntryPoint::Vis, "crate fn foo() {}", "crate");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1,63 +0,0 @@
|
|||||||
SOURCE_FILE
|
|
||||||
FN
|
|
||||||
VISIBILITY
|
|
||||||
CRATE_KW "crate"
|
|
||||||
WHITESPACE " "
|
|
||||||
FN_KW "fn"
|
|
||||||
WHITESPACE " "
|
|
||||||
NAME
|
|
||||||
IDENT "main"
|
|
||||||
PARAM_LIST
|
|
||||||
L_PAREN "("
|
|
||||||
R_PAREN ")"
|
|
||||||
WHITESPACE " "
|
|
||||||
BLOCK_EXPR
|
|
||||||
STMT_LIST
|
|
||||||
L_CURLY "{"
|
|
||||||
WHITESPACE " "
|
|
||||||
R_CURLY "}"
|
|
||||||
WHITESPACE "\n"
|
|
||||||
STRUCT
|
|
||||||
STRUCT_KW "struct"
|
|
||||||
WHITESPACE " "
|
|
||||||
NAME
|
|
||||||
IDENT "S"
|
|
||||||
WHITESPACE " "
|
|
||||||
RECORD_FIELD_LIST
|
|
||||||
L_CURLY "{"
|
|
||||||
WHITESPACE " "
|
|
||||||
RECORD_FIELD
|
|
||||||
VISIBILITY
|
|
||||||
CRATE_KW "crate"
|
|
||||||
WHITESPACE " "
|
|
||||||
NAME
|
|
||||||
IDENT "field"
|
|
||||||
COLON ":"
|
|
||||||
WHITESPACE " "
|
|
||||||
PATH_TYPE
|
|
||||||
PATH
|
|
||||||
PATH_SEGMENT
|
|
||||||
NAME_REF
|
|
||||||
IDENT "u32"
|
|
||||||
WHITESPACE " "
|
|
||||||
R_CURLY "}"
|
|
||||||
WHITESPACE "\n"
|
|
||||||
STRUCT
|
|
||||||
STRUCT_KW "struct"
|
|
||||||
WHITESPACE " "
|
|
||||||
NAME
|
|
||||||
IDENT "T"
|
|
||||||
TUPLE_FIELD_LIST
|
|
||||||
L_PAREN "("
|
|
||||||
TUPLE_FIELD
|
|
||||||
VISIBILITY
|
|
||||||
CRATE_KW "crate"
|
|
||||||
WHITESPACE " "
|
|
||||||
PATH_TYPE
|
|
||||||
PATH
|
|
||||||
PATH_SEGMENT
|
|
||||||
NAME_REF
|
|
||||||
IDENT "u32"
|
|
||||||
R_PAREN ")"
|
|
||||||
SEMICOLON ";"
|
|
||||||
WHITESPACE "\n"
|
|
@ -1,3 +0,0 @@
|
|||||||
crate fn main() { }
|
|
||||||
struct S { crate field: u32 }
|
|
||||||
struct T(crate u32);
|
|
@ -1,33 +0,0 @@
|
|||||||
SOURCE_FILE
|
|
||||||
FN
|
|
||||||
FN_KW "fn"
|
|
||||||
WHITESPACE " "
|
|
||||||
NAME
|
|
||||||
IDENT "foo"
|
|
||||||
PARAM_LIST
|
|
||||||
L_PAREN "("
|
|
||||||
R_PAREN ")"
|
|
||||||
WHITESPACE " "
|
|
||||||
BLOCK_EXPR
|
|
||||||
STMT_LIST
|
|
||||||
L_CURLY "{"
|
|
||||||
WHITESPACE " "
|
|
||||||
EXPR_STMT
|
|
||||||
CALL_EXPR
|
|
||||||
PATH_EXPR
|
|
||||||
PATH
|
|
||||||
PATH
|
|
||||||
PATH_SEGMENT
|
|
||||||
NAME_REF
|
|
||||||
CRATE_KW "crate"
|
|
||||||
COLON2 "::"
|
|
||||||
PATH_SEGMENT
|
|
||||||
NAME_REF
|
|
||||||
IDENT "foo"
|
|
||||||
ARG_LIST
|
|
||||||
L_PAREN "("
|
|
||||||
R_PAREN ")"
|
|
||||||
SEMICOLON ";"
|
|
||||||
WHITESPACE " "
|
|
||||||
R_CURLY "}"
|
|
||||||
WHITESPACE "\n"
|
|
@ -1 +0,0 @@
|
|||||||
fn foo() { crate::foo(); }
|
|
Loading…
x
Reference in New Issue
Block a user