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

Start removing Nonterminal #114647

Closed
wants to merge 18 commits into from

Commits on Aug 22, 2023

  1. Don't match invisible delimiters in can_begin_expr.

    This has no effect right now because invisible delimiters aren't
    produced by `TokenCursor`, but it will make more sense once invisible
    delimiter sources are introduced.
    nnethercote committed Aug 22, 2023
    Configuration menu
    Copy the full SHA
    e5035df View commit details
    Browse the repository at this point in the history
  2. Introduce InvisibleSource on invisible delimiters.

    It's not used meaningfully yet, but will be needed to get rid of
    interpolated tokens.
    nnethercote committed Aug 22, 2023
    Configuration menu
    Copy the full SHA
    eb03a6d View commit details
    Browse the repository at this point in the history
  3. Add invisible open delimiters to TokenDescription.

    Invisible delimiters pretty-print as empty strings, and changing that
    can break some proc macros. But error messages saying "expected
    identifer, found ``" are bad. So this commit adds support for invisible
    open delimiters in `TokenDescription` so they print as "invisible open
    delimiter" in error messages, instead of "``".
    
    It's not used meaningfully yet, but will be needed to get rid of interpolated
    tokens.
    nnethercote committed Aug 22, 2023
    Configuration menu
    Copy the full SHA
    ad7c621 View commit details
    Browse the repository at this point in the history
  4. Tweak expand_incomplete_parse warning.

    By using `token_descr`, as is done for many other errors, we can get
    slightly better descriptions in error messages, e.g.
    "macro expansion ignores token `let` and any following" becomes
    "macro expansion ignores keyword `let` and any tokens following".
    
    This will be more important once invisible delimiters start being
    mentioned in error messages.
    nnethercote committed Aug 22, 2023
    Configuration menu
    Copy the full SHA
    e927137 View commit details
    Browse the repository at this point in the history
  5. Streamline NamedMatch.

    This will make things nicer as more variants are added to
    `ParseNtResult`.
    nnethercote committed Aug 22, 2023
    Configuration menu
    Copy the full SHA
    fcce5dd View commit details
    Browse the repository at this point in the history
  6. Introduce InvisibleSource::MetaVar.

    Token sequences delimited with these invisible delimiters will
    eventually replace `Token::Interpolated` for declarative macro
    expansions.
    
    There are no uses yet, but this commit does modify
    `nonterminal_may_begin_with` so that every `Interpolated` test is now
    mirrored with a `InvisibleSource::MetaVar` test. This means that `Nt*`
    cases can now be removed from that function one at a time without any
    other changes required.
    nnethercote committed Aug 22, 2023
    Configuration menu
    Copy the full SHA
    68d7597 View commit details
    Browse the repository at this point in the history
  7. Remove NtVis.

    We now use invisible delimiters for expanded `vis` fragments, instead of
    `Token::Interpolated`.
    
    This slightly changes some pretty-printed output in tests, but not in
    any significant way.
    nnethercote committed Aug 22, 2023
    Configuration menu
    Copy the full SHA
    8da7e52 View commit details
    Browse the repository at this point in the history
  8. Remove NtTy.

    Notes about tests:
    
    - tests/ui/parser/macro/trait-object-macro-matcher.rs: the syntax error
      is duplicated, because it occurs now when parsing the decl macro
      input, and also when parsing the expanded decl macro. But this won't
      show up for normal users due to error de-duplication.
    
    - The output of stringify! is uglier, due to `print_tts` producing
      uglier output than AST pretty-printing.
    nnethercote committed Aug 22, 2023
    Configuration menu
    Copy the full SHA
    7d9f7cb View commit details
    Browse the repository at this point in the history
  9. Remove NtPat.

    nnethercote committed Aug 22, 2023
    Configuration menu
    Copy the full SHA
    cab935c View commit details
    Browse the repository at this point in the history
  10. Remove NtItem.

    This requires adding `stream_pretty_printing_compatibility_hack`, which
    will replace `nt_pretty_printing_compatibility_hack` once `NtStmt` is
    removed.
    
    Notable test changes:
    - `tests/ui/macros/nonterminal-matching.rs` now passes. Removal of
      `Token::Interpolated` will remove the "captured metavariables except
      for `:tt`, `:ident` and `:lifetime` cannot be compared to other
      tokens" restriction.
    
    - `tests/ui/proc-macro/expand-to-derive.rs`: the diff looks large but
      the only difference is the insertion of a single invisible-delimited
      group. I hope this doesn't cause any new `ProceduralMasquerade`-type
      problems.
    nnethercote committed Aug 22, 2023
    Configuration menu
    Copy the full SHA
    1a07e0c View commit details
    Browse the repository at this point in the history
  11. Remove NtStmt.

    This means `nt_pretty_printing_compatibility_hack` can also be removed.
    
    The handling of statements in `transcribe` is slightly different to
    other nonterminal kinds, due to the lack of `from_ast` implementation
    for empty statements.
    nnethercote committed Aug 22, 2023
    Configuration menu
    Copy the full SHA
    06ff446 View commit details
    Browse the repository at this point in the history
  12. Remove NtMeta.

    Note: there was an existing code path involving `Interpolated` in
    `MetaItem::from_tokens` that was dead. This commit transfers that to the
    new form, but puts an `unreachable!` call inside it.
    nnethercote committed Aug 22, 2023
    Configuration menu
    Copy the full SHA
    b6e6ee0 View commit details
    Browse the repository at this point in the history
  13. Remove NtPath.

    nnethercote committed Aug 22, 2023
    Configuration menu
    Copy the full SHA
    467c76e View commit details
    Browse the repository at this point in the history
  14. Remove NtBlock.

    nnethercote committed Aug 22, 2023
    Configuration menu
    Copy the full SHA
    ad011f2 View commit details
    Browse the repository at this point in the history
  15. XXX: NtExpr/NtLiteral

    [xt] move from_token
    
    Getting a test failure here:
    ```
    Building tool error_index_generator (stage1 -> stage2, x86_64-unknown-linux-gnu)
       Compiling cfg-if v1.0.0
        ...
       Compiling mdbook v0.4.31
    error: internal compiler error: the following error was constructed but not emitted
    
    error: unexpected token: keyword `self`
       --> /home/njn/.cargo/registry/src/index.crates.io-6f17d22bba15001f/mdbook-0.4.31/src/book/summary.rs:275:31
        |
    275 |                         bail!(self.parse_error("Suffix chapters cannot be followed by a list"));
        |                               ^^^^
    
    thread 'rustc' panicked at compiler/rustc_errors/src/diagnostic_builder.rs:775:21:
    error was constructed but not emitted
    ```
    nnethercote committed Aug 22, 2023
    Configuration menu
    Copy the full SHA
    26c0de1 View commit details
    Browse the repository at this point in the history
  16. Remove NtIdent/NtLifetime/Nonterminal/Token::Interpolated.

    Remnants of `Token::Interpolated` still exist in the form of the new
    `token::IdentMv` and `token::LifetimeMv` tokens. I did them like that
    because there's a lot of code that assumes an interpolated
    ident/lifetime fits in a single token, and changing all that code to
    work with invisible delimiters would have been a pain. (Maybe it could
    be done in a follow-up.)
    
    Fully kills off the "captured metavariables except for `:tt`, `:ident`
    and `:lifetime` cannot be compared to other tokens" restriction.
    nnethercote committed Aug 22, 2023
    Configuration menu
    Copy the full SHA
    2c24f50 View commit details
    Browse the repository at this point in the history
  17. Configuration menu
    Copy the full SHA
    8fc2809 View commit details
    Browse the repository at this point in the history
  18. Configuration menu
    Copy the full SHA
    848d2d2 View commit details
    Browse the repository at this point in the history