Skip to content

rustc incorrectly warn #[no_mangle] is not used when doing incremental build #60050

Closed
@wangbj

Description

@wangbj

Steps to reproduce:

  1. make an new crate, set crate type to cdylib
  2. put a simple function in src/lib.rs:
#[no_mangle]
pub extern "C" fn rust_no_mangle() -> i32{
    42
}
  1. build with cargo build --verbose
  2. copy the rustc command line used from above step, and run it as-is

example:

$ cargo build --verbose
   Compiling nm v0.1.0 (/tmp/nm)
     Running `rustc --edition=2018 --crate-name nm src/lib.rs --color always --crate-type cdylib --emit=dep-info,link -C debuginfo=2 -C metadata=38c165a3ed3ed429 --out-dir /tmp/nm/target/debug/deps -C incremental=/tmp/nm/target/debug/incremental -L dependency=/tmp/nm/target/debug/deps`
    Finished dev [unoptimized + debuginfo] target(s) in 0.22s
$ rustc --edition=2018 --crate-name nm src/lib.rs --color always --crate-type cdylib --emit=dep-info,link -C debuginfo=2 -C metadata=38c165a3ed3ed429 --out-dir /tmp/nm/target/debug/deps -C incremental=/tmp/nm/target/debug/incremental -L dependency=/tmp/nm/target/debug/deps
warning: unused attribute
 --> src/lib.rs:1:1
  |
1 | #[no_mangle]
  | ^^^^^^^^^^^^
  |
  = note: #[warn(unused_attributes)] on by default

As you can see, the first time cargo build in step 3) has no warnings, however, step 4) cause rustc complains #[no_mangle] is unused, which isn't true.

Step 4) can be replaced by:

  • modify src/lib.rs, so that it cause rebuild
  • run cargo build again

rustc 1.35.0-nightly (70f1309 2019-04-16)

Metadata

Metadata

Assignees

Labels

A-incr-compArea: Incremental compilationA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions