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

"error: linking with cc failed: exit code: 1" regression in release build with const generics #73298

Closed
is8ac opened this issue Jun 13, 2020 · 11 comments · Fixed by #100315
Closed
Labels
A-const-generics Area: const generics (parameters and arguments) A-lazy-normalization Area: lazy normalization (tracking issue: #60471) A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]` requires-nightly This issue requires a nightly compiler in some way.

Comments

@is8ac
Copy link

is8ac commented Jun 13, 2020

Const generics and release mode and Hc128Rng::seed_from_u64 and rustc 1.45.0-nightly (4bd32c9 2020-05-29) or later cause cc linking error.

To avoid the error, do any of:

  • use rustc 1.45.0-nightly (a74d186 2020-05-14) or earlier
  • remove the #![feature(const_generics)]
  • remove the Hc128Rng::seed_from_u64(42) line
  • compile in debug mode

I'm guessing that Hc128Rng::seed_from_u64 is not the only thing that will trigger this, but I have not been able to find any other examples.

Source code

#![feature(const_generics)]
use rand::SeedableRng;
use rand_hc::Hc128Rng;

fn main() {
    let _ = Hc128Rng::seed_from_u64(42);
}

Dependancies

rand = "0.7.3"
rand_hc = "0.2.0"

Error:

error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/home/isaac/go/src/github.com/is8ac/cc_err_demo/target/release/deps/cc_err_demo-949370c0c3e7c5b4.cc_err_demo.5gfojped-cgu.0.rcgu.o" "/home/isaac/go/src/github.com/is8ac/cc_err_demo/target/release/deps/cc_err_demo-949370c0c3e7c5b4.cc_err_demo.5gfojped-cgu.1.rcgu.o" "/home/isaac/go/src/github.com/is8ac/cc_err_demo/target/release/deps/cc_err_demo-949370c0c3e7c5b4.cc_err_demo.5gfojped-cgu.2.rcgu.o" "/home/isaac/go/src/github.com/is8ac/cc_err_demo/target/release/deps/cc_err_demo-949370c0c3e7c5b4.cc_err_demo.5gfojped-cgu.3.rcgu.o" "/home/isaac/go/src/github.com/is8ac/cc_err_demo/target/release/deps/cc_err_demo-949370c0c3e7c5b4.cc_err_demo.5gfojped-cgu.4.rcgu.o" "-o" "/home/isaac/go/src/github.com/is8ac/cc_err_demo/target/release/deps/cc_err_demo-949370c0c3e7c5b4" "/home/isaac/go/src/github.com/is8ac/cc_err_demo/target/release/deps/cc_err_demo-949370c0c3e7c5b4.3rdszsq7ibbmb3tn.rcgu.o" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-Wl,-O1" "-nodefaultlibs" "-L" "/home/isaac/go/src/github.com/is8ac/cc_err_demo/target/release/deps" "-L" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/isaac/go/src/github.com/is8ac/cc_err_demo/target/release/deps/librand_hc-a144c651cd5437de.rlib" "/home/isaac/go/src/github.com/is8ac/cc_err_demo/target/release/deps/librand-bec2ad1f072a8aa0.rlib" "/home/isaac/go/src/github.com/is8ac/cc_err_demo/target/release/deps/librand_chacha-542ae1a91c9af789.rlib" "/home/isaac/go/src/github.com/is8ac/cc_err_demo/target/release/deps/libppv_lite86-6c3f11be887055bf.rlib" "/home/isaac/go/src/github.com/is8ac/cc_err_demo/target/release/deps/librand_core-2e34a4d1d07e0522.rlib" "/home/isaac/go/src/github.com/is8ac/cc_err_demo/target/release/deps/libgetrandom-f56bf65617cc4079.rlib" "/home/isaac/go/src/github.com/is8ac/cc_err_demo/target/release/deps/liblibc-dc8395e94d7842f0.rlib" "/home/isaac/go/src/github.com/is8ac/cc_err_demo/target/release/deps/libcfg_if-bd1d23d91bf28674.rlib" "-Wl,--start-group" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-0df9faf88e74ed3b.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-f9e6a5fb2e2e8cbc.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-05b3477ba39b37d9.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-fd43f1008ae3de7b.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace-c69fd8a874cc6882.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace_sys-4f9ba7dc6471f5d2.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-a3adee158d70a602.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-36aa33d5b51fea85.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-8ffb67928670fecf.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-95ea48ddc44a311b.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-4f5122dbbdcc70ab.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-68f423c59dc48a40.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-54580c7798bf2225.rlib" "-Wl,--end-group" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-e805fea8b8005cb4.rlib" "-Wl,-Bdynamic" "-lc" "-lm" "-lrt" "-lpthread" "-lutil" "-ldl" "-lutil" "-ldl" "-lrt" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lutil" "-ldl" "-lutil"
  = note: /usr/bin/ld: /home/isaac/go/src/github.com/is8ac/cc_err_demo/target/release/deps/cc_err_demo-949370c0c3e7c5b4.cc_err_demo.5gfojped-cgu.4.rcgu.o: in function `cc_err_demo::main':
          cc_err_demo.5gfojped-cgu.4:(.text._ZN11cc_err_demo4main17h83b85daad37728b4E+0x27): undefined reference to `core::array::<impl core::convert::AsMut<[T]> for [T; N]>::as_mut'
          /usr/bin/ld: /home/isaac/go/src/github.com/is8ac/cc_err_demo/target/release/deps/cc_err_demo-949370c0c3e7c5b4: hidden symbol `_ZN4core5array92_$LT$impl$u20$core..convert..AsMut$LT$$u5b$T$u5d$$GT$$u20$for$u20$$u5b$T$u3b$$u20$N$u5d$$GT$6as_mut17h6128af6739856507E' isn't defined
          /usr/bin/ld: final link failed: bad value
          collect2: error: ld returned 1 exit status
          

error: aborting due to previous error; 1 warning emitted

error: could not compile `cc_err_demo`.

Caused by:
  process didn't exit successfully: `rustc --crate-name cc_err_demo --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C opt-level=3 -Cembed-bitcode=no -C metadata=949370c0c3e7c5b4 -C extra-filename=-949370c0c3e7c5b4 --out-dir /home/isaac/go/src/github.com/is8ac/cc_err_demo/target/release/deps -L dependency=/home/isaac/go/src/github.com/is8ac/cc_err_demo/target/release/deps --extern rand=/home/isaac/go/src/github.com/is8ac/cc_err_demo/target/release/deps/librand-bec2ad1f072a8aa0.rlib --extern rand_hc=/home/isaac/go/src/github.com/is8ac/cc_err_demo/target/release/deps/librand_hc-a144c651cd5437de.rlib` (exit code: 1)

Version

rustc 1.46.0-nightly (feb3536eb 2020-06-09)
binary: rustc
commit-hash: feb3536eba10c2e4585d066629598f03d5ddc7c6
commit-date: 2020-06-09
host: x86_64-unknown-linux-gnu
release: 1.46.0-nightly
LLVM version: 10.0
@is8ac is8ac added the C-bug Category: This is a bug. label Jun 13, 2020
@jonas-schievink jonas-schievink added A-const-generics Area: const generics (parameters and arguments) A-linkage Area: linking into static, shared libraries and binaries F-const_generics `#![feature(const_generics)]` requires-nightly This issue requires a nightly compiler in some way. labels Jun 13, 2020
@lcnr lcnr added the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Jul 16, 2020
@is8ac
Copy link
Author

is8ac commented Sep 11, 2020

I reduced it.

[u8; 1] works, but [u8; 1 * 1] does not work.

#![feature(const_generics)]
use std::convert::AsMut;
use std::default::Default;

trait Foo: Sized {
    type Baz: Default + AsMut<[u8]>;
    fn bar() {
        Self::Baz::default().as_mut();
    }
}

impl Foo for () {
    type Baz = [u8; 1 * 1];
    //type Baz = [u8; 1];
}

fn main() {
    <() as Foo>::bar();
}

In both release and debug, it yields approximate the same error as before on:

rustc 1.48.0-nightly (a1947b3f9 2020-09-10)
binary: rustc
commit-hash: a1947b3f9e2831e2060bc42f0c78e4a2bb67930a
commit-date: 2020-09-10
host: x86_64-unknown-linux-gnu
release: 1.48.0-nightly
LLVM version: 11.0

But compiles successfully on:

rustc 1.45.0-nightly (a74d1862d 2020-05-14)
binary: rustc
commit-hash: a74d1862d4d87a56244958416fd05976c58ca1a8
commit-date: 2020-05-14
host: x86_64-unknown-linux-gnu
release: 1.45.0-nightly
LLVM version: 9.0

@varkor varkor removed the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Sep 13, 2020
@varkor
Copy link
Member

varkor commented Sep 13, 2020

This fails with const_generics, but not min_const_generics.

@varkor
Copy link
Member

varkor commented Oct 21, 2020

This appears to be working now. I'll add a test.

@varkor varkor added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Oct 21, 2020
@varkor varkor self-assigned this Oct 21, 2020
varkor added a commit to varkor/rust that referenced this issue Oct 21, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Oct 22, 2020
@varkor
Copy link
Member

varkor commented Oct 28, 2020

@lcnr and I were unable to reproduce an error with the examples here, but they still fail on extended CI (though not with the original error here). The PR is #78207. We'll have to revisit this one.

@varkor varkor added E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example and removed E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. labels Oct 28, 2020
@is8ac
Copy link
Author

is8ac commented Aug 20, 2021

Note that on latest nightly, I am still encountering this issue.

(Any time I use the rand crate and SeedableRng with #![feature(const_generics)], I trigger this.)

rustc 1.56.0-nightly (6d64f7f69 2021-08-19)
binary: rustc
commit-hash: 6d64f7f695943541fe12bb960971403f440d7225
commit-date: 2021-08-19
host: x86_64-unknown-linux-gnu
release: 1.56.0-nightly
LLVM version: 12.0.1

Error:

error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "-m64" "ice_demo.ice_demo.2f961bda-cgu.0.rcgu.o" "ice_demo.ice_demo.2f961bda-cgu.1.rcgu.o" "ice_demo.ice_demo.2f961bda-cgu.10.rcgu.o" "ice_demo.ice_demo.2f961bda-cgu.11.rcgu.o" "ice_demo.ice_demo.2f961bda-cgu.12.rcgu.o" "ice_demo.ice_demo.2f961bda-cgu.2.rcgu.o" "ice_demo.ice_demo.2f961bda-cgu.3.rcgu.o" "ice_demo.ice_demo.2f961bda-cgu.4.rcgu.o" "ice_demo.ice_demo.2f961bda-cgu.5.rcgu.o" "ice_demo.ice_demo.2f961bda-cgu.6.rcgu.o" "ice_demo.ice_demo.2f961bda-cgu.7.rcgu.o" "ice_demo.ice_demo.2f961bda-cgu.8.rcgu.o" "ice_demo.ice_demo.2f961bda-cgu.9.rcgu.o" "ice_demo.3cmg1zgsfxewpl4s.rcgu.o" "-Wl,--as-needed" "-L" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-1dd6c19f0820d51d.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-4695c0f6311791db.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-1a282f8b292d9e3f.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-a54ae5159230894d.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-13671d003abcccd5.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-7509adad918d4b3b.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-66d0be1f7efaf5ca.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-41443b46a1557b2c.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-60812e99072283ff.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-943ba0c1e3f87a89.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-0dbc7e011696d844.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-78b2343cc72ff57a.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-65fa19680bfb5ee4.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-72cab8079f9b3b1e.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-32d13a5363efe47b.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-9ee1d5d15e6abbeb.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-52d5241975807511.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-9924c22ae1efcf66.rlib" "-Wl,--end-group" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-96219fb718f2f3e8.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "ice_demo" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs"
  = note: /usr/bin/ld: ice_demo.ice_demo.2f961bda-cgu.12.rcgu.o: in function `ice_demo::Foo::bar':
          ice_demo.2f961bda-cgu.12:(.text._ZN8ice_demo3Foo3bar17h82239ce279805729E+0x1b): undefined reference to `core::array::<impl core::convert::AsMut<[T]> for [T; N]>::as_mut'
          /usr/bin/ld: ice_demo: hidden symbol `_ZN4core5array92_$LT$impl$u20$core..convert..AsMut$LT$$u5b$T$u5d$$GT$$u20$for$u20$$u5b$T$u3b$$u20$N$u5d$$GT$6as_mut17ha4f6eccff6597757E' isn't defined
          /usr/bin/ld: final link failed: bad value
          collect2: error: ld returned 1 exit status
          
  = help: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

error: aborting due to previous error; 1 warning emitted

@is8ac
Copy link
Author

is8ac commented Jan 2, 2022

Sorry to keep bumping. I continue to encounter this issue when I attempt to use SeedableRng with generic_const_exprs on latest nightly.

Code
#![feature(generic_const_exprs)]
use std::convert::AsMut;
use std::default::Default;

trait Foo: Sized {
    type Baz: Default + AsMut<[u8]>;
    fn bar() {
        Self::Baz::default().as_mut();
    }
}

impl Foo for () {
    type Baz = [u8; 1 * 1];
    //type Baz = [u8; 1];
}

fn main() {
    <() as Foo>::bar();
}
Error
error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "-m64" "cc_error.cc_error.8de2614d-cgu.0.rcgu.o" "cc_error.cc_error.8de2614d-cgu.1.rcgu.o" "cc_error.cc_error.8de2614d-cgu.10.rcgu.o" "cc_error.cc_error.8de2614d-cgu.2.rcgu.o" "cc_error.cc_error.8de2614d-cgu.3.rcgu.o" "cc_error.cc_error.8de2614d-cgu.4.rcgu.o" "cc_error.cc_error.8de2614d-cgu.5.rcgu.o" "cc_error.cc_error.8de2614d-cgu.6.rcgu.o" "cc_error.cc_error.8de2614d-cgu.7.rcgu.o" "cc_error.cc_error.8de2614d-cgu.8.rcgu.o" "cc_error.cc_error.8de2614d-cgu.9.rcgu.o" "cc_error.1gaqyexc5usivrjm.rcgu.o" "-Wl,--as-needed" "-L" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-c46e4336da0ba77b.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-9cb5ef8235cf10de.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-c94e3d0069d19330.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-5a532766d1e80b5b.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-d08f0c83526179dc.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-d995c6cafdb3d253.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-02ebc04a72bd9433.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-5cbc32ae14534ca9.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-969ebc8623abfcc9.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-7f98f837d3579544.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-b96a8aea2dd7bf12.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-c7b2792f3bc0d0eb.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-7558dde8464d46ce.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-b3d84848ab790cf7.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-f48e57d6d73020ee.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-ffaac76756e3f83b.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-2a6a2797f7a73818.rlib" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-0e3656b1fda5fd7b.rlib" "-Wl,--end-group" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-f98cce041f593917.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/home/isaac/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "cc_error" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-nodefaultlibs"
  = note: /usr/bin/ld: cc_error.cc_error.8de2614d-cgu.0.rcgu.o: in function `cc_error::Foo::bar':
          cc_error.8de2614d-cgu.0:(.text._ZN8cc_error3Foo3bar17hc2d30ef1d966820bE+0x1b): undefined reference to `core::array::<impl core::convert::AsMut<[T]> for [T; N]>::as_mut'
          /usr/bin/ld: cc_error: hidden symbol `_ZN4core5array92_$LT$impl$u20$core..convert..AsMut$LT$$u5b$T$u5d$$GT$$u20$for$u20$$u5b$T$u3b$$u20$N$u5d$$GT$6as_mut17hc1c54643f022e16cE' isn't defined
          /usr/bin/ld: final link failed: bad value
          collect2: error: ld returned 1 exit status
          
  = help: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

error: aborting due to previous error; 1 warning emitted
rustc --version --verbose
rustc 1.59.0-nightly (cfa3fe5af 2021-12-31)
binary: rustc
commit-hash: cfa3fe5af339e724209b25715282adae0c61628f
commit-date: 2021-12-31
host: x86_64-unknown-linux-gnu
release: 1.59.0-nightly
LLVM version: 13.0.0

@mati865
Copy link
Contributor

mati865 commented Jan 2, 2022

Reliably reproduces for me using latest code.

@rustbot modify labels: -E-needs-mcve +E-needs-test

@rustbot rustbot added E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. and removed E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example labels Jan 2, 2022
@is8ac
Copy link
Author

is8ac commented Jan 23, 2022

I encountered a different trigger for what I am guessing is the same underlying bug. Error message is ~identical.

To work around, do one of:

  • Have baz() return an array instead of a Vec.
  • Replace K + 0 with K.
#![feature(generic_const_exprs)]
use std::marker::PhantomData;

pub trait Foo {
    type Quiz;
    fn bar() -> Self::Quiz;
}

#[derive(Clone, Debug)]
struct Corge<const K: usize> {}

impl<const K: usize> Foo for Corge<K>
where
    [(); K + 0]:,
{
    type Quiz = [u16; K + 0];
    fn bar() -> Self::Quiz {
        [0u16; K + 0]
    }
}

struct Gork<R: Foo> {
    t: PhantomData<R>,
}

impl<R: Foo> Gork<R> {
    fn baz(self) -> Vec<R::Quiz> {
        vec![R::bar()]
    }
    //fn baz(self) -> [R::Quiz; 1] {
    //    [R::bar()]
    //}
}

fn main() {
    let x = Gork::<Corge<3>> { t: PhantomData::default() };
    let _ = x.baz();
}

rustc --version --verbose:

rustc 1.60.0-nightly (17d29dcdc 2022-01-21)
binary: rustc
commit-hash: 17d29dcdce9b9e838635eb0adefd9b8b1588410b
commit-date: 2022-01-21
host: x86_64-unknown-linux-gnu
release: 1.60.0-nightly
LLVM version: 13.0.0

@varkor varkor removed their assignment Jan 23, 2022
@is8ac
Copy link
Author

is8ac commented Jan 23, 2022

Different trigger. Allocating with MaybeUninit causes an ICE, but simple [R::bar(); 1] works.

#![feature(generic_const_exprs)]
use std::marker::PhantomData;
use std::mem::MaybeUninit;

pub trait Foo {
    type Quiz;
    fn bar() -> Self::Quiz;
}

#[derive(Clone, Debug)]
struct Corge<const K: usize> {}

impl<const K: usize> Foo for Corge<K>
where
    [(); K + 0]:,
{
    type Quiz = [u8; K + 0];
    fn bar() -> Self::Quiz {
        [0u8; K + 0]
    }
}

struct Gork<R: Foo> {
    t: PhantomData<R>,
}

impl<R: Foo> Gork<R>
where
    R::Quiz: Copy,
{
    fn baz() {
        unsafe { MaybeUninit::<[R::Quiz; 1]>::uninit().assume_init() };
        //[R::bar(); 1];
    }
}

fn main() {
    Gork::<Corge<3>>::baz()
}

@lcnr lcnr removed the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Jan 24, 2022
@armanriazi

This comment was marked as off-topic.

@tmiasko tmiasko added the A-lazy-normalization Area: lazy normalization (tracking issue: #60471) label Feb 9, 2022
@BoxyUwU BoxyUwU added F-generic_const_exprs `#![feature(generic_const_exprs)]` and removed F-const_generics `#![feature(const_generics)]` labels Jun 28, 2022
@lcnr
Copy link
Contributor

lcnr commented Jun 28, 2022

const generics triage

#![feature(generic_const_exprs)]
use std::convert::AsMut;
use std::default::Default;

trait Foo: Sized {
    type Baz: Default + AsMut<[u8]>;
    fn bar() {
        Self::Baz::default().as_mut();
    }
}

impl Foo for () {
    type Baz = [u8; 1 * 1];
    //type Baz = [u8; 1];
}

fn main() {
    <() as Foo>::bar();
}

still causes a linker error but passes with v0 symbol mangling: https://godbolt.org/z/8v4jTnP7f

I assume we end up mangling an unevaluated constant somewhere with legacy?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) A-lazy-normalization Area: lazy normalization (tracking issue: #60471) A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]` requires-nightly This issue requires a nightly compiler in some way.
Projects
None yet
9 participants