From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by sourceware.org (Postfix) with ESMTPS id DF0A3388DEB6 for ; Tue, 31 Jan 2023 13:28:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DF0A3388DEB6 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-lj1-x22b.google.com with SMTP id g14so15900993ljh.10 for ; Tue, 31 Jan 2023 05:28:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=EHzeF5tGrfPa1G+IymfLzF0a2bUWX5wl0QkTvGxGDYc=; b=UkC4CqHeW62SEcTQN40MvZsjZbMGkaQ+KMurvZxSmRpOz4JyS+ny5tqSuHBm6fTLYL gMtan8oKuezYsWekwBmMoO+c3OK/yzrMOc0EtHrD11ZCFN8tjvsIMbeiwBD/XdRT5TSP M7hiHx3vsybeyvc2uupbjMiGzZNkKRb3+MKmvvghcYWzTqwi37A4RxEQGq/ky/m+zq6P N+5nhfRuyNNLkZ03auP7bEcyItPHYkT8A/pf+5Li4Tr+GNVHUWnQLikqYMC4ITgJdQfp 4y2ZAjhGQ5x3ngMTi6Q7zz2Bzq1AXEV0QRsBHtrOXl6L5MwPSy7M6KnxyA6ZDXw5smA4 AdOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EHzeF5tGrfPa1G+IymfLzF0a2bUWX5wl0QkTvGxGDYc=; b=dt5YuAzGAZUZe1J+REgGyz+9owjQOGoXjIbgPYA7yA21/KqQzuMB5Fk+A1yRBGqzIT lGp+kvsiNTNfvEdaqXFOAh09E1FGvVSKCN0mIoK5w7pwRd9G2mVFxTA8z5GTJROXdMiU oCkbafIC3qruK0ZW3UIVfe/Bg1igKwmLEHisTQPDvcXcr4t9VcEbbat/rjJHYXJ4p1yM t4ZrxQ7QzZYWLiEKFPVgE2Nu90Lc1r9s9xFWotbUjy8p10lkb3zXMAB2+nhc2aUWqrG0 BRWHzIwSWLk8WPhCMjJkNyNiDeIhyvx5udYPS0hyRn1K8ntqkcJHTSL5NgHnYK2GlXyh HI9Q== X-Gm-Message-State: AO0yUKVDuXYdQhqqMiwZ9EVfkJbhC0RoKoP/CPykqis3M1wYxX7OVD2V XZPgVgoI2FLRz08t0f6X42p/8MKYIvfQAgWbLQ== X-Google-Smtp-Source: AMrXdXvy0OmpEs2Rc/CwZgpvH42rzid5RDNWNJCnHKDQY/0kYvM4nVoApig7UchHkbOLI13g2gyYoQ== X-Received: by 2002:a05:600c:3c86:b0:3da:2a59:8a4f with SMTP id bg6-20020a05600c3c8600b003da2a598a4fmr54263372wmb.38.1675171244491; Tue, 31 Jan 2023 05:20:44 -0800 (PST) Received: from platypus.lan ([2001:861:5e4c:3bb0:6424:328a:1734:3249]) by smtp.gmail.com with ESMTPSA id iz16-20020a05600c555000b003dd1aa227afsm3365357wmb.31.2023.01.31.05.20.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 05:20:44 -0800 (PST) From: Arthur Cohen To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [COMMITTED] gccrs: lint: Do not emit unused warnings for public items Date: Tue, 31 Jan 2023 14:24:29 +0100 Message-Id: <20230131132429.661457-1-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,LIKELY_SPAM_BODY,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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. Tested on x86_64-pc-linux-gnu, committed on master. --- 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 ++-- .../rust/compile/torture/raw_identifiers_keywords.rs | 4 ++-- 7 files changed, 18 insertions(+), 13 deletions(-) create mode 100644 gcc/testsuite/rust/compile/privacy7.rs 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 +} -- 2.39.1