Skip to content

Commit

Permalink
Rollup merge of rust-lang#56395 - Centril:stabilize-dbg-macro, r=Simo…
Browse files Browse the repository at this point in the history
…nSapin

Stabilize dbg!(...)

Per FCP in rust-lang#54306 (which is ~1 day from completion).

r? @SimonSapin

The PR is fairly isolated so a rollup should probably work.
  • Loading branch information
Mark-Simulacrum committed Dec 1, 2018
2 parents f896e1d + f4cde5b commit 964d722
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 44 deletions.
12 changes: 2 additions & 10 deletions src/libstd/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,9 @@ macro_rules! eprintln {
/// the value of a given expression. An example:
///
/// ```rust
/// #![feature(dbg_macro)]
///
/// let a = 2;
/// let b = dbg!(a * 2) + 1;
/// // ^-- prints: [src/main.rs:4] a * 2 = 4
/// // ^-- prints: [src/main.rs:2] a * 2 = 4
/// assert_eq!(b, 5);
/// ```
///
Expand Down Expand Up @@ -262,8 +260,6 @@ macro_rules! eprintln {
/// With a method call:
///
/// ```rust
/// #![feature(dbg_macro)]
///
/// fn foo(n: usize) {
/// if let Some(_) = dbg!(n.checked_sub(4)) {
/// // ...
Expand All @@ -282,8 +278,6 @@ macro_rules! eprintln {
/// Naive factorial implementation:
///
/// ```rust
/// #![feature(dbg_macro)]
///
/// fn factorial(n: u32) -> u32 {
/// if dbg!(n <= 1) {
/// dbg!(1)
Expand Down Expand Up @@ -312,8 +306,6 @@ macro_rules! eprintln {
/// The `dbg!(..)` macro moves the input:
///
/// ```compile_fail
/// #![feature(dbg_macro)]
///
/// /// A wrapper around `usize` which importantly is not Copyable.
/// #[derive(Debug)]
/// struct NoCopy(usize);
Expand All @@ -325,7 +317,7 @@ macro_rules! eprintln {
///
/// [stderr]: https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)
#[macro_export]
#[unstable(feature = "dbg_macro", issue = "54306")]
#[stable(feature = "dbg_macro", since = "1.32.0")]
macro_rules! dbg {
($val:expr) => {
// Use of `match` here is intentional because it affects the lifetimes
Expand Down
18 changes: 8 additions & 10 deletions src/test/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// Tests ensuring that `dbg!(expr)` has the expected run-time behavior.
// as well as some compile time properties we expect.

#![feature(dbg_macro)]

#[derive(Copy, Clone, Debug)]
struct Unit;

Expand Down Expand Up @@ -57,31 +55,31 @@ fn test() {

fn validate_stderr(stderr: Vec<String>) {
assert_eq!(stderr, &[
":23] Unit = Unit",
":21] Unit = Unit",

":24] a = Unit",
":22] a = Unit",

":30] Point{x: 42, y: 24,} = Point {",
":28] Point{x: 42, y: 24,} = Point {",
" x: 42,",
" y: 24",
"}",

":31] b = Point {",
":29] b = Point {",
" x: 42,",
" y: 24",
"}",

":40] &a = NoCopy(",
":38] &a = NoCopy(",
" 1337",
")",

":40] dbg!(& a) = NoCopy(",
":38] dbg!(& a) = NoCopy(",
" 1337",
")",
":45] f(&42) = 42",
":43] f(&42) = 42",

"before",
":50] { foo += 1; eprintln!(\"before\"); 7331 } = 7331",
":48] { foo += 1; eprintln!(\"before\"); 7331 } = 7331",
]);
}

Expand Down
5 changes: 0 additions & 5 deletions src/test/ui/rfc-2361-dbg-macro/dbg-macro-feature-gate.rs

This file was deleted.

11 changes: 0 additions & 11 deletions src/test/ui/rfc-2361-dbg-macro/dbg-macro-feature-gate.stderr

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0382]: use of moved value: `a`
--> $DIR/dbg-macro-move-semantics.rs:11:18
--> $DIR/dbg-macro-move-semantics.rs:9:18
|
LL | let _ = dbg!(a);
| ------- value moved here
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/rfc-2361-dbg-macro/dbg-macro-move-semantics.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Test ensuring that `dbg!(expr)` will take ownership of the argument.

#![feature(dbg_macro)]

#[derive(Debug)]
struct NoCopy(usize);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0382]: use of moved value: `a`
--> $DIR/dbg-macro-move-semantics.rs:11:18
--> $DIR/dbg-macro-move-semantics.rs:9:18
|
LL | let _ = dbg!(a);
| ------- value moved here
Expand All @@ -10,7 +10,7 @@ LL | let _ = dbg!(a);
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error[E0382]: use of moved value: `a`
--> $DIR/dbg-macro-move-semantics.rs:11:13
--> $DIR/dbg-macro-move-semantics.rs:9:13
|
LL | let _ = dbg!(a);
| ------- value moved here
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/rfc-2361-dbg-macro/dbg-macro-requires-debug.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Test ensuring that `dbg!(expr)` requires the passed type to implement `Debug`.

#![feature(dbg_macro)]

struct NotDebug;

fn main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0277]: `NotDebug` doesn't implement `std::fmt::Debug`
--> $DIR/dbg-macro-requires-debug.rs:8:23
--> $DIR/dbg-macro-requires-debug.rs:6:23
|
LL | let _: NotDebug = dbg!(NotDebug);
| ^^^^^^^^^^^^^^ `NotDebug` cannot be formatted using `{:?}`
Expand Down

0 comments on commit 964d722

Please sign in to comment.