Skip to content

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

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
glandium opened this issue Jun 12, 2024 · 5 comments · Fixed by #126315
Closed

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

glandium opened this issue Jun 12, 2024 · 5 comments · Fixed by #126315
Assignees
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. L-dead_code Lint: dead_code P-medium Medium priority regression-untriaged Untriaged performance or correctness regression. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@glandium
Copy link
Contributor

glandium commented Jun 12, 2024

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.

@glandium glandium added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Jun 12, 2024
@rustbot rustbot added I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jun 12, 2024
@apiraino
Copy link
Contributor

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-medium

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jun 12, 2024
@apiraino apiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 12, 2024
@apiraino
Copy link
Contributor

bisected to rust-lang-ci@c137109

cc @mu001999

@mu001999
Copy link
Contributor

like #126169

@glandium
Copy link
Contributor Author

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

@mu001999
Copy link
Contributor

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

Oh, I see.

@rustbot claim

@jieyouxu jieyouxu added L-dead_code Lint: dead_code A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jun 12, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 13, 2024
…rochenkov

Add pub struct with allow(dead_code) into worklist

<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

    r​? <reviewer name>
-->

Fixes rust-lang#126289
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 13, 2024
…rochenkov

Add pub struct with allow(dead_code) into worklist

<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

    r​? <reviewer name>
-->

Fixes rust-lang#126289
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 13, 2024
…rochenkov

Add pub struct with allow(dead_code) into worklist

<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

    r​? <reviewer name>
-->

Fixes rust-lang#126289
@bors bors closed this as completed in 977c5fd Jun 14, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jun 14, 2024
Rollup merge of rust-lang#126315 - mu001999-contrib:fix/126289, r=petrochenkov

Add pub struct with allow(dead_code) into worklist

<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

    r​? <reviewer name>
-->

Fixes rust-lang#126289
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. L-dead_code Lint: dead_code P-medium Medium priority regression-untriaged Untriaged performance or correctness regression. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants