Skip to content

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

Merged
tatetian merged 6 commits intoasterinas:mainfrom
lrh2000:dead-code-lib
Feb 8, 2025
Merged

Replace #[allow(lint)] with #[expect(lint)]#1820
tatetian merged 6 commits intoasterinas:mainfrom
lrh2000:dead-code-lib

Conversation

@lrh2000
Copy link
Copy Markdown
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
Copy Markdown
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
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