Skip to content

Add DesugaringKind::FormatLiteral #142594

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

mejrs
Copy link
Contributor

@mejrs mejrs commented Jun 16, 2025

Implements DesugaringKind::FormatLiteral to mark the FormatArgs desugaring of format literals. The main use for this is to stop yapping about about formatting parameters if we're not anywhere near a format literal. The other use case is to fix suggestions such as #141350. It might also be useful for new or existing diagnostics that check whether they're in a format-like macro.

cc @xizheyin @fmease

@rustbot
Copy link
Collaborator

rustbot commented Jun 16, 2025

r? @SparrowLii

rustbot has assigned @SparrowLii.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 16, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jun 16, 2025

Some changes occurred in compiler/rustc_ast_lowering/src/format.rs

cc @m-ou-se

@fmease
Copy link
Member

fmease commented Jun 16, 2025

We might want to block this on #140748, I'm relatively sure. Just FYI

@mejrs
Copy link
Contributor Author

mejrs commented Jun 16, 2025

Why is that?

@fmease
Copy link
Member

fmease commented Jun 16, 2025

Idk, if it's not conflicting according to git and if it's not stepping on each other's toes in other ways, I guess it's fine — I only skimmed boths diffs. Mara's PR will likely get approved soon anyway.

Copy link
Contributor

@xizheyin xizheyin left a comment

Choose a reason for hiding this comment

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

Great, #141633 can be refactored after this.

Copy link
Member

@SparrowLii SparrowLii left a comment

Choose a reason for hiding this comment

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

This is very meaningful and the impl looks fine. But adding a new desugaringKind for diagnostics needs some opinions IMO
r? diagnostics

@rustbot rustbot assigned chenyukang and unassigned SparrowLii Jun 18, 2025
@@ -17,7 +19,9 @@ error[E0277]: `Bar` doesn't implement `Debug`
--> $DIR/no-debug.rs:10:32
|
LL | println!("{:?} {:?}", Foo, Bar);
| ^^^ `Bar` cannot be formatted using `{:?}` because it doesn't implement `Debug`
| ---- ^^^ `Bar` cannot be formatted using `{:?}` because it doesn't implement `Debug`
Copy link
Member

Choose a reason for hiding this comment

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

This change on diagnostic reminds me of this issue:
#140578

while we had a PR for it, but seems it's stalled.

Will this PR also resolve #140578? If so, we can link with it, add a unit test, and close that one too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't, but it does make that PR easier to implement; they can simply replace all of the diagnostic item stuff with a matches!(span.desugaring_kind(), Some(rustc_span::DesugaringKind::FormatLiteral {..}))

@@ -4,9 +4,8 @@ error[E0277]: `a::Inner<T>` doesn't implement `Debug`
LL | #[derive(Debug)]
| ----- in this derive macro expansion
LL | struct Outer<T>(Inner<T>);
| ^^^^^^^^ `a::Inner<T>` cannot be formatted using `{:?}`
| ^^^^^^^^ the trait `Debug` is not implemented for `a::Inner<T>`
Copy link
Member

Choose a reason for hiding this comment

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

I'm neutral about this change. Maybe some beginners need to know the relationship between Debug and {:?}. I am not sure about this.

@chenyukang
Copy link
Member

Looks ok for me.

@bors delegate+

@bors
Copy link
Collaborator

bors commented Jun 20, 2025

✌️ @mejrs, you can now approve this pull request!

If @chenyukang told you to "r=me" after making some further change, please make that change, then do @bors r=@chenyukang

@mejrs
Copy link
Contributor Author

mejrs commented Jun 21, 2025

@bors r=@chenyukang

@bors
Copy link
Collaborator

bors commented Jun 21, 2025

📌 Commit 3858b2c has been approved by chenyukang

It is now in the queue for this repository.

@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 Jun 21, 2025
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 22, 2025
Add DesugaringKind::FormatLiteral

Implements `DesugaringKind::FormatLiteral` to mark the FormatArgs desugaring of format literals. The main use for this is to stop yapping about about formatting parameters if we're not anywhere near a format literal. The other use case is to fix suggestions such as rust-lang#141350. It might also be useful for new or existing diagnostics that check whether they're in a format-like macro.

cc `@xizheyin` `@fmease`
bors added a commit that referenced this pull request Jun 22, 2025
Rollup of 10 pull requests

Successful merges:

 - #140254 (Pass -Cpanic=abort for the panic_abort crate)
 - #142594 (Add DesugaringKind::FormatLiteral)
 - #142600 (Port `#[rustc_pub_transparent]` to the new attribute system)
 - #142617 (improve search graph docs, reset `encountered_overflow` between reruns)
 - #142641 (Generate symbols.o for proc-macros too)
 - #142747 (rustdoc_json: conversion cleanups)
 - #142776 (All HIR attributes are outer)
 - #142800 (integer docs: remove extraneous text)
 - #142850 (remove asm_goto feature annotation, for it is now stabilized)
 - #142860 (Notify me on tidy changes)

r? `@ghost`
`@rustbot` modify labels: rollup
@jhpratt
Copy link
Member

jhpratt commented Jun 22, 2025

@bors r-

#142861 (comment)

@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 Jun 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants