Skip to content

#[inline(always)] and -Zhint-mostly-unused play not well with imported mainΒ #144052

@usamoi

Description

@usamoi

I tried this code:

foo/main.rs:

use bar::main

bar/lib.rs:

pub fn main() {
    println!("Hello, world!");
}
RUSTFLAGS="-Zhint-mostly-unused" cargo +nighly run -p foo

I expected to see this happen: it compiles

Instead, this happened: it emits many linking errors

If #[inline(always)] is used, an error will occur even if this flag is not present.

cargo +stable run -p foo
linking errors

error: linking with `cc` failed: exit status: 1
  |
  = note:  "cc" "-m64" "/tmp/rustcs3Kiu4/symbols.o" "<5 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "/usamoi/playground/easy/target/debug/deps/libbar-b6c95891f9ca7c1d.rlib" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib/{libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,libcfg_if-*,liblibc-*,librustc_std_workspace_core-*,liballoc-*,libcore-*,libcompiler_builtins-*}.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-L" "/tmp/rustcs3Kiu4/raw-dylibs" "-B<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/bin/gcc-ld" "-fuse-ld=lld" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/usamoi/playground/easy/target/debug/deps/foo-8a2f36a70114e06d" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: rust-lld: error: undefined symbol: bar::main::h034083ec22b3bbff
          >>> referenced by 467h5aysby46ky3mqgnyk3nkw
          >>>               /usamoi/playground/easy/target/debug/deps/foo-8a2f36a70114e06d.467h5aysby46ky3mqgnyk3nkw.0gco3m2.rcgu.o:(main)
          collect2: error: ld returned 1 exit status
          

error: could not compile `foo` (bin "foo") due to 1 previous error

Meta

rustc +nightly --version --verbose:

rustc 1.90.0-nightly (5795086bd 2025-07-16)
binary: rustc
commit-hash: 5795086bdfe7ed988aa53a110bd0692c33d8755b
commit-date: 2025-07-16
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.8

rustc +stable --version --verbose:

rustc 1.88.0 (6b00bc388 2025-06-23)
binary: rustc
commit-hash: 6b00bc3880198600130e1cf62b8f8a93494488cc
commit-date: 2025-06-23
host: x86_64-unknown-linux-gnu
release: 1.88.0
LLVM version: 20.1.5

Metadata

Metadata

Assignees

Labels

A-monomorphizationArea: MonomorphizationC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions