stabilize std::dbg!(...)
This commit is contained in:
parent
d09466ceb1
commit
f4cde5bc4e
9 changed files with 14 additions and 44 deletions
|
@ -224,11 +224,9 @@ macro_rules! eprintln {
|
||||||
/// the value of a given expression. An example:
|
/// the value of a given expression. An example:
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// #![feature(dbg_macro)]
|
|
||||||
///
|
|
||||||
/// let a = 2;
|
/// let a = 2;
|
||||||
/// let b = dbg!(a * 2) + 1;
|
/// 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);
|
/// assert_eq!(b, 5);
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
|
@ -262,8 +260,6 @@ macro_rules! eprintln {
|
||||||
/// With a method call:
|
/// With a method call:
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// #![feature(dbg_macro)]
|
|
||||||
///
|
|
||||||
/// fn foo(n: usize) {
|
/// fn foo(n: usize) {
|
||||||
/// if let Some(_) = dbg!(n.checked_sub(4)) {
|
/// if let Some(_) = dbg!(n.checked_sub(4)) {
|
||||||
/// // ...
|
/// // ...
|
||||||
|
@ -282,8 +278,6 @@ macro_rules! eprintln {
|
||||||
/// Naive factorial implementation:
|
/// Naive factorial implementation:
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// #![feature(dbg_macro)]
|
|
||||||
///
|
|
||||||
/// fn factorial(n: u32) -> u32 {
|
/// fn factorial(n: u32) -> u32 {
|
||||||
/// if dbg!(n <= 1) {
|
/// if dbg!(n <= 1) {
|
||||||
/// dbg!(1)
|
/// dbg!(1)
|
||||||
|
@ -312,8 +306,6 @@ macro_rules! eprintln {
|
||||||
/// The `dbg!(..)` macro moves the input:
|
/// The `dbg!(..)` macro moves the input:
|
||||||
///
|
///
|
||||||
/// ```compile_fail
|
/// ```compile_fail
|
||||||
/// #![feature(dbg_macro)]
|
|
||||||
///
|
|
||||||
/// /// A wrapper around `usize` which importantly is not Copyable.
|
/// /// A wrapper around `usize` which importantly is not Copyable.
|
||||||
/// #[derive(Debug)]
|
/// #[derive(Debug)]
|
||||||
/// struct NoCopy(usize);
|
/// struct NoCopy(usize);
|
||||||
|
@ -325,7 +317,7 @@ macro_rules! eprintln {
|
||||||
///
|
///
|
||||||
/// [stderr]: https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)
|
/// [stderr]: https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
#[unstable(feature = "dbg_macro", issue = "54306")]
|
#[stable(feature = "dbg_macro", since = "1.32.0")]
|
||||||
macro_rules! dbg {
|
macro_rules! dbg {
|
||||||
($val:expr) => {
|
($val:expr) => {
|
||||||
// Use of `match` here is intentional because it affects the lifetimes
|
// Use of `match` here is intentional because it affects the lifetimes
|
||||||
|
|
|
@ -5,8 +5,6 @@
|
||||||
// Tests ensuring that `dbg!(expr)` has the expected run-time behavior.
|
// Tests ensuring that `dbg!(expr)` has the expected run-time behavior.
|
||||||
// as well as some compile time properties we expect.
|
// as well as some compile time properties we expect.
|
||||||
|
|
||||||
#![feature(dbg_macro)]
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
struct Unit;
|
struct Unit;
|
||||||
|
|
||||||
|
@ -57,31 +55,31 @@ fn test() {
|
||||||
|
|
||||||
fn validate_stderr(stderr: Vec<String>) {
|
fn validate_stderr(stderr: Vec<String>) {
|
||||||
assert_eq!(stderr, &[
|
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,",
|
" x: 42,",
|
||||||
" y: 24",
|
" y: 24",
|
||||||
"}",
|
"}",
|
||||||
|
|
||||||
":31] b = Point {",
|
":29] b = Point {",
|
||||||
" x: 42,",
|
" x: 42,",
|
||||||
" y: 24",
|
" y: 24",
|
||||||
"}",
|
"}",
|
||||||
|
|
||||||
":40] &a = NoCopy(",
|
":38] &a = NoCopy(",
|
||||||
" 1337",
|
" 1337",
|
||||||
")",
|
")",
|
||||||
|
|
||||||
":40] dbg!(& a) = NoCopy(",
|
":38] dbg!(& a) = NoCopy(",
|
||||||
" 1337",
|
" 1337",
|
||||||
")",
|
")",
|
||||||
":45] f(&42) = 42",
|
":43] f(&42) = 42",
|
||||||
|
|
||||||
"before",
|
"before",
|
||||||
":50] { foo += 1; eprintln!(\"before\"); 7331 } = 7331",
|
":48] { foo += 1; eprintln!(\"before\"); 7331 } = 7331",
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
// Feature gate test for `dbg!(..)`.
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
dbg!(1);
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
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`.
|
|
|
@ -1,5 +1,5 @@
|
||||||
error[E0382]: use of moved value: `a`
|
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);
|
LL | let _ = dbg!(a);
|
||||||
| ------- value moved here
|
| ------- value moved here
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
// Test ensuring that `dbg!(expr)` will take ownership of the argument.
|
// Test ensuring that `dbg!(expr)` will take ownership of the argument.
|
||||||
|
|
||||||
#![feature(dbg_macro)]
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct NoCopy(usize);
|
struct NoCopy(usize);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
error[E0382]: use of moved value: `a`
|
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);
|
LL | let _ = dbg!(a);
|
||||||
| ------- value moved here
|
| ------- value moved here
|
||||||
|
@ -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)
|
= 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`
|
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);
|
LL | let _ = dbg!(a);
|
||||||
| ------- value moved here
|
| ------- value moved here
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
// Test ensuring that `dbg!(expr)` requires the passed type to implement `Debug`.
|
// Test ensuring that `dbg!(expr)` requires the passed type to implement `Debug`.
|
||||||
|
|
||||||
#![feature(dbg_macro)]
|
|
||||||
|
|
||||||
struct NotDebug;
|
struct NotDebug;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
error[E0277]: `NotDebug` doesn't implement `std::fmt::Debug`
|
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);
|
LL | let _: NotDebug = dbg!(NotDebug);
|
||||||
| ^^^^^^^^^^^^^^ `NotDebug` cannot be formatted using `{:?}`
|
| ^^^^^^^^^^^^^^ `NotDebug` cannot be formatted using `{:?}`
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue