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

Replace #[allow(lint)] with #[expect(lint)] #1820

Merged
merged 6 commits into from
Feb 8, 2025

Conversation

lrh2000
Copy link
Contributor

@lrh2000 lrh2000 commented Jan 25, 2025

#[expect(lint)] has been stabilized for a while. We should use it instead of #[allow(lint)] whenever possible. RFL's coding guidelines explains why:

On top of that, Rust provides the expect attribute [..]. It makes the compiler warn if the warning was not produced. [..]

This means that expects do not get forgotten when they are not needed, [..]

Thus prefer expect over allow unless [..]

In this PR, I have removed all obsolete #[allow(lint)] and replaced the remaining #[allow(lint)] with #[expect(lint)].

I'm also trying to globally enable the allow_attributes lint to prevent #[allow(lint)] from being added inadvertently in the future. I'm trying to figure out what is the best way for us to globally enable lint1.

First, I enabled the lint in the workspace:

# In `/Cargo.toml`:

[workspace.lints.clippy]
allow_attributes = "warn"

Then every crate in the workspace could be made to respect the lint configuration:

# In `/kernel/Cargo.toml`:

[lints]
workspace = true

However, I could not get such settings to be automatically added to crates outside the workspace (i.e., OSDK and those under kernel/libs/comp-sys). I left such crates as they were:

asterinas/Cargo.toml

Lines 37 to 47 in 56b85cb

exclude = [
"kernel/libs/comp-sys/cargo-component",
"kernel/libs/comp-sys/component",
"kernel/libs/comp-sys/component-macro",
"kernel/libs/comp-sys/controlled",
"osdk",
# The `base` and `test-base` crates are auto-generated by OSDK and ultimately built by Cargo
# during `cargo osdk run` and `cargo osdk test` commands
"target/osdk/base",
"target/osdk/test-base",
]

Footnotes

  1. This is useful for us because it can help us deal with other lints in the future. For example, Rust 2024 is coming, so we may try to globally enable the rust-2024-compatibility lint group soon.

Copy link
Contributor

@tatetian tatetian left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for the contribution!

@tatetian tatetian merged commit 95bbc7f into asterinas:main Feb 8, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants