about summary refs log tree commit diff
path: root/src/libsyntax_ext
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2018-03-13 00:54:33 +0800
committerGitHub <noreply@github.com>2018-03-13 00:54:33 +0800
commit34d9ffec17b820a5ec7d609e1022f72314f9c3b8 (patch)
tree35251914cef13e04fcd342d1c2725bb08367ca17 /src/libsyntax_ext
parent14574db7931285af2d3316dff8e726ca8eccf862 (diff)
parentc033c6e47c1a84e2902c75a1b5ec161362f34f18 (diff)
downloadrust-34d9ffec17b820a5ec7d609e1022f72314f9c3b8.tar.gz
rust-34d9ffec17b820a5ec7d609e1022f72314f9c3b8.zip
Rollup merge of #48934 - Phlosioneer:42453-debug-hygene, r=petrochenkov
Fix hygene issue when deriving Debug

The code for several of the core traits doesn't use hygenic macros.
This isn't a problem, except for the Debug trait, which is the only
one that uses a variable, named "builder".

Variables can't share names with unit structs, so attempting to
[derive(Debug)] on any type while a unit struct with the name
"builder" was in scope would result in an error.

This commit just changes the name of the variable to
"__debug_trait_builder", because I couldn't figure out how to get a
list of all unit structs in-scope from within the derive expansion
function. If someone wants to have a unit struct with
the exact name "__debug_trait_builder", they'll just have to do it
without a [derive(Debug)].

I also checked the implementations of the other built-in derives to
ensure they didn't declare any variables.
Diffstat (limited to 'src/libsyntax_ext')
-rw-r--r--src/libsyntax_ext/deriving/debug.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/libsyntax_ext/deriving/debug.rs b/src/libsyntax_ext/deriving/debug.rs
index 82fc09fca69..7b23de582a7 100644
--- a/src/libsyntax_ext/deriving/debug.rs
+++ b/src/libsyntax_ext/deriving/debug.rs
@@ -70,7 +70,7 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<E
     // We want to make sure we have the ctxt set so that we can use unstable methods
     let span = span.with_ctxt(cx.backtrace());
     let name = cx.expr_lit(span, ast::LitKind::Str(ident.name, ast::StrStyle::Cooked));
-    let builder = Ident::from_str("builder");
+    let builder = Ident::from_str("__debug_trait_builder");
     let builder_expr = cx.expr_ident(span, builder.clone());
 
     let fmt = substr.nonself_args[0].clone();