Description
Summary
The #[expect]
attribute as proposed in RFC 2383 adds a new attribute that suppresses lint emissions, but issues a warning if the expected lint doesn't trigger anymore. In the proposed RFC it was described as this:
This RFC adds an
expect
lint attribute that functions identically toallow
, but will cause a lint to be emitted when the code it decorates does not raise a lint warning.
A working implementation of the attribute is available in nightly with the lint_reasons
feature. See this playground as an example. The goal of this meeting is to resolve the last questions remaining in the tracking issue.
Questions
The questions also contain a collapsed explanation of the current behavior. (This might not work on the mobile view)
1. Should the attribute really be called #[expect]
or is the name too generic? src
2. How should the #[expect]
attribute interact with other lint attributes, like allow
, warn
, deny
? src
For example, should this code fulfill the expectation or not?
#![feature(lint_reasons)]
#[expect(unused_variables)]
pub fn f() {
#[warn(unused_variables)]
let x = 1;
}
Current implementation
Currently, expectations are only fulfilled by lint emissions directly affected by it. The example above would trigger two warnings, one for the unused value x
and one for the fulfilled expectation.
3 Should an expectation be fulfilled, by a lint that would otherwise be allowed? src
For example, should this code fulfill the expectation or not?
#![feature(lint_reasons)]
#![allow(unused)]
#[allow(unsafe_code)]
pub fn f() {
#[expect(unsafe_code)]
unsafe {
}
}
Current implementation
The current implementation only checks if a lint is emitted at a node affected by the lint attribute. The example above would therefore fulfill the expectation, just like #[warn]
would cause the code to trigger the lint. If this wouldn't be the case, the #[expect]
attribute would change behavior based on the outer lint level. This can become confusing if the user defines a lint level via console arguments like this cargo clippy -- -W clippy::pedantic
Background reading
- The tracking issue starting from the stabilization report: Tracking issue for RFC 2383, "Lint Reasons RFC" rust#54503 (comment)
- The RFC: https://rust-lang.github.io/rfcs/2383-lint-reasons.html
- The draft documentation for the current implementation: Document new
#[expect]
attribute andreasons
parameter (RFC 2383) reference#1237
Note
I'd like to attend the meeting as well. It would be awesome if I could be notified when the meeting has been scheduled. I'll also keep an eye on the calender :)
Metadata
Metadata
Assignees
Type
Projects
Status