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

Implement an internal lint encouraging use of Span::eq_ctxt #116787

Merged
merged 5 commits into from
Oct 17, 2023

Conversation

a-lafrance
Copy link
Contributor

@a-lafrance a-lafrance commented Oct 16, 2023

Adds a new Rustc internal lint that forbids use of .ctxt() == .ctxt() for spans, encouraging use of .eq_ctxt() instead (see #49509).

Also fixed a few violations of the lint in the Rustc codebase (a fun additional way I could test my code). Edit: MIR opt folks I believe that's why you're CC'ed, just a heads up.

Two things I'm not sure about:

  1. The way I chose to detect calls to Span::ctxt. I know adding diagnostic items to methods is generally discouraged, but after some searching and experimenting I couldn't find anything else that worked, so I went with it. That said, I'm happy to implement something different if there's a better way out there. (For what it's worth, if there is a better way, it might be worth documenting in the rustc-dev-guide, which I'm happy to take care of)
  2. The error message for the lint. Ideally it would probably be good to give some context as to why the suggestion is made (e.g. rustc::default_hash_types tells the user that it's because of performance), but I don't have that context so I couldn't put it in the error message. Happy to iterate on the error message based on feedback during review.

r? @oli-obk

@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. labels Oct 16, 2023
@rustbot
Copy link
Collaborator

rustbot commented Oct 16, 2023

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rust-log-analyzer

This comment has been minimized.

@oli-obk
Copy link
Contributor

oli-obk commented Oct 16, 2023

impl lgtm (just needs to fix the == usage in clippy, too), though we should probably include a note somewhere that explains why, ideally as a doc comment on the method, too.

r? @compiler-errors do you remember details?

@a-lafrance
Copy link
Contributor Author

PR to fix the lint violation in Clippy is up: rust-lang/rust-clippy#11679

@compiler-errors
Copy link
Member

There's nothing technically wrong with using == on ctxt, I just added it as a convenience method -- but I guess now that there's a convenience method, we should prefer it. So I don't think there's much documentation needed here.

@oli-obk
Copy link
Contributor

oli-obk commented Oct 16, 2023

PR to fix the lint violation in Clippy is up: rust-lang/rust-clippy#11679

Oh 😅 you could've just done it in this PR. x test clippy or even just x check clippy will work locally to test it and you can commit clippy changes here

@a-lafrance
Copy link
Contributor Author

a-lafrance commented Oct 16, 2023

Yeah 😅 I found that out in the Clippy PR. Good to know though, I'll update this PR with those changes.

Edit: updated

@rustbot
Copy link
Collaborator

rustbot commented Oct 16, 2023

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@bors
Copy link
Contributor

bors commented Oct 17, 2023

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

@oli-obk
Copy link
Contributor

oli-obk commented Oct 17, 2023

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Oct 17, 2023

📌 Commit e89d4d4 has been approved by oli-obk

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 Oct 17, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 17, 2023
…li-obk

Implement an internal lint encouraging use of `Span::eq_ctxt`

Adds a new Rustc internal lint that forbids use of `.ctxt() == .ctxt()` for spans, encouraging use of `.eq_ctxt()` instead (see rust-lang#49509).

Also fixed a few violations of the lint in the Rustc codebase (a fun additional way I could test my code). Edit: MIR opt folks I believe that's why you're CC'ed, just a heads up.

Two things I'm not sure about:
1. The way I chose to detect calls to `Span::ctxt`. I know adding diagnostic items to methods is generally discouraged, but after some searching and experimenting I couldn't find anything else that worked, so I went with it. That said, I'm happy to implement something different if there's a better way out there. (For what it's worth, if there is a better way, it might be worth documenting in the rustc-dev-guide, which I'm happy to take care of)
2. The error message for the lint. Ideally it would probably be good to give some context as to why the suggestion is made (e.g. `rustc::default_hash_types` tells the user that it's because of performance), but I don't have that context so I couldn't put it in the error message. Happy to iterate on the error message based on feedback during review.

r? `@oli-obk`
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 17, 2023
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#116717 (Special case iterator chain checks for suggestion)
 - rust-lang#116719 (Add MonoItems and Instance to stable_mir)
 - rust-lang#116787 (Implement an internal lint encouraging use of `Span::eq_ctxt`)
 - rust-lang#116827 (Make `handle_options` public again.)
 - rust-lang#116838 (Fix duplicate labels emitted in `render_multispan_macro_backtrace()`)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 17, 2023
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#111072 (Add new simpler and more explicit syntax for check-cfg)
 - rust-lang#116717 (Special case iterator chain checks for suggestion)
 - rust-lang#116719 (Add MonoItems and Instance to stable_mir)
 - rust-lang#116787 (Implement an internal lint encouraging use of `Span::eq_ctxt`)
 - rust-lang#116827 (Make `handle_options` public again.)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 3ea438e into rust-lang:master Oct 17, 2023
11 checks passed
@rustbot rustbot added this to the 1.75.0 milestone Oct 17, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Oct 17, 2023
Rollup merge of rust-lang#116787 - a-lafrance:span-internal-lint, r=oli-obk

Implement an internal lint encouraging use of `Span::eq_ctxt`

Adds a new Rustc internal lint that forbids use of `.ctxt() == .ctxt()` for spans, encouraging use of `.eq_ctxt()` instead (see rust-lang#49509).

Also fixed a few violations of the lint in the Rustc codebase (a fun additional way I could test my code). Edit: MIR opt folks I believe that's why you're CC'ed, just a heads up.

Two things I'm not sure about:
1. The way I chose to detect calls to `Span::ctxt`. I know adding diagnostic items to methods is generally discouraged, but after some searching and experimenting I couldn't find anything else that worked, so I went with it. That said, I'm happy to implement something different if there's a better way out there. (For what it's worth, if there is a better way, it might be worth documenting in the rustc-dev-guide, which I'm happy to take care of)
2. The error message for the lint. Ideally it would probably be good to give some context as to why the suggestion is made (e.g. `rustc::default_hash_types` tells the user that it's because of performance), but I don't have that context so I couldn't put it in the error message. Happy to iterate on the error message based on feedback during review.

r? ``@oli-obk``
@a-lafrance a-lafrance deleted the span-internal-lint branch October 18, 2023 00:46
bors-ferrocene bot added a commit to ferrocene/ferrocene that referenced this pull request Oct 18, 2023
57: Pull upstream master 2023 10 18 r=pietroalbini a=Veykril

* rust-lang/rust#116505
* rust-lang/rust#116840
* rust-lang/rust#116767
* rust-lang/rust#116855
  * rust-lang/rust#116827
  * rust-lang/rust#116787
  * rust-lang/rust#116719
  * rust-lang/rust#116717
  * rust-lang/rust#111072
* rust-lang/rust#116844
* rust-lang/rust#115577
* rust-lang/rust#116756
* rust-lang/rust#116518



Co-authored-by: Urgau <[email protected]>
Co-authored-by: Esteban Küber <[email protected]>
Co-authored-by: Deadbeef <[email protected]>
Co-authored-by: Ralf Jung <[email protected]>
Co-authored-by: Camille GILLOT <[email protected]>
Co-authored-by: Celina G. Val <[email protected]>
Co-authored-by: Nicholas Nethercote <[email protected]>
Co-authored-by: Arthur Lafrance <[email protected]>
Co-authored-by: Nikolay Arhipov <[email protected]>
Co-authored-by: Nikita Popov <[email protected]>
Co-authored-by: bors <[email protected]>
@wesleywiser wesleywiser mentioned this pull request Jan 26, 2024
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

6 participants