-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement the dbg!(..) macro #54317
Implement the dbg!(..) macro #54317
Conversation
Looks good, thanks! @bors r+ |
📌 Commit 0fa114d207b7e8bea3e5eef2dc8d8918763426ca has been approved by |
macro_rules! dbg { | ||
($val:expr) => { | ||
// Use of `match` here is intentional because it affects the lifetimes | ||
// of temporaries - https://stackoverflow.com/a/48732525/1063961 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is a Stack Overflow the best kind of link for this documentation? may be worth "archiving" as a blog post somewhere on the forge for example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can always update this to something better later -- I'd welcome a follow up PR if you have ideas :)
I think it is sufficient for now.
= note: move occurs because `a` has type `NoCopy`, which does not implement the `Copy` trait | ||
= 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: aborting due to 3 previous errors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[01:03:52] ---- [ui (nll)] ui/rfc-2361-dbg-macro/dbg-macro-move-semantics.rs stdout ----
[01:03:52] diff of stderr:
[01:03:52]
[01:03:52] 9 = note: move occurs because `a` has type `NoCopy`, which does not implement the `Copy` trait
[01:03:52] 10 = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
[01:03:52] 11
[01:03:52] - error[E0382]: borrow of moved value: `a`
[01:03:52] - --> $DIR/dbg-macro-move-semantics.rs:11:18
[01:03:52] - |
[01:03:52] - LL | let _ = dbg!(a);
[01:03:52] - | ------- value moved here
[01:03:52] - LL | let _ = dbg!(a);
[01:03:52] - | ^ value borrowed here after move
[01:03:52] - |
[01:03:52] - = note: move occurs because `a` has type `NoCopy`, which does not implement the `Copy` trait
[01:03:52] - = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
[01:03:52] -
[01:03:52] - error[E0382]: use of moved value: `a`
[01:03:52] - --> $DIR/dbg-macro-move-semantics.rs:11:13
[01:03:52] - |
[01:03:52] - LL | let _ = dbg!(a);
[01:03:52] - | ------- value moved here
[01:03:52] - LL | let _ = dbg!(a);
[01:03:52] - | ^^^^^^^ value used here after move
[01:03:52] - |
[01:03:52] - = note: move occurs because `a` has type `NoCopy`, which does not implement the `Copy` trait
[01:03:52] - = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
[01:03:52] -
[01:03:52] - error: aborting due to 3 previous errors
[01:03:52] + error: aborting due to previous error
[01:03:52] 35
[01:03:52] 36 For more information about this error, try `rustc --explain E0382`.
[01:03:52] 37
@bors r- NLL changes probably changed diagnostics, causing failure in #54389 (comment). Could you rebase on latest master and verify if the CI still passes? |
0fa114d
to
924a693
Compare
@bors r=SimonSapin |
📌 Commit 924a693 has been approved by |
…apin Implement the dbg!(..) macro Implements the `dbg!(..)` macro due to rust-lang#54306. cc rust-lang/rfcs#2361 r? @alexcrichton
Rollup of 10 pull requests Successful merges: - #53652 (define copy_within on slices) - #54261 (Make `dyn` a keyword in the 2018 edition) - #54317 (Implement the dbg!(..) macro) - #54323 (rustbuild: drop color handling) - #54371 (add -Zui-testing to rustdoc) - #54374 (Make 'proc_macro::MultiSpan' public.) - #54402 (Use no_default_libraries for all NetBSD flavors) - #54412 (add applicability to span_suggestion call) - #54413 (Add UI test for deref recursion limit printing twice) - #54422 (Simplify slice's first(_mut) and last(_mut) with get)
Tests failed on wasm.
|
@bors r+ |
📌 Commit b4d6d78 has been approved by |
⌛ Testing commit b4d6d78 with merge bafca5b907c03dd861329a23bfea60a5a00acf04... |
💔 Test failed - status-travis |
This comment has been minimized.
This comment has been minimized.
Same error... |
I added per @eddyb's notes: // ignore-wasm32
// ignore-cloudabi no processes
// ignore-emscripten no processes Let's hope that makes it work :) |
I changed it to: // run-pass
// ignore-cloudabi no processes
// ignore-emscripten no processes since that's what the other tests do and that's more aligned with eddyb's and varkor's thoughts. |
This comment has been minimized.
This comment has been minimized.
@bors r=SimonSapin |
📌 Commit e5b9331 has been approved by |
Implement the dbg!(..) macro Implements the `dbg!(..)` macro due to #54306. cc rust-lang/rfcs#2361 r? @alexcrichton
☀️ Test successful - status-appveyor, status-travis |
The dbg macro lacks a possibility to format the output. For instance, it is not possible to print an u64 as hexadecimal. Therefore, I was thinking about below macro that, when given more than one expression, does allow formatting:
With a single argument this behaves like current dbg, In case there are 2 or more, the first argument is a string literal format string, the second is the evaluated, optional remaining arguments can be provided as specified in the format string.
|
Implements the
dbg!(..)
macro due to #54306.cc rust-lang/rfcs#2361
r? @alexcrichton