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 to allow, 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
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 :)
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:A working implementation of the attribute is available in nightly with the
lint_reasonsfeature. 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? src2. How should the
#[expect]attribute interact with other lint attributes, likeallow,warn,deny? srcFor example, should this code fulfill the expectation or not?
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
xand 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?
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 thiscargo clippy -- -W clippy::pedanticBackground reading
#[expect]attribute andreasonsparameter (RFC 2383) reference#1237Note
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 :)