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

Add lint to deny diagnostics composed of static strings #108760

Merged
merged 2 commits into from
Apr 26, 2023

Conversation

clubby789
Copy link
Contributor

@clubby789 clubby789 commented Mar 5, 2023

r? ghost

I'm hoping to have a lint that semi-automatically converts simple diagnostics such as struct_span_err(span, "msg").help("msg").span_note(span2, "msg").emit() to typed session diagnostics. It's quite hacky and not entirely working because of problems with x fix but should hopefully help reduce some of the work.
I'm going to start trying to apply what I can from this, but opening this as a draft in case anyone wants to develop on it.

cc #100717

@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. A-diagnostics Area: Messages for errors, warnings, and lints A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. labels Mar 5, 2023
@compiler-errors
Copy link
Member

Cool! I like this a lot. Do you plan on landing this as a lint enabled against the compiler, or are you just using it locally? Couldn't tell what your next steps were in "but opening this as a draft in case anyone wants to develop on it.".

@rust-log-analyzer

This comment has been minimized.

@clubby789
Copy link
Contributor Author

I don't think tihs is something that should end up landing since it's reasonably hacky and also hopefully should be a one-time run to apply all the fixes it can.
Sorry if my comment was a bit vague - my thoughts were that this only transforms the most basic cases, but I wanted to have it available in case other people wanted to enhance it to catch more cases (like

let mut err = struct_span_err(..);
err.help(..);
err.note(..);
err.emit();

@compiler-errors
Copy link
Member

I guess so -- it would be nice if we could enforce some lint to make sure people don't add new usages of struct_span_err with static strings, even if it doesn't do the fixing or even provides as helpful of a suggestion as this one.

@clubby789
Copy link
Contributor Author

Maybe this could be landed )with improved messages) but with all the code that does fixing and file modification cfg'd out? Then the detection part of the lint stays working and the rest is readily available if the lint is enhanced

@compiler-errors
Copy link
Member

but with all the code that does fixing and file modification cfg'd out?

Happy to review a version of this lint with all of that logic removed, but would also be open to considering it cfg'd out if it's pretty easily separable from the other logic. Not a huge fan of cfg'ing it out, just because it's like committing commented out code :) but definitely could change my mind.

@bors
Copy link
Contributor

bors commented Mar 12, 2023

☔ The latest upstream changes (presumably #108682) made this pull request unmergeable. Please resolve the merge conflicts.

@compiler-errors
Copy link
Member

@rustbot author

@rustbot rustbot 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-review Status: Awaiting review from the assignee but also interested parties. labels Mar 17, 2023
@compiler-errors
Copy link
Member

@clubby789 any thoughts on this?

@clubby789 clubby789 changed the title experiment: Add lint to automatically generate typed diagnostics for simple cases Add lint to deny diagnostics composed of static strings Apr 10, 2023
@clubby789
Copy link
Contributor Author

Some failures will be fixed by #110092 so I'll finish fixing up the other failures once that is merged

@rustbot label +S-blocked

@rustbot rustbot added the S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. label Apr 10, 2023
@rust-log-analyzer

This comment has been minimized.

@compiler-errors
Copy link
Member

Seems to be unblocked because of #11092 landing

@rustbot author

@clubby789 clubby789 marked this pull request as ready for review April 16, 2023 14:42
@clubby789
Copy link
Contributor Author

@rustbot ready
@rustbot label -S-blocked -S-experimental

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. labels Apr 16, 2023
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@jyn514 jyn514 added the D-diagnostic-infra Diagnostics: Issues that affect all diagnostics, or relate to the diagnostic machinery itself. label Apr 17, 2023
@clubby789
Copy link
Contributor Author

clubby789 commented Apr 17, 2023

In a future PR I'll probably relax the static string check, since any diagnostic created in a chain of diagnostic functions in a single statement should be easily translatable to derive diagnostics, without requiring subdiagnostics or much refactoring of the logic.

@bors
Copy link
Contributor

bors commented Apr 22, 2023

☔ The latest upstream changes (presumably #106934) made this pull request unmergeable. Please resolve the merge conflicts.

@rustbot rustbot removed the S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. label Apr 22, 2023
@clubby789
Copy link
Contributor Author

(oops, I left this as ghost)
r? compiler

@bors
Copy link
Contributor

bors commented Apr 25, 2023

☔ The latest upstream changes (presumably #110325) made this pull request unmergeable. Please resolve the merge conflicts.

@wesleywiser
Copy link
Member

Thanks @clubby789! Using a lint to find these was a really good idea 👍

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Apr 26, 2023

📌 Commit 0138513 has been approved by wesleywiser

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 Apr 26, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 26, 2023
…iaskrgr

Rollup of 10 pull requests

Successful merges:

 - rust-lang#108760 (Add lint to deny diagnostics composed of static strings)
 - rust-lang#109444 (Change tidy error message for TODOs)
 - rust-lang#110419 (Spelling library)
 - rust-lang#110550 (Suggest deref on comparison binop RHS even if type is not Copy)
 - rust-lang#110641 (Add new rustdoc book chapter to describe in-doc settings)
 - rust-lang#110798 (pass `unused_extern_crates` in `librustdoc::doctest::make_test`)
 - rust-lang#110819 (simplify TrustedLen impls)
 - rust-lang#110825 (diagnostics: add test case for already-solved issue)
 - rust-lang#110835 (Make some region folders a little stricter.)
 - rust-lang#110847 (rustdoc-json: Time serialization.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 309496c into rust-lang:master Apr 26, 2023
@rustbot rustbot added this to the 1.71.0 milestone Apr 26, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 27, 2023
…ial, r=compiler-errors

Migrate trivially translatable `rustc_parse` diagnostics

cc rust-lang#100717

Migrate diagnostics in `rustc_parse` which are emitted in a single statement. I worked on this by expanding the lint introduced in rust-lang#108760, although that isn't included here as there is much more work to be done to satisfy it
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 28, 2023
…ial, r=compiler-errors

Migrate trivially translatable `rustc_parse` diagnostics

cc rust-lang#100717

Migrate diagnostics in `rustc_parse` which are emitted in a single statement. I worked on this by expanding the lint introduced in rust-lang#108760, although that isn't included here as there is much more work to be done to satisfy it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic D-diagnostic-infra Diagnostics: Issues that affect all diagnostics, or relate to the diagnostic machinery itself. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants