Skip to content

dbg!: also print column #114910

Closed
Closed
@matthiaskrgr

Description

@matthiaskrgr
Member

I just found myself writing

 .map(|line| if double_ice {  dbg!(&line);   (line, ICEKind::DoubleIce) } else {  dbg!(&line);  (line, ICEKind::Ice(interestingness)) });

only to discover that the dbg macro in fact only prints the source line and not the column of the macro start or something like that 😅

[src/main.rs:1987] &line = "'  left: Align(2 bytes)' ' right: Align(4 bytes)'    assertion `left == right` failed: alignment mismatch between ABI and layout in TyAndLayout {"
[src/main.rs:1987] &line = "'  left: Align(2 bytes)' ' right: Align(4 bytes)'    assertion `left == right` failed: alignment mismatch between ABI and layout in TyAndLayout {"
[src/main.rs:1987] &line = "'  left: Align(2 bytes)' ' right: Align(4 bytes)'    assertion `left == right` failed: alignment mismatch between ABI and layout in TyAndLayout {"
[src/main.rs:1987] &line = "'  left: Align(2 bytes)' ' right: Align(4 bytes)'    assertion `left == right` failed: alignment mismatch between ABI and layout in TyAndLayout {"
[src/main.rs:1987] &line = "'  left: Align(2 bytes)' ' right: Align(4 bytes)'    assertion `left == right` failed: alignment mismatch between ABI and layout in TyAndLayout {"

Is it possible to add the column as well?

Activity

added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Aug 16, 2023
added
Libs-SmallLibs issues that are considered "small" or self-contained
on Aug 16, 2023
darklyspaced

darklyspaced commented on Aug 17, 2023

@darklyspaced
Contributor

@rustbot claim

Urgau

Urgau commented on Aug 17, 2023

@Urgau
Member

This section from the RFC is quite relevant, Excluding the column number:

Most likely, only one dbg!(expr) call will occur per line. The remaining cases will likely occur when dealing with binary operators such as with: dbg!(x) + dbg!(y) + dbg!(z), or with several arguments to a function / method call. However, since the macro prints out stringify!(expr), the user can clearly see which expression on the line that generated the value.
The only exception to this is if the same expression is used multiple times and crucically has side effects altering the value between calls. This scenario is probably uncommon. Furthermore, even in this case, one can visually distinguish between the calls since one is first and the second comes next.

Another reason to exclude column!() is that we want to keep the macro simple, and thus,
we only want to keep the essential parts that help debugging most.

However, the column!() isn't very visually disturbing since it uses horizontal screen real-estate but not vertical real-estate, which may still be a good reason to keep it. Nonetheless, this argument is not sufficient to keep column!(), wherefore this RFC will not include it.

darklyspaced

darklyspaced commented on Aug 18, 2023

@darklyspaced
Contributor

while I agree with the fact that often there is only one debug statement a line, i think that there is one major benefit that the rfc overlooked: users can directly jump to the pertinent debug statement through one unified method regardless of what <expr> are used in the statement itself and if multiple share a single line. searching visually is always slower than a hard, concrete jump.

additionally, the rfc failed to acknowledge the case above as being an ambiguous situation when using solely line numbers. all this combined with the fact that

column!() isn't very visually disturbing since it uses horizontal screen real-estate but not vertical real-estate

means that it seems like a pretty sensible addition to the macro.

added
T-libsRelevant to the library team, which will review and decide on the PR/issue.
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.
and removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Aug 22, 2023
added 2 commits that reference this issue on Dec 16, 2023

Auto merge of rust-lang#114962 - darklyspaced:debug, r=est31

Auto merge of rust-lang#114962 - darklyspaced:debug, r=est31

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

Metadata

Metadata

Assignees

Labels

C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Libs-SmallLibs issues that are considered "small" or self-containedT-libsRelevant to the library team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @matthiaskrgr@Urgau@rustbot@Noratrieb@darklyspaced

    Issue actions

      `dbg!`: also print column · Issue #114910 · rust-lang/rust