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

Documentation about the dbg! macro #1658

Open
Centril opened this issue Dec 3, 2018 · 14 comments
Open

Documentation about the dbg! macro #1658

Centril opened this issue Dec 3, 2018 · 14 comments
Milestone

Comments

@Centril
Copy link

Centril commented Dec 3, 2018

The dbg! macro was just stabilized and will be in Rust 1.32 (see rust-lang/rust#54306). Since one important reason for introducing the macro in the first place was to help beginners it might make sense to use it in the book.

@steveklabnik
Copy link
Member

A lot of our printlns would be dbgs, I think. @carols10cents should we do a massive switch-over?

@ngoldbaum
Copy link

As a new rust user I really like dbg. I think it would also make the introductory sections of the book clearer because you don't need to gloss over the string formatting rules or explain what "{}" means.

@carols10cents
Copy link
Member

Sure, once we switch to 1.32 i'd be up for it. We're currently on 1.31.

@rusty-snake
Copy link

since there is code that need 1.32 or newer (#2034) I think the title page should be updated and dbg! can come.

@carols10cents
Copy link
Member

Just realized that because dbg! takes ownership, instead of having to explain {} or {:?}, we'll have to explain & in order to use this early on in the book. 🤷‍♀ Not sure that's an improvement.

@dekellum
Copy link

dekellum commented Jan 15, 2020

It can be used on copy types without that. Or save dbg! for just after borrowing is addressed?

@rusty-snake
Copy link

@carols10cents dbg! return its parameter, so you can use it when assigning a variable or you can shadowing it.

fn main() {
    let s = dbg!("abc".to_owned());
    let s = dbg!(s);
    drop(s);
}

Or even

fn main() {
    if "42" == dbg!(answer.get()) {
        println!("The answer is 42");
    }
}

Copy types always work (as @dekellum sayed)

@carols10cents
Copy link
Member

@rusty-snake yes, I read the 2 RFCs and the tracking issue before commenting here. I understand the justification behind the dbg! macro taking ownership. I don't think that affects the issue I raised here over whether it would be better to switch the book from using println! to dbg!.

@dekellum
Copy link

Isn't there intrinsic value to the reader and early learner, to see both println! and dbg! at some point in the book, say before finding it in code in the wild?

@carols10cents
Copy link
Member

@dekellum the issue is that closing this issue is not just a quick find-and-replace println! for dbg! in the book, and that the implementation of dbg! complicates the explanation.

@dekellum
Copy link

Fair enough, I still think it has intrinsic value, as early learners will soon encounter both in the wild, and print debugging is rather fundamental.

@nealmcb
Copy link

nealmcb commented Sep 8, 2020

I've been going thru the book, as a newbie, and was already thinking that printing debug info wouldn't be as fun as I'd like.

Then I just ran across dbg! which is indeed fabulous.

I thing getting at least a mention of it in the documentation is a great idea.

We don't have to switch everything to use it in a few places and then later start using it more after & has been explained.

@carols10cents carols10cents modified the milestones: ch3, ch5 Jul 17, 2021
@carols10cents carols10cents modified the milestones: ch5, all Jul 29, 2021
@carols10cents
Copy link
Member

Ok, I just added an explanation of dbg! to chapter 5 where we introduce the Debug trait, and I'm leaving this issue open to consider where we might want to use dbg! instead of println! in later parts of the book (we're going through most of the chapters mostly in order prepping for a larger revision). I'll close this when I'm all the way through the book.

JohnTitor added a commit to JohnTitor/rust that referenced this issue Aug 11, 2021
Update books

## nomicon

2 commits in f51734eb5566c826b471977747ea3d7d6915bbe9..0c7e5bd1428e7838252bb57b7f0fbfda4ec82f02
2021-07-23 18:24:35 +0900 to 2021-08-04 10:18:22 -0700
- Document lifetime elision for fn types, Fn*, impl (rust-lang/nomicon#298)
- Remove unnecessary `extern crate`s (rust-lang/nomicon#297)

## reference

3 commits in 3b7be075af5d6e402a18efff672a8a265b4596fd..4884fe45c14f8b22121760fb117181bb4da8dfe0
2021-07-26 13:20:11 -0700 to 2021-07-28 21:31:28 -0700
- Mention "function item type to `fn pointer`" coercion (rust-lang/reference#1079)
- example for bindings after at (rust-lang/reference#1027)
- array-expr.md: fix typo; 'polish' sentence (rust-lang/reference#1080)

## book

10 commits in a07036f864b37896b31eb996cd7aedb489f69a1f..7e49659102f0977d9142190e1ba23345c0f00eb1
2021-07-26 20:19:46 -0400 to 2021-08-03 21:41:35 -0400
- Make explicit that enum variant construction is a function
- Clarify why None means we have to annotate the type
- Make the convert quotes script able to do one chapter
- Snapshot of chapter 5
-  (rust-lang/book#2811)
-  (rust-lang/book#2809)
- Ugh quote script, that's not right
- Introduce the dbg macro. Connects to rust-lang/book#1658
- Add an example of declaring and instantiating unit-like structs. Fixes rust-lang/book#2442.
- Remove authors field from all the manifests (rust-lang/book#2805)

## rustc-dev-guide

5 commits in 09343d6..c4644b4
2021-07-26 00:37:28 +0200 to 2021-08-10 20:41:44 +0900
- Remove a dead link in `new-target.md` + other nits (rust-lang/rustc-dev-guide#1186)
- Add description of -opt-bisect-limit LLVM option (rust-lang/rustc-dev-guide#1182)
- Fixed team responsible for stabilization (rust-lang/rustc-dev-guide#1181)
- Add S-Inactive PRs as another source of things contributors could work on (rust-lang/rustc-dev-guide#1177)
- git.md: Fix No-Merge Policy link

## embedded-book

1 commits in 09986cd352404eb4659db44613b27cac9aa652fc..4f9fcaa30d11ba52b641e6fd5206536d65838af9
2021-07-18 19:26:46 +0000 to 2021-08-06 17:43:12 +0000
- Fix typo in 'Memory Mapped Registers'  (rust-embedded/book#298)
JohnTitor added a commit to JohnTitor/rust that referenced this issue Aug 11, 2021
Update books

## nomicon

2 commits in f51734eb5566c826b471977747ea3d7d6915bbe9..0c7e5bd1428e7838252bb57b7f0fbfda4ec82f02
2021-07-23 18:24:35 +0900 to 2021-08-04 10:18:22 -0700
- Document lifetime elision for fn types, Fn*, impl (rust-lang/nomicon#298)
- Remove unnecessary `extern crate`s (rust-lang/nomicon#297)

## reference

3 commits in 3b7be075af5d6e402a18efff672a8a265b4596fd..4884fe45c14f8b22121760fb117181bb4da8dfe0
2021-07-26 13:20:11 -0700 to 2021-07-28 21:31:28 -0700
- Mention "function item type to `fn pointer`" coercion (rust-lang/reference#1079)
- example for bindings after at (rust-lang/reference#1027)
- array-expr.md: fix typo; 'polish' sentence (rust-lang/reference#1080)

## book

10 commits in a07036f864b37896b31eb996cd7aedb489f69a1f..7e49659102f0977d9142190e1ba23345c0f00eb1
2021-07-26 20:19:46 -0400 to 2021-08-03 21:41:35 -0400
- Make explicit that enum variant construction is a function
- Clarify why None means we have to annotate the type
- Make the convert quotes script able to do one chapter
- Snapshot of chapter 5
-  (rust-lang/book#2811)
-  (rust-lang/book#2809)
- Ugh quote script, that's not right
- Introduce the dbg macro. Connects to rust-lang/book#1658
- Add an example of declaring and instantiating unit-like structs. Fixes rust-lang/book#2442.
- Remove authors field from all the manifests (rust-lang/book#2805)

## rustc-dev-guide

5 commits in 09343d6..c4644b4
2021-07-26 00:37:28 +0200 to 2021-08-10 20:41:44 +0900
- Remove a dead link in `new-target.md` + other nits (rust-lang/rustc-dev-guide#1186)
- Add description of -opt-bisect-limit LLVM option (rust-lang/rustc-dev-guide#1182)
- Fixed team responsible for stabilization (rust-lang/rustc-dev-guide#1181)
- Add S-Inactive PRs as another source of things contributors could work on (rust-lang/rustc-dev-guide#1177)
- git.md: Fix No-Merge Policy link

## embedded-book

1 commits in 09986cd352404eb4659db44613b27cac9aa652fc..4f9fcaa30d11ba52b641e6fd5206536d65838af9
2021-07-18 19:26:46 +0000 to 2021-08-06 17:43:12 +0000
- Fix typo in 'Memory Mapped Registers'  (rust-embedded/book#298)
JohnTitor added a commit to JohnTitor/rust that referenced this issue Aug 12, 2021
Update books

## nomicon

2 commits in f51734eb5566c826b471977747ea3d7d6915bbe9..0c7e5bd1428e7838252bb57b7f0fbfda4ec82f02
2021-07-23 18:24:35 +0900 to 2021-08-04 10:18:22 -0700
- Document lifetime elision for fn types, Fn*, impl (rust-lang/nomicon#298)
- Remove unnecessary `extern crate`s (rust-lang/nomicon#297)

## reference

3 commits in 3b7be075af5d6e402a18efff672a8a265b4596fd..4884fe45c14f8b22121760fb117181bb4da8dfe0
2021-07-26 13:20:11 -0700 to 2021-07-28 21:31:28 -0700
- Mention "function item type to `fn pointer`" coercion (rust-lang/reference#1079)
- example for bindings after at (rust-lang/reference#1027)
- array-expr.md: fix typo; 'polish' sentence (rust-lang/reference#1080)

## book

10 commits in a07036f864b37896b31eb996cd7aedb489f69a1f..7e49659102f0977d9142190e1ba23345c0f00eb1
2021-07-26 20:19:46 -0400 to 2021-08-03 21:41:35 -0400
- Make explicit that enum variant construction is a function
- Clarify why None means we have to annotate the type
- Make the convert quotes script able to do one chapter
- Snapshot of chapter 5
-  (rust-lang/book#2811)
-  (rust-lang/book#2809)
- Ugh quote script, that's not right
- Introduce the dbg macro. Connects to rust-lang/book#1658
- Add an example of declaring and instantiating unit-like structs. Fixes rust-lang/book#2442.
- Remove authors field from all the manifests (rust-lang/book#2805)

## rustc-dev-guide

5 commits in 09343d6..c4644b4
2021-07-26 00:37:28 +0200 to 2021-08-10 20:41:44 +0900
- Remove a dead link in `new-target.md` + other nits (rust-lang/rustc-dev-guide#1186)
- Add description of -opt-bisect-limit LLVM option (rust-lang/rustc-dev-guide#1182)
- Fixed team responsible for stabilization (rust-lang/rustc-dev-guide#1181)
- Add S-Inactive PRs as another source of things contributors could work on (rust-lang/rustc-dev-guide#1177)
- git.md: Fix No-Merge Policy link

## embedded-book

1 commits in 09986cd352404eb4659db44613b27cac9aa652fc..4f9fcaa30d11ba52b641e6fd5206536d65838af9
2021-07-18 19:26:46 +0000 to 2021-08-06 17:43:12 +0000
- Fix typo in 'Memory Mapped Registers'  (rust-embedded/book#298)
@mikemorris
Copy link

Opened #2842 to address most of what I saw as direct swaps from println! calls to dbg!

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

Successfully merging a pull request may close this issue.

8 participants