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

dump!: debugging macro #12426

Closed

Conversation

seanmonstar
Copy link
Contributor

dump! is a shorter way of quickly outputing some values to debug programs.
Example:

dump!(val_a, 2 + 2); // "val_a = ~[2u8, 3u8], 2 + 2 = 4"

fixes #12015

dump! is a shorter way of quickly outputing some values to debug programs.
Example:
    dump!(val_a, 2 + 2); => "val_a = true, 2 + 2 = 4"

fixes rust-lang#12015
@lilyball
Copy link
Contributor

LGTM, but I'm going to hold off r+ until someone with more authority decides if this is desired.

One note: it is, in fact, possible to test the output. You can redirect task-local stdout to a buffer, perform your dump!(), and check the contents of the buffer.

@seanmonstar
Copy link
Contributor Author

I just copied what test_write and test_print were doing.

@lilyball
Copy link
Contributor

Those should probably be fixed as well, either as part of this PR or as a new one.

@alexcrichton
Copy link
Member

#12019 should be considered when merging this.

@seanmonstar
Copy link
Contributor Author

@kballard i added formatting tests for print! and dump!

t!(r.read_line().unwrap(), "hi~[0u8]hello\n");
t!(r.read_line().unwrap(), "this is a test\n");
t!(r.read_line().unwrap(), "bar\n");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should verify at this point that the channel is closed. You can use .recv_opt and ensure it returns None. This is effectively testing to make sure there isn't any more output after what was expected.

@seanmonstar
Copy link
Contributor Author

@alexcrichton I don't understand enough of that issue to know what to do about it.

@seanmonstar
Copy link
Contributor Author

@kballard I amended that commit with tests for EndOfFile

@lilyball
Copy link
Contributor

r=me if someone else is willing to make the call that we definitely want this.

I don't think anything concrete needs to be done about #12019 at the moment with regards to this. If reflection gets a lint, hopefully that lint will see through the macro and flag the calls to dump!().

@brson
Copy link
Contributor

brson commented Feb 21, 2014

Though I do understand the utility, I'm firmly on the fence about this. That everybody is doing debug logging with println! instead of debug! is a bad sign. Also, of course we may still end up removing "{:?}".

@lilyball
Copy link
Contributor

The problem with debug!() is you need to also figure out the right RUST_LOG invocation to actually use it. println!() is much more friendly to quick print debugging because you can run the program the same way you always do.

@huonw
Copy link
Member

huonw commented Feb 21, 2014

It's cool that it can be implemented in a library. Maybe we could have a libdebug crate with this macro exported and functions like breakpoint() (that quits to a debugger if running inside one), and...

(I can't think of anything else, so the crate might be rather empty.)

@lilyball
Copy link
Contributor

@huonw std::reflect could then be moved inside of libdebug. Then maybe {:?} would simply not be usable if you don't say extern crate debug;.

@emberian
Copy link
Member

That's not a bad idea. Having reflection in a crate named debug seems
like a perfect solution to all of the reflection woes. Doesn't really help
with visit glue though...

On Thu, Feb 20, 2014 at 9:01 PM, Kevin Ballard notifications@gh.neting.ccwrote:

@huonw https://github.com/huonw std::reflect could then be moved inside
of libdebug. Then maybe {:?} would simply not be usable if you don't say extern
crate debug;.


Reply to this email directly or view it on GitHubhttps://github.com//pull/12426#issuecomment-35692016
.

@seanmonstar
Copy link
Contributor Author

So, should I make a new PR with this + moving breakpoint/reflect into libdebug?

@alexcrichton
Copy link
Member

Closing due to a lack of activity, but a libdebug option sounds promising. This may want to get fleshed out with a full RFC before moving forward, however.

@brson
Copy link
Contributor

brson commented Mar 9, 2014

I was thinking today we might make "info" the default level to encourage its use for things like this.

@dobkeratops
Copy link

interesting, i was about to ask for something like this;
my version is very similar except i also display file!(), line!() which I find really useful (finding if & when things are called from frameworks.. finding where something crashed without a debugger.) ; i'd usually called that part 'trace' , does the standard logging have an option for that?

I was also after the equivalent of __FUNCTION__.. i'd tried func!() function!() ..

bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 25, 2022
… r=Veykril

feature: `Merge imports` assist can merge multiple selected imports.

The selected imports have to have a common prefix in paths.

Select imports or use trees to merge:
```rust
$0use std::fmt::Display;
use std::fmt::Debug;
use std::fmt::Write;$0
```
Apply `Merge imports`:
```rust
use std::fmt::{Display, Debug, Write};
```

Closes rust-lang#12426
flip1995 pushed a commit to flip1995/rust that referenced this pull request Mar 7, 2024
…-ctxt, r=Manishearth

Don't lint `redundant_field_names` across macro boundaries

Fixes rust-lang#12426

The `field.span.eq_ctxt(field.ident.span)` addition is the relevant line for the bugfix

The current implementation checks that the field's name and the path are in the same context by comparing the idents, but not that the two are in the same context as the entire field itself, so in local macros `SomeStruct { $ident: $ident }` would get linted

changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a shorter macro for println!("{:?}", foo)
7 participants