Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

spurious "unused extern crate" #56098

Closed
RalfJung opened this issue Nov 20, 2018 · 9 comments · Fixed by #116191
Closed

spurious "unused extern crate" #56098

RalfJung opened this issue Nov 20, 2018 · 9 comments · Fixed by #116191
Assignees
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@RalfJung
Copy link
Member

RalfJung commented Nov 20, 2018

When compiling this code

#![feature(libc, extern_crate_item_prelude)]

extern crate libc;

use std::ffi::CString;

mod mlibc {
    use libc::{c_char, size_t};
    extern {
        #[link_name = "strlen"]
        pub fn my_strlen(str: *const c_char) -> size_t;
    }
}

fn strlen(str: String) -> usize {
    // C string is terminated with a zero
    let s = CString::new(str).unwrap();
    unsafe {
        mlibc::my_strlen(s.as_ptr()) as usize
    }
}

pub fn main() {
    let len = strlen("Rust".to_string());
    assert_eq!(len, 4);
}

with --edition 2018 -Wunused, I get an incorrect warning:

warning: unused extern crate
  --> tests/run-pass-fullmir/foreign-fn-linkname.rs:15:1
   |
15 | extern crate libc;
   | ^^^^^^^^^^^^^^^^^^ help: remove it
   |
   = note: `-W unused-extern-crates` implied by `-W unused`

The extern crate is used; removing it breaks the program.

@petrochenkov
Copy link
Contributor

Have you checked this on nightly?
This looks like a duplicate of #56038 and it was fixed a couple of days ago.

@RalfJung
Copy link
Member Author

Yes, this is with

rustc 1.32.0-nightly (5aff30734 2018-11-19)

@RalfJung
Copy link
Member Author

Note that I need to add -Wunused. No warning is shown without that flag.

@Mark-Simulacrum
Copy link
Member

I can reproduce on playground with #![warn(unused)] as well: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=f042e0d802065bb01c52be2d274f00b6

@jonas-schievink jonas-schievink added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. labels Jan 27, 2019
@RalfJung
Copy link
Member Author

I cannot reproduce the warning any more, it seems to be fixed.

However, I am not sure if there is a testcase for that.

@kadiwa4
Copy link
Contributor

kadiwa4 commented Jan 28, 2023

@rustbot label: +E-needs-test
Test could be added to tests/ui/foreign/foreign-fn-linkname.rs (which is the example above).
The #[allow(unused_extern_crates)] in std can probably also be removed

@rustbot rustbot added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Jan 28, 2023
@Suyashtnt
Copy link
Contributor

@rustbot claim

@Noratrieb
Copy link
Member

Unassigning because they told me that they don't have the time to do this.

@apekros
Copy link
Contributor

apekros commented Sep 27, 2023

@rustbot claim

apekros added a commit to apekros/rust that referenced this issue Sep 27, 2023
bors added a commit to rust-lang-ci/rust that referenced this issue Sep 28, 2023
…iaskrgr

Rollup of 3 pull requests

Successful merges:

 - rust-lang#116191 (Add regression test for rust-lang#56098)
 - rust-lang#116214 (rustdoc: rename `issue-\d+.rs` tests to have meaningful names)
 - rust-lang#116221 (core/slice: Fix inconsistency between docs for `rotate_left` and `rotate_right`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors closed this as completed in ba0d977 Sep 28, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Sep 28, 2023
Rollup merge of rust-lang#116191 - apekros:issue-56098, r=petrochenkov

Add regression test for rust-lang#56098

Closes rust-lang#56098
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants