Skip to content

Commit

Permalink
Rollup merge of rust-lang#57847 - clarcharr:dbg_no_params, r=Centril
Browse files Browse the repository at this point in the history
dbg!() without parameters

Fixes rust-lang#57845.
  • Loading branch information
Centril authored Mar 19, 2019
2 parents 8ddcc75 + ea9e2c4 commit 1dce36e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/libstd/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,16 @@ macro_rules! eprintln {
/// let _ = dbg!(a); // <-- `a` is moved again; error!
/// ```
///
/// You can also use `dbg!()` without a value to just print the
/// file and line whenever it's reached.
///
/// [stderr]: https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)
#[macro_export]
#[stable(feature = "dbg_macro", since = "1.32.0")]
macro_rules! dbg {
() => {
eprintln!("[{}:{}]", file!(), line!());
};
($val:expr) => {
// Use of `match` here is intentional because it affects the lifetimes
// of temporaries - https://stackoverflow.com/a/48732525/1063961
Expand Down
13 changes: 9 additions & 4 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 @@ -33,6 +33,9 @@ fn test() {
// We can move `b` because it's Copy.
drop(b);

// Without parameters works as expected.
let _: () = dbg!();

// Test that we can borrow and that successive applications is still identity.
let a = NoCopy(1337);
let b: &NoCopy = dbg!(dbg!(&a));
Expand Down Expand Up @@ -69,17 +72,19 @@ fn validate_stderr(stderr: Vec<String>) {
" y: 24",
"}",

":38] &a = NoCopy(",
":37]",

":41] &a = NoCopy(",
" 1337",
")",

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

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

Expand Down

0 comments on commit 1dce36e

Please sign in to comment.