gccrs: add unused unsafe lint#4630
Open
lucasly-ba wants to merge 1 commit into
Open
Conversation
P-E-P
reviewed
Jul 6, 2026
9ed4d9b to
9e8afb6
Compare
Warn about an unsafe block that does not contain any operation requiring an unsafe context. The unsafe checker now records which unsafe blocks are actually used by an unsafe operation, and reports the rest. The warning is gated behind -frust-unused-check-2.0. gcc/rust/ChangeLog: * checks/errors/rust-unsafe-checker.cc (check_static_mut) (check_extern_static, check_unsafe_call, check_extern_call) (check_target_attr): Return whether the operation requires unsafe and only error outside of an unsafe context. (UnsafeChecker::mark_unsafe_used): New. (UnsafeChecker::check_use_of_static) (UnsafeChecker::check_function_call) (UnsafeChecker::check_function_attr): Mark the unsafe block as used. (UnsafeChecker::visit): Mark used and warn on unnecessary unsafe block. * checks/errors/rust-unsafe-checker.h (UnsafeChecker): Add mark_unsafe_used and used_unsafe_blocks. * rust-lang.cc (grs_langhook_init_options_struct): Enable warn_unused. gcc/testsuite/ChangeLog: * rust/compile/unused-unsafe_0.rs: New test. Signed-off-by: Lucas Ly Ba <lucas.ly-ba@outlook.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This patch adds the unused unsafe lint, which warns about an
unsafeblock that does not contain any operation requiring an unsafe context. The unsafe checker now records which unsafe blocks are actually used and reports the rest.gcc/testsuite/ChangeLog: