Skip to content

Allow expanding tidy check for undocumented unsafe code #93045

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/tools/tidy/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,21 @@ pub fn check(path: &Path, bad: &mut bool) {
}
}
}

// Check for comments explaining unsafe code.
//
// Currently we only check `core`, but this list may be expanded in the future.
let check_for_undocumented_unsafe = vec!["core"];
let is_test = || file.components().any(|c| c.as_os_str() == "tests");
// for now we just check libcore
if line.contains("unsafe {") && !line.trim().starts_with("//") && !last_safety_comment {
if file.components().any(|c| c.as_os_str() == "core") && !is_test() {
suppressible_tidy_err!(err, skip_undocumented_unsafe, "undocumented unsafe");
for path in check_for_undocumented_unsafe {
if file.components().any(|c| c.as_os_str() == path) && !is_test() {
suppressible_tidy_err!(
err,
skip_undocumented_unsafe,
"undocumented unsafe"
);
}
}
}
if line.contains("// SAFETY:") {
Expand All @@ -336,6 +346,7 @@ pub fn check(path: &Path, bad: &mut bool) {
} else {
last_safety_comment = false;
}

if (line.starts_with("// Copyright")
|| line.starts_with("# Copyright")
|| line.starts_with("Copyright"))
Expand Down