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

quote_expr macro: embed Ident using special encoding that retains hygiene state. #16477

Closed
wants to merge 2 commits into from

Conversation

pnkfelix
Copy link
Member

quote_expr macro: embed Ident using special encoding that retains hygiene state.

Fix #15750, #15962

…ygiene.

This adds support to `quote_expr!` and friends for round-trip hygienic
preservation of Ident.

Here are the pieces of the puzzle:

* adding a method for encoding Ident for re-reading into token tree.

* Support for reading such encoded Idents in the lexer.  Note that one
  must peek ahead for MOD_SEP after scan_embedded_hygienic_ident.

* To ensure that encoded Idents are only read when we are in the midst
  of expanding a `quote_expr` or similar, added a
  `read_embedded_ident` flag on `StringReader`.

* pprust support for encoding Ident's as (uint,uint) pairs (for hygiene).
I chose to make two of them because I wanted something close to an
"end-to-end" test (*), but at the same time I wanted a test that
would run on Windows (**).

(*) The run-make test serves as the end-to-end: It constructs an input
that is trying to subvert the hack and we are going to check that it
fails in the attempt).

(**) The compile-fail-fulldeps test serves as a more narrow test that
will be tested on all platforms.  It also attempts to subvert the
hack, testing that when you use `new_parser_from_tts`, the resulting
parser does not support reading embedded Idents.
@pnkfelix
Copy link
Member Author

r? anyone, perhaps @huonw

@brson
Copy link
Contributor

brson commented Aug 13, 2014

Awesome hack! Thanks for working this out, @pnkfelix.

bors added a commit that referenced this pull request Aug 14, 2014
quote_expr macro: embed Ident using special encoding that retains hygiene state.

Fix #15750, #15962
@bors bors closed this Aug 14, 2014
@pnkfelix
Copy link
Member Author

I realized last night that perhaps the most important test was not included in the PR above: namely, a run-pass test of a use of quote_expr! itself in a procedural macro, perhaps the form of the one posted on #15750. (The PR above just added compile-fail tests to ensure that the hack did not leak outside of quote_expr!.) I will put up a PR with a run-pass test shortly.

bors added a commit that referenced this pull request Aug 15, 2014
…hton

Followup to PR #16477: a run-pass regression test for Issue #15750.
@larsbergstrom
Copy link
Contributor

@pnkfelix Thanks much!

matthiaskrgr pushed a commit to matthiaskrgr/rust that referenced this pull request Feb 11, 2024
…agnostic, r=Veykril

feat: Add incorrect case diagnostics for traits and their associated items

Updates incorrect case diagnostic to:
- Check traits and their associated items
- Ignore trait implementations except for patterns in associated function bodies

Also cleans up `hir-ty::diagnostics::decl_check` a bit (mostly to make it a bit more DRY and easier to maintain)

Also fixes: rust-lang#8675 and fixes: rust-lang#8225
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.

Quote/splice discard syntactic context
4 participants