Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/deriving/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub(crate) fn expand_deriving_debug(
safety: Safety::Default,
document: true,
};
trait_def.expand(cx, item, push)
trait_def.expand_ext_inner(cx, item, push, false, true)
}

fn formatter_ident(cx: &ExtCtxt<'_>, span: Span) -> Box<ast::Expr> {
Expand Down
13 changes: 13 additions & 0 deletions compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,11 +460,22 @@ impl<'a> TraitDef<'a> {
}

pub(crate) fn expand_ext(
self,
cx: &ExtCtxt<'_>,
item: &'a ast::Item,
push: &mut dyn FnMut(Box<ast::Item>),
from_scratch: bool
) {
self.expand_ext_inner(cx, item, push, from_scratch, false);
}

pub(crate) fn expand_ext_inner(
self,
cx: &ExtCtxt<'_>,
item: &'a ast::Item,
push: &mut dyn FnMut(Box<ast::Item>),
from_scratch: bool,
empty: bool
) {
let span = self.span;
let is_packed = matches!(
Expand Down Expand Up @@ -509,6 +520,8 @@ impl<'a> TraitDef<'a> {
let methods = self.methods.iter().filter_map(|method_def| {
let body = if from_scratch || method_def.is_static() {
method_def.call_substructure_method(cx, span, StaticEnum(enum_def), *ident)
} else if empty && enum_def.variants.len() > 0 {
method_def.call_substructure_method(cx, span, EnumDiscr(None), *ident)
} else {
method_def.expand_enum_method_body(cx, span, enum_def, *ident)
};
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2539,7 +2539,7 @@ options! {
flatten_format_args: bool = (true, parse_bool, [TRACKED],
"flatten nested format_args!() and literals into a simplified format_args!() call \
(default: yes)"),
fmt_debug: FmtDebug = (FmtDebug::Full, parse_fmt_debug, [TRACKED],
fmt_debug: FmtDebug = (FmtDebug::None, parse_fmt_debug, [TRACKED],
"how detailed `#[derive(Debug)]` should be. `full` prints types recursively, \
`shallow` prints only type names, `none` prints nothing and disables `{:?}`. (default: `full`)"),
force_intrinsic_fallback: bool = (false, parse_bool, [TRACKED],
Expand Down
78 changes: 15 additions & 63 deletions tests/ui/derives/deriving-all-codegen.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl ::core::marker::Copy for Empty { }
impl ::core::fmt::Debug for Empty {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f, "Empty")
::core::result::Result::Ok(())
}
}
#[automatically_derived]
Expand Down Expand Up @@ -101,8 +101,7 @@ impl ::core::marker::Copy for Point { }
impl ::core::fmt::Debug for Point {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "Point", "x",
&self.x, "y", &&self.y)
::core::result::Result::Ok(())
}
}
#[automatically_derived]
Expand Down Expand Up @@ -185,8 +184,7 @@ impl ::core::marker::Copy for PackedPoint { }
impl ::core::fmt::Debug for PackedPoint {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "PackedPoint",
"x", &{ self.x }, "y", &&{ self.y })
::core::result::Result::Ok(())
}
}
#[automatically_derived]
Expand Down Expand Up @@ -263,8 +261,7 @@ impl ::core::marker::Copy for TupleSingleField { }
impl ::core::fmt::Debug for TupleSingleField {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"TupleSingleField", &&self.0)
::core::result::Result::Ok(())
}
}
#[automatically_derived]
Expand Down Expand Up @@ -338,8 +335,7 @@ impl ::core::marker::Copy for SingleField { }
impl ::core::fmt::Debug for SingleField {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field1_finish(f, "SingleField",
"foo", &&self.foo)
::core::result::Result::Ok(())
}
}
#[automatically_derived]
Expand Down Expand Up @@ -422,13 +418,7 @@ impl ::core::marker::Copy for Big { }
impl ::core::fmt::Debug for Big {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
let names: &'static _ =
&["b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8"];
let values: &[&dyn ::core::fmt::Debug] =
&[&self.b1, &self.b2, &self.b3, &self.b4, &self.b5, &self.b6,
&self.b7, &&self.b8];
::core::fmt::Formatter::debug_struct_fields_finish(f, "Big", names,
values)
::core::result::Result::Ok(())
}
}
#[automatically_derived]
Expand Down Expand Up @@ -672,8 +662,7 @@ struct Unsized([u32]);
impl ::core::fmt::Debug for Unsized {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Unsized",
&&self.0)
::core::result::Result::Ok(())
}
}
#[automatically_derived]
Expand Down Expand Up @@ -751,8 +740,7 @@ impl<T: ::core::fmt::Debug + Trait, U: ::core::fmt::Debug> ::core::fmt::Debug
for Generic<T, U> where T::A: ::core::fmt::Debug {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field3_finish(f, "Generic", "t",
&self.t, "ta", &self.ta, "u", &&self.u)
::core::result::Result::Ok(())
}
}
#[automatically_derived]
Expand Down Expand Up @@ -871,8 +859,7 @@ impl<T: ::core::fmt::Debug + ::core::marker::Copy + Trait,
{
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field3_finish(f, "PackedGeneric",
&{ self.0 }, &{ self.1 }, &&{ self.2 })
::core::result::Result::Ok(())
}
}
#[automatically_derived]
Expand Down Expand Up @@ -1037,11 +1024,7 @@ impl ::core::clone::Clone for Enum1 {
impl ::core::fmt::Debug for Enum1 {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Single { x: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Single", "x", &__self_0),
}
::core::result::Result::Ok(())
}
}
#[automatically_derived]
Expand Down Expand Up @@ -1109,7 +1092,7 @@ impl ::core::clone::Clone for Fieldless1 {
impl ::core::fmt::Debug for Fieldless1 {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f, "A")
::core::result::Result::Ok(())
}
}
#[automatically_derived]
Expand Down Expand Up @@ -1169,12 +1152,7 @@ impl ::core::marker::Copy for Fieldless { }
impl ::core::fmt::Debug for Fieldless {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
Fieldless::A => "A",
Fieldless::B => "B",
Fieldless::C => "C",
})
::core::result::Result::Ok(())
}
}
#[automatically_derived]
Expand Down Expand Up @@ -1250,16 +1228,7 @@ impl ::core::marker::Copy for Mixed { }
impl ::core::fmt::Debug for Mixed {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::P => ::core::fmt::Formatter::write_str(f, "P"),
Self::Q => ::core::fmt::Formatter::write_str(f, "Q"),
Self::R(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "R",
&__self_0),
Self::S { d1: __self_0, d2: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f, "S",
"d1", __self_0, "d2", &__self_1),
}
::core::result::Result::Ok(())
}
}
#[automatically_derived]
Expand Down Expand Up @@ -1430,17 +1399,7 @@ impl ::core::clone::Clone for Fielded {
impl ::core::fmt::Debug for Fielded {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::X(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "X",
&__self_0),
Self::Y(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Y",
&__self_0),
Self::Z(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Z",
&__self_0),
}
::core::result::Result::Ok(())
}
}
#[automatically_derived]
Expand Down Expand Up @@ -1536,14 +1495,7 @@ impl<T: ::core::fmt::Debug, U: ::core::fmt::Debug> ::core::fmt::Debug for
EnumGeneric<T, U> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::One(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "One",
&__self_0),
Self::Two(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Two",
&__self_0),
}
::core::result::Result::Ok(())
}
}
#[automatically_derived]
Expand Down
Loading