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

Tracking issue for RFC 2383, "Lint Reasons RFC" #54503

Closed
3 of 6 tasks
Centril opened this issue Sep 23, 2018 · 56 comments · Fixed by #120924
Closed
3 of 6 tasks

Tracking issue for RFC 2383, "Lint Reasons RFC" #54503

Centril opened this issue Sep 23, 2018 · 56 comments · Fixed by #120924
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. F-lint_reasons `#![feature(lint_reasons)]` S-tracking-needs-summary Status: It's hard to tell what's been done and what hasn't! Someone should do some investigation. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@Centril
Copy link
Contributor

Centril commented Sep 23, 2018

This is a tracking issue for the RFC "Lint Reasons RFC" (rust-lang/rfcs#2383).

Steps:

Unresolved questions:

  • The use sites of the reason parameter.
@Centril Centril added B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. T-lang Relevant to the language team, which will review and decide on the PR/issue. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. labels Sep 23, 2018
@zackmdavis
Copy link
Member

I started looking at this tonight. (Briefly; I regret that my time is limited.)

The example output in the RFC puts a reason: line immediately below the top-level error: line, but from a consilience-with-the-existing-implementation perspective, I'm inclined to think it would make more sense to use an ordinary note: (just as the existing "#[level(lint)] on by default" messages and must-use rationales do).

The reason should probably be stored as a third field inside of LintSource::Node.

@zackmdavis
Copy link
Member

PR for reason = is #54683.

Unresolved questions:

  • The use sites of the reason parameter.

@myrrlyn I'm not sure what "use sites" means in this context?

zackmdavis added a commit to zackmdavis/rust that referenced this issue Oct 15, 2018
This is just for the `reason =` name-value meta-item; the
`#[expect(lint)]` attribute also described in the RFC is a problem for
another day.

The place where we were directly calling `emit()` on a match block
(whose arms returned a mutable reference to a diagnostic-builder) was
admittedly cute, but no longer plausibly natural after adding the
if-let to the end of the `LintSource::Node` arm.

This regards rust-lang#54503.
zackmdavis added a commit to zackmdavis/rust that referenced this issue Oct 27, 2018
This is just for the `reason =` name-value meta-item; the
`#[expect(lint)]` attribute also described in the RFC is a problem for
another day.

The place where we were directly calling `emit()` on a match block
(whose arms returned a mutable reference to a diagnostic-builder) was
admittedly cute, but no longer plausibly natural after adding the
if-let to the end of the `LintSource::Node` arm.

This regards rust-lang#54503.
@zackmdavis
Copy link
Member

It's a little bit sad/awkward that reason comments are most useful in practice for allow (rather than warn, deny, or forbid, which authors are more likely to regard as self-explanatory), and yet allow is the only case for which the new reason = functionality doesn't actually do anything. 😿

(This observation prompted by my thought that we should be able to dogfood reason = in this repo now that that functionality is in the beta bootstrap compiler, but ag '//.*\n\w*#\[(warn|deny|forbid|allow)' --ignore tools --ignore test only turns up instances of allow.)

@oli-obk
Copy link
Contributor

oli-obk commented Dec 17, 2018

We could add a lint that suggests turning allow with reason into expect because $reasons

@myrrlyn
Copy link

myrrlyn commented Jul 8, 2019

I apologize for my absence on this issue.

I'm not sure what "use sites" means in this context?

My standing question was "how should the reason value be used in the diagnostic", and it appears that the simplest answer is the one you provided: "put it in a note item". I have no firm attachment to rendering it as reason: User text here, and if prior art exists for note: User text here, then that is perfectly fine.

@jonas-schievink jonas-schievink added the A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. label Jan 31, 2020
@JohnTitor
Copy link
Member

Here's the initial work of expect lint level: https://github.com/JohnTitor/rust/tree/lint-expect

The remaining thing is to trigger the expectation_missing lint but I have no idea how to implement. If someone could do, feel free to steal something from there. Or I'm happy to continue the work if someone could mentor me :)

@xFrednet
Copy link
Member

Hello everyone,
I would like to work on the expect attribute and move this issue towards stabilization.

Is there someone here who could mentor me? My contributions so far have only focussed on Clippy. If not I would most likely ask on Zulip for help 🙃.

@nikomatsakis
Copy link
Contributor

@xFrednet I would happily mentor you on this! Let me start by opening an issue dedicated to jus the implementaton, since I dislike using the tracking issue for that sort of thing. I'll assign it to you.

@xFrednet
Copy link
Member

xFrednet commented May 31, 2021

Issue #55112 is related to the implementation of the reason field. The current implementation apparently allows the usage of an attribute with only a reason #[allow(reason = "foo")]. Source:

// FIXME (#55112): issue unused-attributes lint if we thereby
// don't have any lint names (`#[level(reason = "foo")]`)

Noted as a FIXME in the LintsLevelBilder

Just to keep track that this also has to be fixed before stabilization.

PR: #94580

@xFrednet
Copy link
Member

Has a decision on the name been addressed yet?

The topic has been discussed as part of the design meeting. Generally, it was said, that expect could be used/doesn't need to be reserved, but the name might depend on how the expect attribute will work in the end.

At the risk of adding noise to a naming question, suppress reads well to me.

This might work, if the try-and-catch model is used for the expect attribute. Though, for me, this name doesn't imply, that a warning should be issued if nothing gets suppressed.

That's why I like expect (or similar variance) a bit more :)


If you have any thoughts on the mental model, a comment on Zulip would be appreciated. The discussion has sadly stalled, and some more feedback might help :)

@laralove143
Copy link

as far as i understand, unused allow annotations are only reported when expect is provided, why is that so? i'd be using this to notice allow annotations that are forgotten there or falsely added, and this adds another step to allowing lints

i'd prefer another lint that reports unused allows (and warns/denies/forbids as well)

the way eslint does this is you specify it in its config file, which is not what i prefer but its something to look at

@xFrednet
Copy link
Member

as far as i understand, unused allow annotations are only reported when expect is provided, why is that so?

Some #[allow] attributes can be unused most of the time, this happens for instance, when cfged is the trigger reason. It would be possible to use cfg_attr(allow)... but that is less readable than a simple #[allow]. It can also be that a project preemptively enables some lints it doesn't care about. This can especially, the case for project templates. This is to say, there is a place for #[allow] attributes, which are not triggered rn.

The idea for expect is, that it would be used instead of #[allow] in most cases. This requires some migration, but then it should essentially be the same as using #[allow] with a lint like you requested. Otherwise, please, say so, I might be missing something.

i'd prefer another lint that reports unused allows (and warns/denies/forbids as well)

Implementing this as a lint, might be possible, but would require the same framework and tracking nightly rustc currently does for #[expect]. One of the problems that came up during development was incremental compilation. It would be possible, but I feel like having a separate attribute, like #[expect], is more versatile. :)

@laralove143
Copy link

i think allowing conditionally based on the cfg is better but we cant impose that i think, my idea was this feature would be opt-in but in a way that doesnt require users to adding another attribute to every allow they use, so if it gets in their way, they can just disable it just like any other lint that gets in their way

@flip1995
Copy link
Member

flip1995 commented May 23, 2023

require users to adding another attribute to every allow they use, so if it gets in their way, they can just disable it just like any other lint that gets in their way

They shouldn't add another attribute, they should replace the allow with expect, where possible. For migration, a auto-fixable opt-in (Clippy) lint could be implemented, that looks for allow attributes and suggests to replace them with expect.

@xFrednet
Copy link
Member

For migration, a auto-fixable opt-in (Clippy) lint could be implemented, that looks for allow attributes and suggests to replace them with expect.

Clippy already has the clippy::allow_attributes lint for this :)

@laralove143
Copy link

ah, thats what the discussion is about then, i agree expect is a bit hard to understand for this, it makes sense but it's not obvious, i imagine most people will replace allows with expect, how about suppress or permit, they dont give the meaning as clearly across but it fits better as an alternative to allow in my opinion

@xFrednet xFrednet added the I-lang-nominated The issue / PR has been nominated for discussion during a lang team meeting. label Jul 10, 2023
@xFrednet
Copy link
Member

After the lang meeting in March, there was a discussion on Zulip what the mental model of the expect attribute should be. Two possible explanations came up:

  1. The expectation is fulfilled, if a #[warn] attribute in the same location would cause a diagnostic to be emitted. The suppression of this diagnostic fulfills the expectation. (src) (Current implementation in rustc)

  2. The expectation is fulfilled if removing the #[expect] attribute would cause the warning to be emitted. (src)

I've created a list of use cases to hopefully help with the discussion of these two models. Usually, both models work equally well, except for use case 4 which would only be possible with the first model.

I'm nominating this for T-lang to review.

@nikomatsakis
Copy link
Contributor

@xFrednet I just want to say, these are some excellent write-ups / summarization.

