From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7905) id CD233383FB89; Tue, 31 Jan 2023 13:14:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CD233383FB89 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675170881; bh=2BuGDLwqnfUdmyMdSawICuv8dBRldUuWtGk90HlB89o=; h=From:To:Subject:Date:From; b=cD27LREGjB+DBxWoKJZp1gt5v+BpoAfQqJgT48lZu7iEgwDqPkd/G1ob9i2vTs+xX e+X2PazQ9Q5117KsBU0vC7ASgrGxzvZnFic5LHHbn+L1DM0KSQLJ7zm+0sXqYxerLR pclD/vmko9JLPKBI4mhMgfHrx4wmDPfYTxxTObdk= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Arthur Cohen To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-5539] gccrs: lint: Do not emit unused warnings for public items X-Act-Checkin: gcc X-Git-Author: Arthur Cohen X-Git-Refname: refs/heads/master X-Git-Oldrev: 3a3a352091b74916c5ad3177e0df9d624d746cac X-Git-Newrev: 938facc5e93a9ff31fe39ff00684e591c371fd37 Message-Id: <20230131131441.CD233383FB89@sourceware.org> Date: Tue, 31 Jan 2023 13:14:41 +0000 (GMT) List-Id: https://gcc.gnu.org/g:938facc5e93a9ff31fe39ff00684e591c371fd37 commit r13-5539-g938facc5e93a9ff31fe39ff00684e591c371fd37 Author: Arthur Cohen Date: Fri Aug 26 14:09:24 2022 +0200 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. Diff: --- gcc/rust/checks/lints/rust-lint-scan-deadcode.h | 9 +++++---- gcc/testsuite/rust/compile/issue-1031.rs | 2 -- gcc/testsuite/rust/compile/issue-1289.rs | 2 -- gcc/testsuite/rust/compile/privacy7.rs | 9 +++++++++ gcc/testsuite/rust/compile/test_mod.rs | 1 - gcc/testsuite/rust/compile/torture/raw_identifiers.rs | 4 ++-- gcc/testsuite/rust/compile/torture/raw_identifiers_keywords.rs | 4 ++-- 7 files changed, 18 insertions(+), 13 deletions(-) diff --git a/gcc/rust/checks/lints/rust-lint-scan-deadcode.h b/gcc/rust/checks/lints/rust-lint-scan-deadcode.h index 3289b7d759b..63a308949c3 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%>", diff --git a/gcc/testsuite/rust/compile/issue-1031.rs b/gcc/testsuite/rust/compile/issue-1031.rs index 939f0f981e0..5ba8f7a267b 100644 --- a/gcc/testsuite/rust/compile/issue-1031.rs +++ b/gcc/testsuite/rust/compile/issue-1031.rs @@ -6,12 +6,10 @@ extern "rust-intrinsic" { #[lang = "const_ptr"] impl *const T { pub const unsafe fn offset(self, count: isize) -> *const T { - // { dg-warning "associated function is never used" "" { target *-*-* } .-1 } unsafe { offset(self, count) } } pub const unsafe fn add(self, count: usize) -> Self { - // { dg-warning "associated function is never used" "" { target *-*-* } .-1 } unsafe { self.offset(count as isize) } } } diff --git a/gcc/testsuite/rust/compile/issue-1289.rs b/gcc/testsuite/rust/compile/issue-1289.rs index 343aaab078b..eb41af0a75b 100644 --- a/gcc/testsuite/rust/compile/issue-1289.rs +++ b/gcc/testsuite/rust/compile/issue-1289.rs @@ -23,12 +23,10 @@ impl *mut T { #[lang = "const_ptr"] impl *const T { pub const unsafe fn offset(self, count: isize) -> *mut T { - // { dg-warning "associated function is never used" "" { target *-*-* } .-1 } unsafe { intrinsics::offset(self, count) as *mut T } } pub const unsafe fn add(self, count: usize) -> Self { - // { dg-warning "associated function is never used" "" { target *-*-* } .-1 } unsafe { self.offset(count as isize) } } } diff --git a/gcc/testsuite/rust/compile/privacy7.rs b/gcc/testsuite/rust/compile/privacy7.rs new file mode 100644 index 00000000000..00fa0ef8f11 --- /dev/null +++ b/gcc/testsuite/rust/compile/privacy7.rs @@ -0,0 +1,9 @@ +pub struct Foo(i8); +struct Bar(pub i8); // { dg-warning "struct is never constructed: .Bar." } +pub struct Baz { + a: i32, // { dg-warning "field is never read: .a." } + pub b: i32, +} + +pub fn foo() {} +fn bar() {} // { dg-warning "function is never used: .bar." } diff --git a/gcc/testsuite/rust/compile/test_mod.rs b/gcc/testsuite/rust/compile/test_mod.rs index 4b3c000236b..6e9c19b3fa4 100644 --- a/gcc/testsuite/rust/compile/test_mod.rs +++ b/gcc/testsuite/rust/compile/test_mod.rs @@ -3,4 +3,3 @@ //! foo bar baz cake pizza carbs pub struct Test(pub i32); -// { dg-warning "struct is never constructed" "" { target *-*-* } .-1 } diff --git a/gcc/testsuite/rust/compile/torture/raw_identifiers.rs b/gcc/testsuite/rust/compile/torture/raw_identifiers.rs index 8746f337048..7e6cd916244 100644 --- a/gcc/testsuite/rust/compile/torture/raw_identifiers.rs +++ b/gcc/testsuite/rust/compile/torture/raw_identifiers.rs @@ -1,3 +1,3 @@ -pub fn square(num: i32) -> i32 { /* { dg-warning "used" } */ +pub fn square(num: i32) -> i32 { r#num * num -} \ No newline at end of file +} diff --git a/gcc/testsuite/rust/compile/torture/raw_identifiers_keywords.rs b/gcc/testsuite/rust/compile/torture/raw_identifiers_keywords.rs index c9aa3cf4938..3a15223631f 100644 --- a/gcc/testsuite/rust/compile/torture/raw_identifiers_keywords.rs +++ b/gcc/testsuite/rust/compile/torture/raw_identifiers_keywords.rs @@ -1,3 +1,3 @@ -pub fn plus(r#break: i32, r#unsafe: i32) -> i32 { /* { dg-warning "used" } */ +pub fn plus(r#break: i32, r#unsafe: i32) -> i32 { r#break + r#unsafe -} \ No newline at end of file +}