Skip to content

Commit 3759c41

Browse files
committed
Auto merge of #15287 - lowr:internal/remove-crate-vis, r=lnicola
internal: remove `crate` visibility modifier This PR removes `crate` as a now-unaccepted experimental visibility modifier from our parser. This feature has been [unaccepted] and [removed] from rustc more than a year ago, so I don't think this removal affects anyone. [unaccepted]: rust-lang/rust#53120 (comment) [removed]: rust-lang/rust#97239
2 parents cc2f0ec + 004971f commit 3759c41

File tree

6 files changed

+43
-160
lines changed

6 files changed

+43
-160
lines changed

crates/parser/src/grammar.rs

+43-59
Original file line numberDiff line numberDiff line change
@@ -211,70 +211,54 @@ impl BlockLike {
211211
const VISIBILITY_FIRST: TokenSet = TokenSet::new(&[T![pub], T![crate]]);
212212

213213
fn opt_visibility(p: &mut Parser<'_>, in_tuple_field: bool) -> bool {
214-
match p.current() {
215-
T![pub] => {
216-
let m = p.start();
217-
p.bump(T![pub]);
218-
if p.at(T!['(']) {
219-
match p.nth(1) {
220-
// test crate_visibility
221-
// pub(crate) struct S;
222-
// pub(self) struct S;
223-
// pub(super) struct S;
224-
225-
// test_err crate_visibility_empty_recover
226-
// pub() struct S;
227-
228-
// test pub_parens_typepath
229-
// struct B(pub (super::A));
230-
// struct B(pub (crate::A,));
231-
T![crate] | T![self] | T![super] | T![ident] | T![')'] if p.nth(2) != T![:] => {
232-
// If we are in a tuple struct, then the parens following `pub`
233-
// might be an tuple field, not part of the visibility. So in that
234-
// case we don't want to consume an identifier.
235-
236-
// test pub_tuple_field
237-
// struct MyStruct(pub (u32, u32));
238-
// struct MyStruct(pub (u32));
239-
// struct MyStruct(pub ());
240-
if !(in_tuple_field && matches!(p.nth(1), T![ident] | T![')'])) {
241-
p.bump(T!['(']);
242-
paths::use_path(p);
243-
p.expect(T![')']);
244-
}
245-
}
246-
// test crate_visibility_in
247-
// pub(in super::A) struct S;
248-
// pub(in crate) struct S;
249-
T![in] => {
250-
p.bump(T!['(']);
251-
p.bump(T![in]);
252-
paths::use_path(p);
253-
p.expect(T![')']);
254-
}
255-
_ => {}
214+
if !p.at(T![pub]) {
215+
return false;
216+
}
217+
218+
let m = p.start();
219+
p.bump(T![pub]);
220+
if p.at(T!['(']) {
221+
match p.nth(1) {
222+
// test crate_visibility
223+
// pub(crate) struct S;
224+
// pub(self) struct S;
225+
// pub(super) struct S;
226+
227+
// test_err crate_visibility_empty_recover
228+
// pub() struct S;
229+
230+
// test pub_parens_typepath
231+
// struct B(pub (super::A));
232+
// struct B(pub (crate::A,));
233+
T![crate] | T![self] | T![super] | T![ident] | T![')'] if p.nth(2) != T![:] => {
234+
// If we are in a tuple struct, then the parens following `pub`
235+
// might be an tuple field, not part of the visibility. So in that
236+
// case we don't want to consume an identifier.
237+
238+
// test pub_tuple_field
239+
// struct MyStruct(pub (u32, u32));
240+
// struct MyStruct(pub (u32));
241+
// struct MyStruct(pub ());
242+
if !(in_tuple_field && matches!(p.nth(1), T![ident] | T![')'])) {
243+
p.bump(T!['(']);
244+
paths::use_path(p);
245+
p.expect(T![')']);
256246
}
257247
}
258-
m.complete(p, VISIBILITY);
259-
true
260-
}
261-
// test crate_keyword_vis
262-
// crate fn main() { }
263-
// struct S { crate field: u32 }
264-
// struct T(crate u32);
265-
T![crate] => {
266-
if p.nth_at(1, T![::]) {
267-
// test crate_keyword_path
268-
// fn foo() { crate::foo(); }
269-
return false;
248+
// test crate_visibility_in
249+
// pub(in super::A) struct S;
250+
// pub(in crate) struct S;
251+
T![in] => {
252+
p.bump(T!['(']);
253+
p.bump(T![in]);
254+
paths::use_path(p);
255+
p.expect(T![')']);
270256
}
271-
let m = p.start();
272-
p.bump(T![crate]);
273-
m.complete(p, VISIBILITY);
274-
true
257+
_ => {}
275258
}
276-
_ => false,
277259
}
260+
m.complete(p, VISIBILITY);
261+
true
278262
}
279263

280264
fn opt_rename(p: &mut Parser<'_>) {

crates/parser/src/tests/prefix_entries.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ fn vis() {
66
check(PrefixEntryPoint::Vis, "fn foo() {}", "");
77
check(PrefixEntryPoint::Vis, "pub(fn foo() {}", "pub");
88
check(PrefixEntryPoint::Vis, "pub(crate fn foo() {}", "pub(crate");
9-
check(PrefixEntryPoint::Vis, "crate fn foo() {}", "crate");
109
}
1110

1211
#[test]

crates/parser/test_data/parser/inline/ok/0040_crate_keyword_vis.rast

-63
This file was deleted.

crates/parser/test_data/parser/inline/ok/0040_crate_keyword_vis.rs

-3
This file was deleted.

crates/parser/test_data/parser/inline/ok/0125_crate_keyword_path.rast

-33
This file was deleted.

crates/parser/test_data/parser/inline/ok/0125_crate_keyword_path.rs

-1
This file was deleted.

0 commit comments

Comments
 (0)