diff options
| author | Steven Fackler <sfackler@gmail.com> | 2015-05-17 14:03:37 -0700 |
|---|---|---|
| committer | Steven Fackler <sfackler@gmail.com> | 2015-05-17 14:03:37 -0700 |
| commit | 1973ee479d83f06aea2366963d5ec092d8c591dc (patch) | |
| tree | 89f3f338aaeb3bf1d7fa46d54dc29a1f077eb335 | |
| parent | 8b7c17db2235a2a3f2c71242b11fc429a8d05a90 (diff) | |
| download | rust-1973ee479d83f06aea2366963d5ec092d8c591dc.tar.gz rust-1973ee479d83f06aea2366963d5ec092d8c591dc.zip | |
Make #[derive(Debug)] work with unsized fields
Closes #25394
| -rw-r--r-- | src/libsyntax/ext/deriving/show.rs | 16 | ||||
| -rw-r--r-- | src/test/run-pass/issue-25394.rs | 14 |
2 files changed, 25 insertions, 5 deletions
diff --git a/src/libsyntax/ext/deriving/show.rs b/src/libsyntax/ext/deriving/show.rs index 518bd161c1e..9dcbd2d1f70 100644 --- a/src/libsyntax/ext/deriving/show.rs +++ b/src/libsyntax/ext/deriving/show.rs @@ -75,6 +75,7 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span, match *substr.fields { Struct(ref fields) | EnumMatching(_, _, ref fields) => { + if fields.is_empty() || fields[0].name.is_none() { // tuple struct/"normal" variant expr = cx.expr_method_call(span, @@ -83,11 +84,14 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span, vec![name]); for field in fields { + // Use double indirection to make sure this works for unsized types + let field = cx.expr_addr_of(field.span, field.self_.clone()); + let field = cx.expr_addr_of(field.span, field); + expr = cx.expr_method_call(span, expr, token::str_to_ident("field"), - vec![cx.expr_addr_of(field.span, - field.self_.clone())]); + vec![field]); } } else { // normal struct/struct variant @@ -100,12 +104,14 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span, let name = cx.expr_lit(field.span, ast::Lit_::LitStr( token::get_ident(field.name.clone().unwrap()), ast::StrStyle::CookedStr)); + + // Use double indirection to make sure this works for unsized types + let field = cx.expr_addr_of(field.span, field.self_.clone()); + let field = cx.expr_addr_of(field.span, field); expr = cx.expr_method_call(span, expr, token::str_to_ident("field"), - vec![name, - cx.expr_addr_of(field.span, - field.self_.clone())]); + vec![name, field]); } } } diff --git a/src/test/run-pass/issue-25394.rs b/src/test/run-pass/issue-25394.rs new file mode 100644 index 00000000000..c42de6fdf34 --- /dev/null +++ b/src/test/run-pass/issue-25394.rs @@ -0,0 +1,14 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[derive(Debug)] +struct Row<T>([T]); + +fn main() {} |
