Skip to content

Commit 5b8312d

Browse files
committed
Interpolate AST nodes in quasiquote.
This changes the `ToTokens` implementations for expressions, statements, etc. with almost-trivial ones that produce `Interpolated(*Nt(...))` pseudo-tokens. In this way, quasiquote now works the same way as macros do: already-parsed AST fragments are used as-is, not reparsed. The `ToSource` trait is removed. Quasiquote no longer involves pretty-printing at all, which removes the need for the `encode_with_hygiene` hack. All associated machinery is removed. Two new `Nonterminal`s are added: NtArm and NtMethod, which the parser now interpolates. These are just for quasiquote. They aren't used by macros (although they could be in the future). `ToTokens` is no longer implemented for `Arg` (although this could be added again) and `Generics` (which I don't think makes sense). This breaks any compiler extensions that relied on the ability of `ToTokens` to turn AST fragments back into inspectable token trees. For this reason, this closes rust-lang#16987. As such, this is a [breaking-change]. Fixes rust-lang#16472. Fixes rust-lang#15962. Fixes rust-lang#17397. Fixes rust-lang#16617.
1 parent 79dd393 commit 5b8312d

File tree

9 files changed

+180
-551
lines changed

9 files changed

+180
-551
lines changed

src/libsyntax/ast.rs

-6
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,6 @@ impl Ident {
9090
pub fn as_str<'a>(&'a self) -> &'a str {
9191
self.name.as_str()
9292
}
93-
94-
pub fn encode_with_hygiene(&self) -> String {
95-
format!("\x00name_{},ctxt_{}\x00",
96-
self.name.usize(),
97-
self.ctxt)
98-
}
9993
}
10094

10195
impl fmt::Debug for Ident {

0 commit comments

Comments
 (0)