Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse pub(restricted) visibilities on tuple struct fields #33161

Merged
merged 2 commits into from
Apr 28, 2016

Conversation

jseyfried
Copy link
Contributor

@jseyfried jseyfried commented Apr 23, 2016

Parse pub(restricted) on tuple struct fields (cc #32409).

r? @nikomatsakis

@jseyfried jseyfried changed the title Parse tuple struct field vis Parse pub(restricted) visibilities on tuple struct fields Apr 23, 2016
@jseyfried
Copy link
Contributor Author

cc @petrochenkov

@petrochenkov
Copy link
Contributor

petrochenkov commented Apr 23, 2016

Ha, I expected to implement this myself today.

I'd like to see more tests for error messages for failed reinterpretation.
Also, ty nonterminals shouldn't be interpreted as visibilities even if they expand into (path), i.e. pub $t u8 or pub ($t) u8 where $t: ty shouldn't parse (this needs tests too).

@jseyfried
Copy link
Contributor Author

jseyfried commented Apr 23, 2016

@petrochenkov

I'd like to see more tests for error messages for failed reinterpretation.

Will do. Do you think there should be a different error message for failed reinterpretation?
Now, pub(non-path type) ... behaves exactly as it did before this PR.

Also, ty nonterminals shouldn't be interpreted as visibilities even if they expand into (path)

Good point, I hadn't considered that. Will do.

@petrochenkov
Copy link
Contributor

Do you think there should be a different error message for failed reinterpretation?

It just needs to be reasonable, I think the current one is ok.

@bors
Copy link
Contributor

bors commented Apr 24, 2016

☔ The latest upstream changes (presumably #33179) made this pull request unmergeable. Please resolve the merge conflicts.

@jseyfried jseyfried force-pushed the parse_tuple_struct_field_vis branch from 0deeebf to 1bfc50b Compare April 25, 2016 02:56
type T = ();
struct S1(pub(foo) (), pub(T), pub(crate) (), pub(((), T)));
struct S2(pub(id!(foo)) ()); //~ ERROR expected one of `+` or `,`, found `(`
//~| ERROR expected one of `+`, `;`, or `where`, found `(`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cf #33188

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nikomatsakis we have this test case, but the macro id should be

#![feature(type_macros)]
macro_rules! id {
    ($t:ty) => { $t }
}

instead of how it is defined now.

Is this the type of test you had in mind?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add more tests, but due to poor error recovery we need one test per parse error.

@jseyfried
Copy link
Contributor Author

I rebased and addressed @petrochenkov's comments.

let ty = p.parse_ty_sum()?;
let mut vis = p.parse_visibility(false)?;
let ty_is_interpolated =
p.token.is_interpolated() || p.look_ahead(1, |t| t.is_interpolated());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have any tests covering this interpolated case? I expected to see one where we substitute in a $t:ty.

It is a bit of a shame that we have no $p:path fragment specificier, though I guess rust-lang/rfcs#1575 would address the use case.

@nikomatsakis
Copy link
Contributor

@jseyfried

Is this the type of test you had in mind?

Yes, and maybe also having pub($t) in the expansion?

@jseyfried
Copy link
Contributor Author

also having pub($t) in the expansion?

Good point, will do.

@nikomatsakis
Copy link
Contributor

r=me w/ a few more tests

also, @jseyfried, you can I think use the revisions mechanism if you'd prefer to have multiple errors per file. You have to add

// revisions: a b c

then write code with #[cfg(a)] etc. You can then specify the expected error as

//[a] error-pattern:foo

or //[a]~ ERROR foo.

@nikomatsakis
Copy link
Contributor

(Though maybe it doesn't work with that class of test yet)

@jseyfried
Copy link
Contributor Author

use the revisions mechanism if you'd prefer to have multiple errors per file

Interesting, I'll give it a try.

@jseyfried
Copy link
Contributor Author

The revisions mechanism won't work for parse errors since we always parse and expand unconfigured items (cf my comment in #25544).

@jseyfried jseyfried force-pushed the parse_tuple_struct_field_vis branch from 1bfc50b to d2ca7d0 Compare April 27, 2016 22:03
@jseyfried jseyfried force-pushed the parse_tuple_struct_field_vis branch from d2ca7d0 to 78a8127 Compare April 27, 2016 23:42
@jseyfried
Copy link
Contributor Author

@bors r=nikomatsakis

@bors
Copy link
Contributor

bors commented Apr 27, 2016

📌 Commit 78a8127 has been approved by nikomatsakis

@bors
Copy link
Contributor

bors commented Apr 28, 2016

⌛ Testing commit 78a8127 with merge 0f9ba99...

bors added a commit that referenced this pull request Apr 28, 2016
…matsakis

Parse `pub(restricted)` visibilities on tuple struct fields

Parse `pub(restricted)` on tuple struct fields (cc #32409).

r? @nikomatsakis
@bors bors merged commit 78a8127 into rust-lang:master Apr 28, 2016
@jseyfried jseyfried deleted the parse_tuple_struct_field_vis branch May 31, 2016 23:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants