/// 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);
/// ```
///
/// With a method call:
///
/// ```rust
-/// #![feature(dbg_macro)]
-///
/// fn foo(n: usize) {
/// if let Some(_) = dbg!(n.checked_sub(4)) {
/// // ...
/// Naive factorial implementation:
///
/// ```rust
-/// #![feature(dbg_macro)]
-///
/// fn factorial(n: u32) -> u32 {
/// if dbg!(n <= 1) {
/// dbg!(1)
/// 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);
///
/// [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
// 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;
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",
]);
}
+++ /dev/null
-// Feature gate test for `dbg!(..)`.
-
-fn main() {
- dbg!(1);
-}
+++ /dev/null
-error[E0658]: macro dbg! is unstable (see issue #54306)
- --> $DIR/dbg-macro-feature-gate.rs:4:5
- |
-LL | dbg!(1);
- | ^^^^^^^^
- |
- = help: add #![feature(dbg_macro)] to the crate attributes to enable
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0658`.
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
// Test ensuring that `dbg!(expr)` will take ownership of the argument.
-#![feature(dbg_macro)]
-
#[derive(Debug)]
struct NoCopy(usize);
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
= 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
// Test ensuring that `dbg!(expr)` requires the passed type to implement `Debug`.
-#![feature(dbg_macro)]
-
struct NotDebug;
fn main() {
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 `{:?}`