Skip to content
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

Merged
merged 10 commits into from
Sep 25, 2018
Merged

Implement the dbg!(..) macro #54317

merged 10 commits into from
Sep 25, 2018

Conversation

Centril
Copy link
Contributor

@Centril Centril commented Sep 18, 2018

Implements the dbg!(..) macro due to #54306.
cc rust-lang/rfcs#2361

r? @alexcrichton

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 18, 2018
@SimonSapin
Copy link
Contributor

Looks good, thanks!

@bors r+

@bors
Copy link
Contributor

bors commented Sep 18, 2018

📌 Commit 0fa114d207b7e8bea3e5eef2dc8d8918763426ca has been approved by SimonSapin

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 18, 2018
macro_rules! dbg {
($val:expr) => {
// Use of `match` here is intentional because it affects the lifetimes
// of temporaries - https://stackoverflow.com/a/48732525/1063961
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Member

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	

@kennytm
Copy link
Member

kennytm commented Sep 20, 2018

@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?

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Sep 20, 2018
@kennytm
Copy link
Member

kennytm commented Sep 21, 2018

@bors r=SimonSapin

@bors
Copy link
Contributor

bors commented Sep 21, 2018

📌 Commit 924a693 has been approved by SimonSapin

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 21, 2018
kennytm added a commit to kennytm/rust that referenced this pull request Sep 21, 2018
…apin

Implement the dbg!(..) macro

Implements the `dbg!(..)` macro due to rust-lang#54306.
cc rust-lang/rfcs#2361

r? @alexcrichton
bors added a commit that referenced this pull request Sep 21, 2018
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)
@pietroalbini
Copy link
Member

Tests failed on wasm.
@bors r-

[00:59:02] ---- [ui] ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.rs stdout ----
[00:59:02] error: test run failed!
[00:59:02] status: exit code: 101
[00:59:02] status: exit code: 101
[00:59:02] command: "/node-v9.2.0-linux-x64/bin/node" "/checkout/src/etc/wasm32-shim.js" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior/a.wasm"
[00:59:02] ------------------------------------------
[00:59:02] 
[00:59:02] ------------------------------------------
[00:59:02] stderr:
[00:59:02] stderr:
[00:59:02] ------------------------------------------
[00:59:02] RuntimeError: unreachable
[00:59:02]     at __rust_start_panic (wasm-function[148]:1)
[00:59:02]     at rust_panic.llvm.7229658430215002035 (wasm-function[142]:38)
[00:59:02]     at std::panicking::rust_panic_with_hook::h226a58a5977f2e17 (wasm-function[137]:500)
[00:59:02]     at std::panicking::continue_panic_fmt::h5f0126bd5d9da93f (wasm-function[136]:155)
[00:59:02]     at rust_begin_unwind (wasm-function[135]:3)
[00:59:02]     at core::panicking::panic_fmt::hebc42c0af7746402 (wasm-function[245]:80)
[00:59:02]     at core::result::unwrap_failed::hb8e1b756b0aad0f7 (wasm-function[19]:149)
[00:59:02]     at _$LT$core..result..Result$LT$T$C$$u20$E$GT$$GT$::unwrap::h047f9d6689dc96bf (wasm-function[1]:43)
[00:59:02]     at dbg_macro_expected_behavior::main::h80c10857552d47ce (wasm-function[6]:2332)
[00:59:02]     at std::rt::lang_start::_$u7b$$u7b$closure$u7d$$u7d$::hffb7cd8ec38eb3e9 (wasm-function[9]:25)
[00:59:02]     at std::sys_common::backtrace::__rust_begin_short_backtrace::h178ce1cdbcfd3352 (wasm-function[68]:8)
[00:59:02]     at std::panicking::try::do_call::h92ed3f8ab1f1fe4c (.llvm.7229658430215002035) (wasm-function[134]:20)
[00:59:02]     at __rust_maybe_catch_panic (wasm-function[147]:5)
[00:59:02]     at std::rt::lang_start_internal::had2eaac6c6c88dfd (wasm-function[69]:150)
[00:59:02]     at std::rt::lang_start::hecee5b62d0f0e846 (wasm-function[8]:42)
[00:59:02]     at main (wasm-function[7]:11)
[00:59:02]     at Object.<anonymous> (/checkout/src/etc/wasm32-shim.js:136:20)
[00:59:02]     at Module._compile (module.js:641:30)
[00:59:02]     at Object.Module._extensions..js (module.js:652:10)
[00:59:02]     at Module.load (module.js:560:32)
[00:59:02] ------------------------------------------
[00:59:02] 
[00:59:02] 
[00:59:02] thread '[ui] ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.rs' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:3205:9

@SimonSapin
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Sep 22, 2018

📌 Commit b4d6d78 has been approved by SimonSapin

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 22, 2018
@bors
Copy link
Contributor

bors commented Sep 23, 2018

⌛ Testing commit b4d6d78 with merge bafca5b907c03dd861329a23bfea60a5a00acf04...

@bors
Copy link
Contributor

bors commented Sep 23, 2018

💔 Test failed - status-travis

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Sep 23, 2018
@rust-highfive

This comment has been minimized.

@Centril
Copy link
Contributor Author

Centril commented Sep 23, 2018

Same error...
I'm confused as to why the test is still running on wasm...

@Centril
Copy link
Contributor Author

Centril commented Sep 23, 2018

I added per @eddyb's notes:

// ignore-wasm32
// ignore-cloudabi no processes
// ignore-emscripten no processes

Let's hope that makes it work :)

@Centril
Copy link
Contributor Author

Centril commented Sep 23, 2018

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.

@rust-highfive

This comment has been minimized.

@kennytm kennytm added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 23, 2018
@varkor
Copy link
Member

varkor commented Sep 25, 2018

@bors r=SimonSapin

@bors
Copy link
Contributor

bors commented Sep 25, 2018

📌 Commit e5b9331 has been approved by SimonSapin

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 25, 2018
@bors
Copy link
Contributor

bors commented Sep 25, 2018

⌛ Testing commit e5b9331 with merge e7416d5...

bors added a commit that referenced this pull request Sep 25, 2018
Implement the dbg!(..) macro

Implements the `dbg!(..)` macro due to #54306.
cc rust-lang/rfcs#2361

r? @alexcrichton
@bors
Copy link
Contributor

bors commented Sep 25, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: SimonSapin
Pushing e7416d5 to master...

@bors bors merged commit e5b9331 into rust-lang:master Sep 25, 2018
@Centril Centril deleted the feature/dbg_macro branch October 3, 2018 22:20
@RoelKluin
Copy link

RoelKluin commented Jan 20, 2019

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:

#[macro_export]
macro_rules! dbg {
    ($expr:expr) => (dbg!("{:#?}", $expr));
    ($fmt:expr, $expr:expr$(, $opt:expr)*) => {
        match $expr {
            expr => {
                eprintln!(concat!("[{}:{}] {} = ", $fmt), file!(), line!(), stringify!($expr), &expr$(, $opt)*);
                expr
            }
        }
    }
}

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.

example:

let t = dbg!(2 + 1);

// instead of:
let _: u64 = dbg!((1 << 63) | (t << 8));

// this gives a nicer representation:
let _: u64 = dbg!("0x{:x}", (1 << 63) | (t << 8));
    
// also possible:
let _: u64 = dbg!("0x{:x}, with t={}", (1 << 63) | (t << 8), t);

@RoelKluin RoelKluin mentioned this pull request Jan 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants