Skip to content

Uplift clippy::invalid_utf8_in_unchecked lint#111543

Merged
bors merged 4 commits intorust-lang:masterfrom
Urgau:uplift_invalid_utf8_in_unchecked
May 30, 2023
Merged

Uplift clippy::invalid_utf8_in_unchecked lint#111543
bors merged 4 commits intorust-lang:masterfrom
Urgau:uplift_invalid_utf8_in_unchecked

Conversation

@Urgau
Copy link
Member

@Urgau Urgau commented May 13, 2023

This PR aims at uplifting the clippy::invalid_utf8_in_unchecked lint into two lints.

invalid_from_utf8_unchecked

(deny-by-default)

The invalid_from_utf8_unchecked lint checks for calls to std::str::from_utf8_unchecked and std::str::from_utf8_unchecked_mut with an invalid UTF-8 literal.

Example

unsafe {
    std::str::from_utf8_unchecked(b"cl\x82ippy");
}

Explanation

Creating such a str would result in undefined behavior as per documentation for std::str::from_utf8_unchecked and std::str::from_utf8_unchecked_mut.

invalid_from_utf8

(warn-by-default)

The invalid_from_utf8 lint checks for calls to std::str::from_utf8 and std::str::from_utf8_mut with an invalid UTF-8 literal.

Example

std::str::from_utf8(b"ru\x82st");

Explanation

Trying to create such a str would always return an error as per documentation for std::str::from_utf8 and std::str::from_utf8_mut.


Mostly followed the instructions for uplifting a clippy lint described here: #99696 (review)

@rustbot label: +I-lang-nominated
r? compiler


For Clippy:

changelog: Moves: Uplifted clippy::invalid_utf8_in_unchecked into rustc

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-lang Relevant to the language team

Projects

None yet

Development

Successfully merging this pull request may close these issues.