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 diagnostic item for std::iter::Iterator::enumerate #124542

Merged
merged 1 commit into from
May 1, 2024

Conversation

CBSpeir
Copy link
Contributor

@CBSpeir CBSpeir commented Apr 29, 2024

Adds a diagnostic item for the std::iter:Iterator::enumerate trait method. This change, along with PR #124308, will be used by the clippy unused_enumerate_index lint to move away from paths to using diagnostic items.

see: rust-lang/rust-clippy#5393

@rustbot
Copy link
Collaborator

rustbot commented Apr 29, 2024

r? @scottmcm

rustbot has assigned @scottmcm.
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 Apr 29, 2024
@@ -974,6 +974,7 @@ pub trait Iterator {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_do_not_const_check]
#[cfg_attr(not(test), rustc_diagnostic_item = "enumerate_method")]
Copy link
Member

Choose a reason for hiding this comment

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

Maybe a silly question, but why not(test)?

A quick rg rustc_diagnostic_item library shows lots with, but also lots without, and I don't understand why.

Copy link
Contributor Author

@CBSpeir CBSpeir Apr 30, 2024

Choose a reason for hiding this comment

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

The Rust Compiler Development Guide explains, not including not(test) can cause compilation errors while running some tests. It goes on to say it's okay to add it as a preventative measure for all diagnostic items.

I did not test whether this specific diagnostic item causes any testing compilation errors. I will look into this further to determine if it does.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ran ./x test, which I believe runs all tests given my current configuration. There were no failures with not(test) removed.

Copy link
Member

@lukas-code lukas-code Apr 30, 2024

Choose a reason for hiding this comment

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

The cfg(not(test)) is required in alloc and std, but not in core.

This is because alloc and std contain some unit #[test]s as part of the library crates and the crates therefore have to be compiled twice: Once as a library as a dependency of the test crate (which contains the default test runner) and once as an executable that imports the test crate.

When the crates are compiled twice and the diagnostic items don't have cfg(not(test)), then we get an error that the diagnostic items are defined multiple times. (The same also happens for lang items.)

The core package explicitly doesn't test its library crate and only has integration tests, so the cfg(not(test)) is not required there.

[lib]
test = false
bench = false

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since cfg(not(test)) is not required for this diagnostic item, should I remove it? Or is it okay to leave it on as a preventative measure?

@scottmcm
Copy link
Member

scottmcm commented May 1, 2024

Thanks for teaching me about this! Since this is far from the only place that would be doing this in core, I think it's fine to accept as-is and if people want to change them all later for consistency that can be a different PR.

@bors r+ rollup=always

@bors
Copy link
Contributor

bors commented May 1, 2024

📌 Commit c8079e9 has been approved by scottmcm

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 May 1, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request May 1, 2024
…method, r=scottmcm

Add diagnostic item for `std::iter::Iterator::enumerate`

Adds a diagnostic item for the `std::iter:Iterator::enumerate` trait method. This change, along with PR rust-lang#124308, will be used by the clippy `unused_enumerate_index` lint to move away from paths to using diagnostic items.

see: rust-lang/rust-clippy#5393
bors added a commit to rust-lang-ci/rust that referenced this pull request May 1, 2024
…iaskrgr

Rollup of 3 pull requests

Successful merges:

 - rust-lang#124529 (Rewrite select (in the new solver) to use a `ProofTreeVisitor`)
 - rust-lang#124542 (Add diagnostic item for `std::iter::Iterator::enumerate`)
 - rust-lang#124566 (fix `NormalizesTo` proof tree issue)

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

Rollup of 2 pull requests

Successful merges:

 - rust-lang#124542 (Add diagnostic item for `std::iter::Iterator::enumerate`)
 - rust-lang#124566 (fix `NormalizesTo` proof tree issue)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 38cbad9 into rust-lang:master May 1, 2024
9 checks passed
@rustbot rustbot added this to the 1.80.0 milestone May 1, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 1, 2024
Rollup merge of rust-lang#124542 - CBSpeir:diagnostic-item-enumerate-method, r=scottmcm

Add diagnostic item for `std::iter::Iterator::enumerate`

Adds a diagnostic item for the `std::iter:Iterator::enumerate` trait method. This change, along with PR rust-lang#124308, will be used by the clippy `unused_enumerate_index` lint to move away from paths to using diagnostic items.

see: rust-lang/rust-clippy#5393
@CBSpeir CBSpeir deleted the diagnostic-item-enumerate-method branch May 1, 2024 20:13
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. 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.

5 participants