Repository: rust
Issue: `tests/ui/allocator/no_std-*`, `tests/ui/extern-flag/*force-extern`, `tests/ui/meta/no_std-*` fail when bootstrapping stage 2
Labels: A-testsuite,T-compiler,T-bootstrap,C-bug

When bootstrapping rust 1.76.0 for distribution (build and test stage 2), several tests fail with output similar to #108767:

```
failures:
    [ui] tests/ui/allocator/no_std-alloc-error-handler-custom.rs
    [ui] tests/ui/allocator/no_std-alloc-error-handler-default.rs
    [ui] tests/ui/extern-flag/force-extern.rs
    [ui] tests/ui/extern-flag/no-force-extern.rs
    [ui] tests/ui/extern-flag/redundant-force-extern.rs
    [ui] tests/ui/meta/no_std-extern-libc.rs
```

Test invocation:

```sh
export RUST_BACKTRACE=1
python ./x.py test -j "$(nproc)" --no-doc --no-fail-fast \
  --stage 2 \
  --target 'x86_64-unknown-linux-gnu' \
  tests/codegen \
  tests/codegen-units \
  tests/incremental \
  tests/mir-opt \
  tests/pretty \
  tests/run-make \
  tests/run-make-fulldeps \
  tests/ui \
  tests/ui-fulldeps \
  --skip tests/run-make/long-linker-command-lines \
  --skip tests/ui/sanitize \
  --skip tests/ui/issues/issue-21763.rs \
```

<details>
<summary>config.toml</summary>

```toml
profile = "user"
change-id = 118703

[llvm]
link-shared = true

[build]
# When compiling from source, you almost always want a full stage 2 build,
# which has all the latest optimizations from nightly.
build-stage = 2
test-stage = 2
doc-stage = 2
target = [
  "x86_64-unknown-linux-gnu",
  "i686-unknown-linux-gnu",
  "x86_64-unknown-linux-musl",
  "wasm32-unknown-unknown",
  "wasm32-wasi",
]
cargo = "/usr/bin/cargo"
rustc = "/usr/bin/rustc"
rustfmt = "/usr/bin/rustfmt"
locked-deps = true
vendor = true
# When compiling from source, you usually want all tools.
# extended = true
tools = [
  "cargo",
  "clippy",
  "rustdoc",
  "rustfmt",
  "rust-analyzer-proc-macro-srv",
  "analysis",
  "src",
  "rust-demangler",
]
sanitizers = true
profiler = true

# Generating docs fails with the wasm32-* targets
docs = false

[install]
prefix = "/usr"

[rust]
debuginfo-level-std = 2
channel = "stable"
description = "Arch Linux rust 1:1.76.0-2"
rpath = false
backtrace-on-ice = true
jemalloc = true

#optimize = 3
#lto = "fat"
use-lld = true

# Causes "error: --remap-path-prefix must contain '=' between FROM and TO"
# even after creating the missing ~/.cargo/registry/src dir.
# https://github.com/rust-lang/rust/issues/117885
remap-debuginfo = false

# LLVM crashes when passing an object through ThinLTO twice.  This is triggered
# when using rust code in cross-language LTO if libstd was built using ThinLTO.
# http://blog.llvm.org/2019/09/closing-gap-cross-language-lto-between.html
# https://github.com/rust-lang/rust/issues/54872
#codegen-units = 1
#codegen-units-std = 1

# musl target produces warnings
deny-warnings = false

[dist]
compression-formats = ["gz"]

[target.x86_64-unknown-linux-gnu]
cc = "/usr/bin/gcc"
cxx = "/usr/bin/g++"
ar = "/usr/bin/gcc-ar"
ranlib = "/usr/bin/gcc-ranlib"
llvm-config = "/usr/bin/llvm-config"

[target.i686-unknown-linux-gnu]
cc = "/usr/bin/gcc"
cxx = "/usr/bin/g++"
ar = "/usr/bin/gcc-ar"
ranlib = "/usr/bin/gcc-ranlib"

[target.x86_64-unknown-linux-musl]
sanitizers = false
musl-root = "/usr/lib/musl"

[target.wasm32-unknown-unknown]
sanitizers = false
profiler = false

[target.wasm32-wasi]
sanitizers = false
profiler = false
wasi-root = "/usr/share/wasi-sysroot"
```
</details>

<details>
<summary>Output of the failing tests</summary>

```
---- [ui] tests/ui/allocator/no_std-alloc-error-handler-custom.rs stdout ----

error: test compilation failed although it shouldn't!
status: exit status: 1
command: RUSTC_ICE="0" "/build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/build/rust/src/rustc-1.76.0-src/tests/ui/allocator/no_std-alloc-error-handler-custom.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/build/.cargo" "--sysroot" "/build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "-O" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "-C" "prefer-dynamic" "-o" "/build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/test/ui/allocator/no_std-alloc-error-handler-custom/a" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-Clink-arg=-fuse-ld=lld" "-Clink-arg=-Wl,--threads=1" "-L" "/build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/test/ui/allocator/no_std-alloc-error-handler-custom/auxiliary" "-C" "panic=abort"
stdout: none
--- stderr -------------------------------
error[E0464]: multiple candidates for `rmeta` dependency `libc` found
  --> /build/rust/src/rustc-1.76.0-src/tests/ui/allocator/no_std-alloc-error-handler-custom.rs:16:1
   |
LL | extern crate libc;
   | ^^^^^^^^^^^^^^^^^^
   |
   = note: candidate #1: /build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-0f4b0a7025d9b441.rmeta
   = note: candidate #2: /build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-cb41d8ba0394dce7.rlib

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0464`.
------------------------------------------


---- [ui] tests/ui/allocator/no_std-alloc-error-handler-default.rs stdout ----

error: test compilation failed although it shouldn't!
status: exit status: 1
command: RUSTC_ICE="0" "/build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/build/rust/src/rustc-1.76.0-src/tests/ui/allocator/no_std-alloc-error-handler-default.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/build/.cargo" "--sysroot" "/build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "-O" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "-C" "prefer-dynamic" "-o" "/build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/test/ui/allocator/no_std-alloc-error-handler-default/a" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-Clink-arg=-fuse-ld=lld" "-Clink-arg=-Wl,--threads=1" "-L" "/build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/test/ui/allocator/no_std-alloc-error-handler-default/auxiliary" "-C" "panic=abort"
stdout: none
--- stderr -------------------------------
error[E0464]: multiple candidates for `rmeta` dependency `libc` found
  --> /build/rust/src/rustc-1.76.0-src/tests/ui/allocator/no_std-alloc-error-handler-default.rs:15:1
   |
LL | extern crate libc;
   | ^^^^^^^^^^^^^^^^^^
   |
   = note: candidate #1: /build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-0f4b0a7025d9b441.rmeta
   = note: candidate #2: /build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-cb41d8ba0394dce7.rlib

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0464`.
------------------------------------------


---- [ui] tests/ui/extern-flag/force-extern.rs stdout ----

error: auxiliary build of "/build/rust/src/rustc-1.76.0-src/tests/ui/extern-flag/auxiliary/panic_handler.rs" failed to compile:
status: exit status: 1
command: RUSTC_ICE="0" "/build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/build/rust/src/rustc-1.76.0-src/tests/ui/extern-flag/auxiliary/panic_handler.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/build/.cargo" "--sysroot" "/build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "-C" "prefer-dynamic" "--out-dir" "/build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/test/ui/extern-flag/force-extern/auxiliary" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-Clink-arg=-fuse-ld=lld" "-Clink-arg=-Wl,--threads=1" "--crate-type" "dylib" "-L" "/build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/test/ui/extern-flag/force-extern/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0464]: multiple candidates for `rmeta` dependency `libc` found
  --> /build/rust/src/rustc-1.76.0-src/tests/ui/extern-flag/auxiliary/panic_handler.rs:9:1
   |
LL | extern crate libc;
   | ^^^^^^^^^^^^^^^^^^
   |
   = note: candidate #1: /build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-0f4b0a7025d9b441.rmeta
   = note: candidate #2: /build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-cb41d8ba0394dce7.rlib

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0464`.
------------------------------------------


---- [ui] tests/ui/extern-flag/no-force-extern.rs stdout ----

error: auxiliary build of "/build/rust/src/rustc-1.76.0-src/tests/ui/extern-flag/auxiliary/panic_handler.rs" failed to compile:
status: exit status: 1
command: RUSTC_ICE="0" "/build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/build/rust/src/rustc-1.76.0-src/tests/ui/extern-flag/auxiliary/panic_handler.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/build/.cargo" "--sysroot" "/build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "-C" "prefer-dynamic" "--out-dir" "/build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/test/ui/extern-flag/no-force-extern/auxiliary" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-Clink-arg=-fuse-ld=lld" "-Clink-arg=-Wl,--threads=1" "--crate-type" "dylib" "-L" "/build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/test/ui/extern-flag/no-force-extern/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0464]: multiple candidates for `rmeta` dependency `libc` found
  --> /build/rust/src/rustc-1.76.0-src/tests/ui/extern-flag/auxiliary/panic_handler.rs:9:1
   |
LL | extern crate libc;
   | ^^^^^^^^^^^^^^^^^^
   |
   = note: candidate #1: /build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-0f4b0a7025d9b441.rmeta
   = note: candidate #2: /build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-cb41d8ba0394dce7.rlib

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0464`.
------------------------------------------


---- [ui] tests/ui/extern-flag/redundant-force-extern.rs stdout ----

error: auxiliary build of "/build/rust/src/rustc-1.76.0-src/tests/ui/extern-flag/auxiliary/panic_handler.rs" failed to compile:
status: exit status: 1
command: RUSTC_ICE="0" "/build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/build/rust/src/rustc-1.76.0-src/tests/ui/extern-flag/auxiliary/panic_handler.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/build/.cargo" "--sysroot" "/build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "-C" "prefer-dynamic" "--out-dir" "/build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/test/ui/extern-flag/redundant-force-extern/auxiliary" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-Clink-arg=-fuse-ld=lld" "-Clink-arg=-Wl,--threads=1" "--crate-type" "dylib" "-L" "/build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/test/ui/extern-flag/redundant-force-extern/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0464]: multiple candidates for `rmeta` dependency `libc` found
  --> /build/rust/src/rustc-1.76.0-src/tests/ui/extern-flag/auxiliary/panic_handler.rs:9:1
   |
LL | extern crate libc;
   | ^^^^^^^^^^^^^^^^^^
   |
   = note: candidate #1: /build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-0f4b0a7025d9b441.rmeta
   = note: candidate #2: /build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-cb41d8ba0394dce7.rlib

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0464`.
------------------------------------------


---- [ui] tests/ui/meta/no_std-extern-libc.rs stdout ----

error: test compilation failed although it shouldn't!
status: exit status: 1
command: RUSTC_ICE="0" "/build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/build/rust/src/rustc-1.76.0-src/tests/ui/meta/no_std-extern-libc.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/build/.cargo" "--sysroot" "/build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/test/ui/meta/no_std-extern-libc" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-Clink-arg=-fuse-ld=lld" "-Clink-arg=-Wl,--threads=1" "-L" "/build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/test/ui/meta/no_std-extern-libc/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0464]: multiple candidates for `rmeta` dependency `libc` found
  --> /build/rust/src/rustc-1.76.0-src/tests/ui/meta/no_std-extern-libc.rs:7:1
   |
LL | extern crate libc;
   | ^^^^^^^^^^^^^^^^^^
   |
   = note: candidate #1: /build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-0f4b0a7025d9b441.rmeta
   = note: candidate #2: /build/rust/src/rustc-1.76.0-src/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-cb41d8ba0394dce7.rlib

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0464`.
------------------------------------------
```

<!--
Thank you for filing a bug report! 🐛 Please provide a short summary of the bug,
along with any information you feel relevant to replicating the bug.
-->

I tried this code:

```rust
<code>
```

I expected to see this happen: *explanation*

Instead, this happened: *explanation*

### Meta
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`rustc --version --verbose`:
```
<version>
```



<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary>Backtrace</summary>
<p>

```
<backtrace>
```

</p>
</details>