Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b43aa96
Print failure message on all tests that should panic, but don't
johanngan Jan 10, 2021
679f6f3
Add `unwrap_unchecked()` methods for `Option` and `Result`
ojeda Jan 10, 2021
76299b3
Add `SAFETY` annotations
ojeda Jan 10, 2021
f97c7a5
rustc: Stabilize `-Zrun-dsymutil` as `-Csplit-debuginfo`
alexcrichton Nov 30, 2020
63a1eee
Reset LateContext enclosing body in nested items
camsteffen Jan 18, 2021
21fb586
Query for TypeckResults in LateContext::qpath_res
camsteffen Jan 18, 2021
def0e9b
Fix ICE with `ReadPointerAsBytes` validation error
camelid Jan 11, 2021
a7b7a43
Move test to `src/test/ui/consts/`
camelid Jan 11, 2021
eaba3da
Remove qpath_res util function
camsteffen Jan 18, 2021
e25959b
Make more traits of the From/Into family diagnostic items
flip1995 Jan 22, 2021
3a4786d
Use UFCS instead of method calls in `derive(Debug)`. See issue 81211 …
pnkfelix Jan 23, 2021
78e57d3
Regression tests for issue 81211.
pnkfelix Jan 23, 2021
d78f0a1
Test exploring the interactions between all of the different kinds of…
pnkfelix Jan 23, 2021
aa8fdad
placate tidy.
pnkfelix Jan 23, 2021
6d4e03a
codegen: assume constants cannot fail to evaluate
RalfJung Jan 24, 2021
2be1993
Ignore test on 32-bit architectures
camelid Jan 25, 2021
26b4baf
Point to span of upvar making closure FnMut
sledgehammervampire Jan 18, 2021
088c89d
Account for generics when suggesting bound
estebank Jan 19, 2021
042facb
Fix some bugs reported by eslint
GuillaumeGomez Jan 23, 2021
0140dac
Link the reference about undefined behavior
ojeda Jan 25, 2021
01250fc
Add tracking issue
ojeda Jan 25, 2021
24149d7
Blessed change to output of flaky test.
pnkfelix Jan 25, 2021
02291a1
Rollup merge of #79570 - alexcrichton:split-debuginfo, r=bjorn3
jonas-schievink Jan 25, 2021
16983d9
Rollup merge of #80868 - johanngan:should-panic-msg-with-expected, r=…
jonas-schievink Jan 25, 2021
fb253d8
Rollup merge of #80876 - ojeda:option-result-unwrap_unchecked, r=m-ou-se
jonas-schievink Jan 25, 2021
590e7a1
Rollup merge of #80900 - camelid:readpointerasbytes-ice, r=oli-obk
jonas-schievink Jan 25, 2021
018ac7c
Rollup merge of #81158 - 1000teslas:issue-80313-fix, r=Aaron1011
jonas-schievink Jan 25, 2021
8e8891f
Rollup merge of #81176 - camsteffen:qpath-res, r=oli-obk
jonas-schievink Jan 25, 2021
daaebcc
Rollup merge of #81195 - estebank:suggest-bound-on-trait-with-params,…
jonas-schievink Jan 25, 2021
b3f474b
Rollup merge of #81277 - flip1995:from_diag_items, r=matthewjasper
jonas-schievink Jan 25, 2021
dd8d7a1
Rollup merge of #81294 - pnkfelix:issue-81211-use-ufcs-in-derive-debu…
jonas-schievink Jan 25, 2021
2600baf
Rollup merge of #81299 - GuillaumeGomez:fix-eslint-detected-bugs, r=N…
jonas-schievink Jan 25, 2021
0de16e1
Rollup merge of #81327 - RalfJung:codegen-no-const-fail, r=oli-obk
jonas-schievink Jan 25, 2021
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
Prev Previous commit
Next Next commit
Use UFCS instead of method calls in derive(Debug). See issue 81211 …
…for discussion.
  • Loading branch information
pnkfelix committed Jan 23, 2021
commit 3a4786d5a6119a0bc62560993d64dfd1e9bce4ec
40 changes: 25 additions & 15 deletions compiler/rustc_builtin_macros/src/deriving/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ use rustc_expand::base::{Annotatable, ExtCtxt};
use rustc_span::symbol::{sym, Ident};
use rustc_span::{Span, DUMMY_SP};

fn make_mut_borrow(cx: &mut ExtCtxt<'_>, sp: Span, expr: P<Expr>) -> P<Expr> {
cx.expr(sp, ast::ExprKind::AddrOf(ast::BorrowKind::Ref, ast::Mutability::Mut, expr))
}

pub fn expand_deriving_debug(
cx: &mut ExtCtxt<'_>,
span: Span,
Expand Down Expand Up @@ -67,34 +71,37 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
let fmt = substr.nonself_args[0].clone();

let mut stmts = Vec::with_capacity(fields.len() + 2);
let fn_path_finish;
match vdata {
ast::VariantData::Tuple(..) | ast::VariantData::Unit(..) => {
// tuple struct/"normal" variant
let expr =
cx.expr_method_call(span, fmt, Ident::new(sym::debug_tuple, span), vec![name]);
let fn_path_debug_tuple = cx.std_path(&[sym::fmt, sym::Formatter, sym::debug_tuple]);
let expr = cx.expr_call_global(span, fn_path_debug_tuple, vec![fmt, name]);
stmts.push(cx.stmt_let(span, true, builder, expr));

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);

let expr = cx.expr_method_call(
span,
builder_expr.clone(),
Ident::new(sym::field, span),
vec![field],
);
let fn_path_field = cx.std_path(&[sym::fmt, sym::DebugTuple, sym::field]);
let builder_recv = make_mut_borrow(cx, span, builder_expr.clone());
let expr = cx.expr_call_global(span, fn_path_field, vec![builder_recv, field]);

// Use `let _ = expr;` to avoid triggering the
// unused_results lint.
stmts.push(stmt_let_underscore(cx, span, expr));
}

fn_path_finish = cx.std_path(&[sym::fmt, sym::DebugTuple, sym::finish]);
}
ast::VariantData::Struct(..) => {
// normal struct/struct variant
let expr =
cx.expr_method_call(span, fmt, Ident::new(sym::debug_struct, span), vec![name]);
let fn_path_debug_struct =
cx.std_path(&[sym::fmt, sym::Formatter, sym::debug_struct]);
let expr = cx.expr_call_global(
span, fn_path_debug_struct, vec![fmt, name]
);
stmts.push(cx.stmt_let(DUMMY_SP, true, builder, expr));

for field in fields {
Expand All @@ -104,20 +111,23 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
);

// Use double indirection to make sure this works for unsized types
let fn_path_field = cx.std_path(&[sym::fmt, sym::DebugStruct, sym::field]);
let field = cx.expr_addr_of(field.span, field.self_.clone());
let field = cx.expr_addr_of(field.span, field);
let expr = cx.expr_method_call(
let builder_recv = make_mut_borrow(cx, span, builder_expr.clone());
let expr = cx.expr_call_global(
span,
builder_expr.clone(),
Ident::new(sym::field, span),
vec![name, field],
fn_path_field,
vec![builder_recv, name, field],
);
stmts.push(stmt_let_underscore(cx, span, expr));
}
fn_path_finish = cx.std_path(&[sym::fmt, sym::DebugStruct, sym::finish]);
}
}

let expr = cx.expr_method_call(span, builder_expr, Ident::new(sym::finish, span), vec![]);
let builder_recv = make_mut_borrow(cx, span, builder_expr);
let expr = cx.expr_call_global(span, fn_path_finish, vec![builder_recv]);

stmts.push(cx.stmt_expr(expr));
let block = cx.block(span, stmts);
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ symbols! {
Copy,
Count,
Debug,
DebugStruct,
DebugTuple,
Decodable,
Decoder,
Default,
Expand Down