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

Allow #[expect] and #[allow] within function bodies for missing_panics_doc #14407

Merged
merged 4 commits into from
Mar 31, 2025

Conversation

Alexendoo
Copy link
Member

Implements #11436 (comment)

[...] I'd really like to be able to (reusing some above examples),

/// Do something
pub fn string_from_byte_stream() -> String {
    let bytes = get_valid_utf8();
    #[expect(clippy::missing_panics_doc_ok, reason="caller can't do anything about this")]
    String::from_utf8(bytes).expect("`get_valid_utf8()` always returns valid UTF-8")
}

Also fixes an issue where if the first panic is in a const context disables the lint for the rest of the function

The first commit is just moving code around

changelog: [missing_panics_doc]: #[allow] and #[expect] can now be used within the function body to ignore individual panics

@rustbot
Copy link
Collaborator

rustbot commented Mar 14, 2025

r? @Jarcho

rustbot has assigned @Jarcho.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Mar 14, 2025
@Alexendoo Alexendoo force-pushed the missing-panics-doc-node branch 2 times, most recently from e1c74cc to bb05ad9 Compare March 14, 2025 16:26
@duelafn
Copy link

duelafn commented Mar 14, 2025

Fantastic! You're my hero! -- Thank you!

@Jarcho
Copy link
Contributor

Jarcho commented Mar 22, 2025

for_each_expr could be used instead of writing a visitor since it already ignores anon constants. Should probably also search until the end to fulfill all expectations. e.g.

fn foo(x: Option<u32>, y: Option<u32>) {
    let x = x.unwrap();
    #[expect(clippy::missing_panics_doc)]
    let y = y.unwrap();
}

@Alexendoo Alexendoo force-pushed the missing-panics-doc-node branch from bb05ad9 to e6cf687 Compare March 22, 2025 16:25
Copy link
Contributor

@Jarcho Jarcho left a comment

Choose a reason for hiding this comment

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

Thank you.

@Jarcho Jarcho enabled auto-merge March 31, 2025 10:21
@Alexendoo Alexendoo force-pushed the missing-panics-doc-node branch from e6cf687 to f894a81 Compare March 31, 2025 12:52
@Jarcho Jarcho added this pull request to the merge queue Mar 31, 2025
Merged via the queue into rust-lang:master with commit b96fecf Mar 31, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants