Skip to content

Review proc macro API 1.2 - #50473

Merged
bors merged 7 commits into
rust-lang:masterfrom
petrochenkov:pmapi
May 16, 2018
Merged

Review proc macro API 1.2#50473
bors merged 7 commits into
rust-lang:masterfrom
petrochenkov:pmapi

Conversation

@petrochenkov

@petrochenkov petrochenkov commented May 6, 2018

Copy link
Copy Markdown
Contributor

cc #38356

Summary of applied changes:

  • Documentation for proc macro API 1.2 is expanded.
  • Renamed APIs: Term -> Ident, TokenTree::Term -> TokenTree::Ident, Op -> Punct, TokenTree::Op -> TokenTree::Punct, Op::op -> Punct::as_char.
  • Removed APIs: Ident::as_str, use Display impl for Ident instead.
  • New APIs (not stabilized in 1.2): Ident::new_raw for creating a raw identifier (I'm not sure new_x it's a very idiomatic name though).
  • Runtime changes:
    • Punct::new now ensures that the input char is a valid punctuation character in Rust.
    • Ident::new ensures that the input str is a valid identifier in Rust.
    • Lifetimes in proc macros are now represented as two joint tokens - Punct('\'', Spacing::Joint) and Ident("lifetime_name_without_quote") similarly to multi-character operators.
  • Stabilized APIs: None yet.

A bit of motivation for renaming (although it was already stated in the review comments):

  • With my compiler frontend glasses on Ident is the single most appropriate name for this thing, especially if we are doing input validation on construction. TokenTree::Ident effectively wraps token::Ident or ast::Ident + is_raw, its meaning is "identifier" and it's already named ident in declarative macros.
  • Regarding Punct, the motivation is that Op is actively misleading. The thing doesn't mean an operator, it's neither a subset of operators (there is non-operator punctuation in the language), nor superset (operators can be multicharacter while this thing is always a single character). So I named it Punct (first proposed in the original RFC, then by @SimonSapin) , together with input validation it's now a subset of ASCII punctuation character category (u8::is_ascii_punctuation).

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.