Skip to content

Design decisions around the #[expect] attribute #191

Closed
@xFrednet

Description

@xFrednet

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 :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-langmeeting-proposalProposal for a lang team design meetingmeeting-scheduledLang team design meeting that has a scheduled date

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions