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

unused_imports redundant import is already defined here points to self #121915

Closed
correabuscar opened this issue Mar 2, 2024 · 4 comments · Fixed by #121958
Closed

unused_imports redundant import is already defined here points to self #121915

correabuscar opened this issue Mar 2, 2024 · 4 comments · Fixed by #121958
Assignees
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-resolve Area: Name resolution C-bug Category: This is a bug. D-confusing Diagnostics: Confusing error or lint that should be reworked. D-papercut Diagnostics: An error or lint that needs small tweaks. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@correabuscar
Copy link

is already defined here doesn't point to the proper place:
playground link
in this output:

   Compiling playground v0.0.1 (/playground)
warning: the item `libc` is imported redundantly
 --> src/main.rs:3:5
  |
3 | use libc;
  |     ^^^^ the item `libc` is already defined here
  |
  = note: `#[warn(unused_imports)]` on by default

warning: `playground` (bin "playground") generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.58s
     Running `target/debug/playground`

for this code:

use std::ffi::{CStr, CString};

use libc;

fn main() {
    let lib_name = CString::new("libEGL.so").unwrap();
    let lib_ptr = unsafe { libc::dlopen(lib_name.as_ptr(), libc::RTLD_NOW) };

    if lib_ptr.is_null() {
        let error_msg = unsafe { CStr::from_ptr(libc::dlerror()) }.to_str().unwrap();
        println!("Error loading library: {}", error_msg);
        return;
    }

    // Access functions from the library
    // ...

    unsafe { libc::dlclose(lib_ptr) };
}

Meta

rustc --version --verbose:

rustc 1.78.0-nightly (ef324565d 2024-02-27)
binary: rustc
commit-hash: ef324565d071c6d7e2477a195648549e33d6a465
commit-date: 2024-02-27
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0


initially mentioned it here, on the pull request: #117772 (comment)

@correabuscar correabuscar added the C-bug Category: This is a bug. label Mar 2, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 2, 2024
@jieyouxu jieyouxu added A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 2, 2024
@ehuss
Copy link
Contributor

ehuss commented Mar 2, 2024

I believe it is pointing at the correct place (the use libc; is redundant and should be removed). What I think is missing is an explanation of why the redundancy exists (it is because libc already exists in the extern prelude).

@correabuscar
Copy link
Author

Normally you see something like:

   Compiling playground v0.0.1 (/playground)
warning: the item `TryFrom` is imported redundantly
   --> src/main.rs:3:5
    |
3   | use std::convert::TryFrom;//~ WARNING the item `TryFrom` is imported redundantly
    |     ^^^^^^^^^^^^^^^^^^^^^
    |
   ::: /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:129:13
    |
129 |     pub use core::prelude::rust_2021::*;
    |             ------------------------ the item `TryFrom` is already defined here
    |
note: the lint level is defined here
   --> src/main.rs:1:9

Here it says where is already defined here is, correctly.
playground link

#![warn(unused_imports)]

use std::convert::TryFrom;//~ WARNING the item `TryFrom` is imported redundantly
use std::convert::TryInto;//~ WARNING the item `TryInto` is imported redundantly

fn main() {
    let _e: Result<i32, _> = 8u8.try_into();
    let _f: Result<i32, _> = i32::try_from(8u8);
}

@fmease
Copy link
Member

fmease commented Mar 3, 2024

I believe it is pointing at the correct place (the use libc; is redundant and should be removed). What I think is missing is an explanation of why the redundancy exists (it is because libc already exists in the extern prelude).

Yes, exactly! We just need to adjust the contents of the label in this situation.

@fmease fmease added A-resolve Area: Name resolution A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. and removed A-diagnostics Area: Messages for errors, warnings, and lints labels Mar 3, 2024
@fmease
Copy link
Member

fmease commented Mar 3, 2024

Minimized:

// --- dep.rs ---    rustc dep.rs --crate-type=lib
pub fn item() {}
// --- usr.rs ---    rustc usr.rs --extern=dep -L. --edition=2021
fn main() {
    use dep;
    dep::item();
}
warning: the item `dep` is imported redundantly
 --> usr.rs:2:9
  |
2 |     use dep;
  |         ^^^ the item `dep` is already defined here
  |
  = note: `#[warn(unused_imports)]` on by default

warning: 1 warning emitted

@fmease fmease added S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue D-papercut Diagnostics: An error or lint that needs small tweaks. labels Mar 3, 2024
@chenyukang chenyukang self-assigned this Mar 4, 2024
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Mar 4, 2024
…t, r=pnkfelix

Fix redundant import errors for preload extern crate

Fixes rust-lang#121915
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 6, 2024
…t, r=petrochenkov

Fix redundant import errors for preload extern crate

Fixes rust-lang#121915
@bors bors closed this as completed in 550b8a2 Mar 7, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 7, 2024
Rollup merge of rust-lang#121958 - chenyukang:yukang-fix-121915-import, r=petrochenkov

Fix redundant import errors for preload extern crate

Fixes rust-lang#121915
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. A-resolve Area: Name resolution C-bug Category: This is a bug. D-confusing Diagnostics: Confusing error or lint that should be reworked. D-papercut Diagnostics: An error or lint that needs small tweaks. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue 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.

6 participants