about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-03-19 15:16:46 +0100
committerGitHub <noreply@github.com>2019-03-19 15:16:46 +0100
commitd4ef74b2daab3119e34e2dbed6bb2ab40b49cae9 (patch)
treeb82f9d1975bfffa209df981ced4e12cc02360a87 /src
parentc1975dbd34a69565cd0a66770377ed9bfc85fa35 (diff)
parentea9e2c4ef5cf2d1867b284bd4f84b5417d8df45b (diff)
downloadrust-d4ef74b2daab3119e34e2dbed6bb2ab40b49cae9.tar.gz
rust-d4ef74b2daab3119e34e2dbed6bb2ab40b49cae9.zip
Rollup merge of #57847 - clarcharr:dbg_no_params, r=Centril
dbg!() without parameters

Fixes #57845.
Diffstat (limited to 'src')
-rw-r--r--src/libstd/macros.rs6
-rw-r--r--src/test/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.rs13
2 files changed, 15 insertions, 4 deletions
diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs
index 9d0eb2e6b1c..d5dc5f7c4f0 100644
--- a/src/libstd/macros.rs
+++ b/src/libstd/macros.rs
@@ -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
diff --git a/src/test/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.rs b/src/test/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.rs
index 3d24f49ad75..67f7f80a9e2 100644
--- a/src/test/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.rs
+++ b/src/test/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.rs
@@ -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));
@@ -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",
     ]);
 }