Skip to content

dead_code lint wrongly warns about "never used" functions that are, in fact used #126289

Closed

Description

@glandium

Code

mod ffi {
    use super::*;

    extern "C" {
        pub fn DomPromise_AddRef(promise: *const Promise);
        pub fn DomPromise_Release(promise: *const Promise);
    }
}

#[repr(C)]
#[allow(unused)]
pub struct Promise {
    private: [u8; 0],
    __nosync: ::std::marker::PhantomData<::std::rc::Rc<u8>>,
}

pub unsafe trait RefCounted {
    unsafe fn addref(&self);
    unsafe fn release(&self);
}

unsafe impl RefCounted for Promise {
    unsafe fn addref(&self) {
        ffi::DomPromise_AddRef(self)
    }
    unsafe fn release(&self) {
        ffi::DomPromise_Release(self)
    }
}

Output with 1.79.0:

nothing

Output with 1.80.0:

warning: function `DomPromise_AddRef` is never used
 --> src/lib.rs:5:16
  |
5 |         pub fn DomPromise_AddRef(promise: *const Promise);
  |                ^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: function `DomPromise_Release` is never used
 --> src/lib.rs:6:16
  |
6 |         pub fn DomPromise_Release(promise: *const Promise);
  |                ^^^^^^^^^^^^^^^^^^

warning: `playground` (lib) generated 2 warnings

The original code didn't have the #[allow(unused)], which was added because of the "never constructed" dead_code lint, which I guess would be #126169. Adding a constructor does make the function never used errors go away, so it seems #[allow(unused)] doesn't have enough power.

Activity

  1. added
    C-bugCategory: This is a bug.
    regression-untriagedUntriaged performance or correctness regression.
    on Jun 12, 2024
  2. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jun 12, 2024
  3. apiraino commented on Jun 12, 2024

    @apiraino
    Contributor

    WG-prioritization assigning priority (Zulip discussion).

    @rustbot label -I-prioritize +P-medium

  4. added and removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Jun 12, 2024
  5. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Jun 12, 2024
  6. apiraino commented on Jun 12, 2024

    @apiraino
    Contributor
  7. mu001999 commented on Jun 12, 2024

    @mu001999
    Member

    like #126169

  8. glandium commented on Jun 12, 2024

    @glandium
    ContributorAuthor

    #126169 is about the struct itself, and there's a allow(unused). This is about the side effects.

  9. mu001999 commented on Jun 12, 2024

    @mu001999
    Member

    #126169 is about the struct itself, and there's a allow(unused). This is about the side effects.

    Oh, I see.

    @rustbot claim

  10. added
    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
    D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jun 12, 2024
  11. added 4 commits that reference this issue on Jun 13, 2024
    c87e06d
    d583c6d
    977c5fd
    7ebbf16
  12. added a commit that references this issue on Jun 14, 2024
    1d675b2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.L-dead_codeLint: dead_codeP-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-untriagedUntriaged performance or correctness regression.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions