Skip to content

Add remove literal dbg stmt for remove_dbg #20354

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

Merged

Conversation

A4-Tacks
Copy link
Contributor

@A4-Tacks A4-Tacks commented Aug 1, 2025

Remove only contain literals dbg statement

fn foo() {
    $0dbg!(3);
    dbg!(2.6);
    dbg!(1, 2.5);
    dbg!('x');
    // needless comment
    dbg!("foo");$0
}

->

fn foo() {
    // needless comment
}

Old:

fn foo() {
    3;
    2.6;
    (1, 2.5);
    'x';
    // needless comment
    "foo";
}

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 1, 2025
@ChayimFriedman2
Copy link
Contributor

dbg!() of literals seems rather uncommon. Can we get this to also remove variable names (dbg!(foo) and dbg!(&foo))?

@A4-Tacks
Copy link
Contributor Author

A4-Tacks commented Aug 3, 2025

That dbg!(foo) must have Copy bounded

@A4-Tacks
Copy link
Contributor Author

A4-Tacks commented Aug 3, 2025

That dbg!(foo) must have Copy bounded

It seems that due to syntax::hacks::parse_expr_from_str, I am unable to resolve the type of the expression

@ChayimFriedman2
Copy link
Contributor

That dbg!(foo) must have Copy bounded

No? Removing it can't change code meaning, even if it's not Copy.

@A4-Tacks
Copy link
Contributor Author

A4-Tacks commented Aug 4, 2025

No? Removing it can't change code meaning, even if it's not Copy.

Example side-effect Drop implement or Drop out of await point

@ChayimFriedman2
Copy link
Contributor

I think we can safely ignore that. Assists are not required to never change code meaning, and this side-effect is rarely a problem.

@A4-Tacks
Copy link
Contributor Author

A4-Tacks commented Aug 5, 2025

I think we can safely ignore that. Assists are not required to never change code meaning, and this side-effect is rarely a problem.

ok

Copy link
Contributor

@ChayimFriedman2 ChayimFriedman2 left a comment

Choose a reason for hiding this comment

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

Can you squash please?

Remove only contain literals dbg statement

```rust
fn foo() {
    let n = 2;
    $0dbg!(3);
    dbg!(2.6);
    dbg!(1, 2.5);
    dbg!('x');
    dbg!(&n);
    dbg!(n);
    // needless comment
    dbg!("foo");$0
}
```
->
```rust
fn foo() {
    // needless comment
}
```
Old:
```rust
fn foo() {
    3;
    2.6;
    (1, 2.5);
    'x';
    &n;
    n;
    // needless comment
    "foo";
}
```
@A4-Tacks A4-Tacks force-pushed the clean-lit-stmt-remove-dbg branch from 26f834e to 75fd004 Compare August 6, 2025 13:34
@A4-Tacks
Copy link
Contributor Author

A4-Tacks commented Aug 6, 2025

Can you squash please?

Ok

@ChayimFriedman2
Copy link
Contributor

Thanks!

@ChayimFriedman2 ChayimFriedman2 added this pull request to the merge queue Aug 6, 2025
Merged via the queue into rust-lang:master with commit 4b49c7b Aug 6, 2025
15 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 6, 2025
@A4-Tacks A4-Tacks deleted the clean-lit-stmt-remove-dbg branch August 7, 2025 06:01
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.

3 participants