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

:vis matcher for macro_rules #41012

Merged
merged 10 commits into from
Apr 17, 2017
Merged

:vis matcher for macro_rules #41012

merged 10 commits into from
Apr 17, 2017

Conversation

durka
Copy link
Contributor

@durka durka commented Apr 2, 2017

Resurrection of @DanielKeep's implementation posted with RFC 1575.

@jseyfried was of the opinion that this doesn't need an RFC.

Needed before merge:

  • sign-off from @DanielKeep since I stole his code
  • feature gate
  • docs

@rust-highfive
Copy link
Collaborator

r? @pnkfelix

(rust_highfive has picked a reviewer for you, use r? to override)

@DanielKeep
Copy link
Contributor

  • sign-off from @DanielKeep since I graciously resurrected his code lazy hack that he is

Copy link
Contributor

@jseyfried jseyfried left a comment

Choose a reason for hiding this comment

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

Code LGTM

match *tok {
TokenTree::Token(_, ref tok) => match *tok {
Comma => Ok(true),
ModSep => Ok(true),
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we just allow Comma and ModSep? Seems arbitrary to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

If I remember correctly, I allowed ModSep because you can already have pub ::path::to::a_type that you might want to parse and special-case. I allowed comma because having some kind of sequence-delimiting token is useful. If you're passing bits of parsed input around, you might have inner!($thing, $a_vis, $more_tts). Everything else was excluded based on wanting to err on the side of being conservative.

Copy link
Contributor

Choose a reason for hiding this comment

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

I allowed ModSep because you can already have pub ::path::to::a_type

This seems quite inconsistent, you can already have pub ARBITRARY_TYPE, but only a subset of paths is allowed.

This should probably use all can_begin_type tokens (in addition to comma) + ty/path/ident for MetaVarDecls.
Or all is_path_start tokens (in addition to comma) + ty/path/ident for MetaVarDecls if we want to be conservative.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can_begin_type seems good, tuple declarations really restrict us from changing visibility syntax too much in the future (as we saw during the pub(restricted) debate).

@@ -371,6 +371,7 @@ pub enum Nonterminal {
NtGenerics(ast::Generics),
NtWhereClause(ast::WhereClause),
NtArg(ast::Arg),
NtVis(ast::Visibility),
Copy link
Contributor

Choose a reason for hiding this comment

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

Now the comment // These are not exposed to macros .... applies to NtVis, it's better moved higher in the list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

/*
The rule duplication is currently unavoidable due to the leading attribute
matching.
*/
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DanielKeep why did you not use :vis at the top level of this macro??

@durka durka changed the title [WIP] :vis matcher for macro_rules :vis matcher for macro_rules Apr 3, 2017
@durka
Copy link
Contributor Author

durka commented Apr 3, 2017

Comments addressed.

@durka durka force-pushed the vis-matcher branch 2 times, most recently from 6f03265 to 41dcfec Compare April 3, 2017 02:10
@petrochenkov
Copy link
Contributor

LGTM, but needs @rust-lang/lang decision

@petrochenkov petrochenkov added I-nominated T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Apr 3, 2017
@joshtriplett
Copy link
Member

As a note: I observed someone needing this on the #rust IRC channel a few days ago, to avoid hard-coding "pub".

@nrc
Copy link
Member

nrc commented Apr 3, 2017

@rfcbot fcp merge

@rfcbot
Copy link

rfcbot commented Apr 3, 2017

Team member @nrc has proposed to merge this. The next step is review by the rest of the tagged teams:

No concerns currently listed.

Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@withoutboats
Copy link
Contributor

@rfcbot reviewed


* `vis`: a visibility qualifier. Examples: nothing (default visibility); `pub`; `pub(crate)`.

A `vis` variable may be followed by a comma, ident, type, or path.
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I'm feeling dense: Why can a vis variable be followed by a comma?

Copy link
Contributor Author

@durka durka Apr 4, 2017

Choose a reason for hiding this comment

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

To quote @DanielKeep's rationale from above (hidden comment):

I allowed comma because having some kind of sequence-delimiting token is useful. If you're passing bits of parsed input around, you might have inner!($thing, $a_vis, $more_tts).

This isn't required, we can exclude it and you'd have to use ($a_vis) to pass around parsed visibility fragments within macros.

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems harmless to me. I can't imagine using , as an "operator" in a visibility specifier (at last outside of parens or something).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pnkfelix are you still worried about this? Should we exclude it in order to get this PR into FCP? I just don't want this to continue languishing for too long...

Copy link
Member

Choose a reason for hiding this comment

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

no its okay; thanks for your patience.

@nrc nrc removed the I-nominated label Apr 6, 2017
@bors
Copy link
Contributor

bors commented Apr 7, 2017

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

@Mark-Simulacrum Mark-Simulacrum added the S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). label Apr 14, 2017
@pnkfelix
Copy link
Member

@rfcbot reviewed

@rfcbot
Copy link

rfcbot commented Apr 14, 2017

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label Apr 14, 2017
@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). labels Apr 14, 2017
@durka
Copy link
Contributor Author

durka commented Apr 15, 2017

Rebased.

@bors
Copy link
Contributor

bors commented Apr 15, 2017

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

@durka
Copy link
Contributor Author

durka commented Apr 15, 2017

Rebased.

@aturon
Copy link
Member

aturon commented Apr 17, 2017

@bors r=petrochenkov

@bors
Copy link
Contributor

bors commented Apr 17, 2017

📌 Commit cfa51f2 has been approved by petrochenkov

@aturon aturon added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 17, 2017
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Apr 17, 2017
:vis matcher for macro_rules

Resurrection of @DanielKeep's implementation posted with [RFC 1575](rust-lang/rfcs#1575).

@jseyfried was of the opinion that this doesn't need an RFC.

Needed before merge:

- [x] sign-off from @DanielKeep since I stole his code
- [x] feature gate
- [x] docs
bors added a commit that referenced this pull request Apr 17, 2017
Rollup of 3 pull requests

- Successful merges: #41012, #41280, #41290
- Failed merges:
@bors bors merged commit cfa51f2 into rust-lang:master Apr 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.