diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-08-26 14:09:24 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2023-01-31 14:16:49 +0100 |
commit | 938facc5e93a9ff31fe39ff00684e591c371fd37 (patch) | |
tree | 932824796545492d7157a9551d950b984e26d3a5 /gcc/rust | |
parent | 3a3a352091b74916c5ad3177e0df9d624d746cac (diff) | |
download | gcc-938facc5e93a9ff31fe39ff00684e591c371fd37.zip gcc-938facc5e93a9ff31fe39ff00684e591c371fd37.tar.gz gcc-938facc5e93a9ff31fe39ff00684e591c371fd37.tar.bz2 |
gccrs: lint: Do not emit unused warnings for public items
gcc/rust/ChangeLog:
* checks/lints/rust-lint-scan-deadcode.h: Do not report public items
as dead code.
gcc/testsuite/ChangeLog:
* rust/compile/issue-1031.rs: Remove extraneous dead code warnings.
* rust/compile/issue-1289.rs: Likewise.
* rust/compile/test_mod.rs: Likewise.
* rust/compile/torture/raw_identifiers.rs: Likewise.
* rust/compile/torture/raw_identifiers_keywords.rs: Likewise.
* rust/compile/privacy7.rs: New test.
Diffstat (limited to 'gcc/rust')
-rw-r--r-- | gcc/rust/checks/lints/rust-lint-scan-deadcode.h | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/gcc/rust/checks/lints/rust-lint-scan-deadcode.h b/gcc/rust/checks/lints/rust-lint-scan-deadcode.h index 3289b7d..63a3089 100644 --- a/gcc/rust/checks/lints/rust-lint-scan-deadcode.h +++ b/gcc/rust/checks/lints/rust-lint-scan-deadcode.h @@ -53,7 +53,7 @@ public: void visit (HIR::Function &function) override { HirId hirId = function.get_mappings ().get_hirid (); - if (should_warn (hirId)) + if (should_warn (hirId) && !function.get_visibility ().is_public ()) { if (mappings->is_impl_item (hirId)) { @@ -78,7 +78,7 @@ public: void visit (HIR::StructStruct &stct) override { HirId hirId = stct.get_mappings ().get_hirid (); - if (should_warn (hirId)) + if (should_warn (hirId) && !stct.get_visibility ().is_public ()) { bool name_starts_underscore = stct.get_identifier ().at (0) == '_'; if (!name_starts_underscore) @@ -92,7 +92,8 @@ public: for (auto &field : stct.get_fields ()) { HirId field_hir_id = field.get_mappings ().get_hirid (); - if (should_warn (field_hir_id)) + if (should_warn (field_hir_id) + && !field.get_visibility ().is_public ()) { rust_warning_at (field.get_locus (), 0, "field is never read: %<%s%>", @@ -106,7 +107,7 @@ public: { // only warn tuple struct unconstructed, and ignoring unused field HirId hirId = stct.get_mappings ().get_hirid (); - if (should_warn (hirId)) + if (should_warn (hirId) && !stct.get_visibility ().is_public ()) { rust_warning_at (stct.get_locus (), 0, "struct is never constructed: %<%s%>", |