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

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

Closed
wangbj opened this issue Apr 17, 2019 · 15 comments · Fixed by #60823
Closed

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

wangbj opened this issue Apr 17, 2019 · 15 comments · Fixed by #60823
Assignees
Labels
A-incr-comp Area: Incremental compilation A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. P-medium Medium priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@wangbj
Copy link

wangbj commented Apr 17, 2019

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)

@jonas-schievink jonas-schievink added A-FFI Area: Foreign function interface (FFI) A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 17, 2019
@MikailBag
Copy link
Contributor

I have same error on today's nightly too

@bjorn3
Copy link
Member

bjorn3 commented Apr 18, 2019

Same for me

@jonas-schievink jonas-schievink added A-incr-comp Area: Incremental compilation and removed A-FFI Area: Foreign function interface (FFI) labels Apr 18, 2019
@alexandermerritt
Copy link
Contributor

alexandermerritt commented Apr 20, 2019

I see the same warning text during a build for crate type “staticlib” using nightly 1.36.0 commit 5d20ff4 2019-04-18

@jonas-schievink jonas-schievink added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. I-nominated E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc labels Apr 24, 2019
@nagisa
Copy link
Member

nagisa commented Apr 25, 2019

I will bisect this and then pass the baton to @oli-obk to fix this.

@nagisa nagisa self-assigned this Apr 25, 2019
@nagisa nagisa added P-medium Medium priority and removed I-nominated labels Apr 25, 2019
@nagisa
Copy link
Member

nagisa commented Apr 27, 2019

Bisection claims 9217fe0, (#59850). cc @Zoxc

@nagisa nagisa assigned Zoxc and oli-obk and unassigned nagisa Apr 27, 2019
@Zoxc
Copy link
Contributor

Zoxc commented Apr 27, 2019

My guess is that no_mangle should be a Whitelisted attribute? It was declared twice before #59850 and the Whitelisted variant got removed.

@Zoxc
Copy link
Contributor

Zoxc commented Apr 27, 2019

Also our scheme to track unused attributes does not work the incremental compilation, which is probably why it only happens with that.

@Zoxc
Copy link
Contributor

Zoxc commented May 6, 2019

cc @petrochenkov

@jonas-schievink jonas-schievink removed the E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc label May 9, 2019
@oli-obk
Copy link
Contributor

oli-obk commented May 14, 2019

A fix is up. I this still nightly only or do we need to backport?

@jonas-schievink
Copy link
Contributor

Seems to be nightly-only still

Centril added a commit to Centril/rust that referenced this issue May 20, 2019
…chaelwoerister

Fix incremental compilation of cdylib emitting spurious unused_attributes lint

fixes rust-lang#60050
@elichai
Copy link
Contributor

elichai commented May 22, 2019

@oli-obk I get this with regular cargo build on a crate type staticlib with nightly 2019-05-20

@oli-obk oli-obk reopened this May 22, 2019
@oli-obk
Copy link
Contributor

oli-obk commented May 22, 2019

@elichai can you try with the latest nightly? This was only closed yesterday, so today's nightly should contain the fix.

@Disasm
Copy link
Contributor

Disasm commented May 22, 2019

My case (#60835) is no longer reproducible on 2019-05-21 nightly.

@phil-opp
Copy link
Contributor

phil-opp commented May 22, 2019

I no longer see the error warning with rustc 1.36.0-nightly (50a0defd5 2019-05-21).

@elichai
Copy link
Contributor

elichai commented May 22, 2019

Yep it seems it's fixed. sorry I missed that it was merged yesterday. thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-incr-comp Area: Incremental compilation A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. P-medium Medium priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. 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.