@nikomatsakis
Copy link
Contributor

@rustbot labels -I-lang-nominated

I'm removing the nomination -- @xFrednet thanks for your patience here. I've opened #115980 to drive this to a final decision. I'm really excited to see this land!

@rustbot rustbot removed the I-lang-nominated The issue / PR has been nominated for discussion during a lang team meeting. label Sep 19, 2023
@bors bors closed this as completed in 4bc39f0 Jun 26, 2024
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Jun 27, 2024
…u,blyxyas

Let's `#[expect]` some lints: Stabilize `lint_reasons` (RFC 2383)

Let's give this another try! The [previous stabilization attempt](rust-lang/rust#99063) was stalled by some unresolved questions. These have been discussed in a [lang team](rust-lang/lang-team#191) meeting. The last open question, regarding the semantics of the `#[expect]` attribute was decided on in rust-lang/rust#115980

I've just updated the [stabilization report](rust-lang/rust#54503 (comment)) with the discussed questions and decisions. Luckily, the decision is inline with the current implementation.

This hopefully covers everything. Let's hope that the CI will be green like the spring.

fixes #115980
fixes #54503

---

r? `@wesleywiser`

Tacking Issue: rust-lang/rust#54503
Stabilization Report: rust-lang/rust#54503 (comment)
Documentation Update: rust-lang/reference#1237

<!--
For Clippy:

changelog: [`allow_attributes`]: Is now available on stable, since the `lint_reasons` feature was stabilized
changelog: [`allow_attributes_without_reason`]: Is now available on stable, since the `lint_reasons` feature was stabilized
-->

---

Roses are red,
Violets are blue,
Let's expect lints,
With reason clues
flip1995 pushed a commit to flip1995/rust-clippy that referenced this issue Jun 27, 2024
…u,blyxyas

Let's `#[expect]` some lints: Stabilize `lint_reasons` (RFC 2383)

Let's give this another try! The [previous stabilization attempt](rust-lang/rust#99063) was stalled by some unresolved questions. These have been discussed in a [lang team](rust-lang/lang-team#191) meeting. The last open question, regarding the semantics of the `#[expect]` attribute was decided on in rust-lang/rust#115980

I've just updated the [stabilization report](rust-lang/rust#54503 (comment)) with the discussed questions and decisions. Luckily, the decision is inline with the current implementation.

This hopefully covers everything. Let's hope that the CI will be green like the spring.

fixes #115980
fixes #54503

---

r? `@wesleywiser`

Tacking Issue: rust-lang/rust#54503
Stabilization Report: rust-lang/rust#54503 (comment)
Documentation Update: rust-lang/reference#1237

<!--
For Clippy:

changelog: [`allow_attributes`]: Is now available on stable, since the `lint_reasons` feature was stabilized
changelog: [`allow_attributes_without_reason`]: Is now available on stable, since the `lint_reasons` feature was stabilized
-->

---

Roses are red,
Violets are blue,
Let's expect lints,
With reason clues
flip1995 pushed a commit to flip1995/rust-clippy that referenced this issue Jun 28, 2024
…u,blyxyas

Let's `#[expect]` some lints: Stabilize `lint_reasons` (RFC 2383)

Let's give this another try! The [previous stabilization attempt](rust-lang/rust#99063) was stalled by some unresolved questions. These have been discussed in a [lang team](rust-lang/lang-team#191) meeting. The last open question, regarding the semantics of the `#[expect]` attribute was decided on in rust-lang/rust#115980

I've just updated the [stabilization report](rust-lang/rust#54503 (comment)) with the discussed questions and decisions. Luckily, the decision is inline with the current implementation.

This hopefully covers everything. Let's hope that the CI will be green like the spring.

fixes #115980
fixes #54503

---

r? `@wesleywiser`

Tacking Issue: rust-lang/rust#54503
Stabilization Report: rust-lang/rust#54503 (comment)
Documentation Update: rust-lang/reference#1237

<!--
For Clippy:

changelog: [`allow_attributes`]: Is now available on stable, since the `lint_reasons` feature was stabilized
changelog: [`allow_attributes_without_reason`]: Is now available on stable, since the `lint_reasons` feature was stabilized
-->

---

Roses are red,
Violets are blue,
Let's expect lints,
With reason clues
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. F-lint_reasons `#![feature(lint_reasons)]` S-tracking-needs-summary Status: It's hard to tell what's been done and what hasn't! Someone should do some investigation. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.