Skip to content

Linker error with u32::to_ne_bytes and map #88549

Closed
@ejmount

Description

@ejmount

I tried this code (playground example)

#![allow(incomplete_features)]
#![feature(const_generics)]

pub fn main() {
    // this causes a linker error if const_generics is enabled
    let _ = [0; 1].map(u32::to_ne_bytes);
    
    // but this does not!
    //let _ = [0; 1].map(|x| u32::to_ne_bytes(x));
}

I expected to see this happen: a compile error. And also, I particularly expect map(foo) and map(|x| foo(x)) to behave similarly.

Instead, this happened: the linker falls over:

error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "-m64" "/playground/target/debug/deps/playground-4c173013dcdff931.playground.8c85a93c-cgu.0.rcgu.o" "/playground/target/debug/deps/playground-4c173013dcdff931.12vh8z6qs538xs91.rcgu.o" "-Wl,--as-needed" "-L" "/playground/target/debug/deps" "-L" "/playground/target/debug/build/libsqlite3-sys-0d351e27eaa1e97b/out" "-L" "/playground/target/debug/build/ring-38bf9793e960dc3f/out" "-L" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-03b16363306a53dd.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-4695c0f6311791db.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-1a282f8b292d9e3f.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-a54ae5159230894d.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-13671d003abcccd5.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-7509adad918d4b3b.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-66d0be1f7efaf5ca.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-41443b46a1557b2c.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-60812e99072283ff.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-412d545269c27063.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-0dbc7e011696d844.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-78b2343cc72ff57a.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-65fa19680bfb5ee4.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-72cab8079f9b3b1e.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-32d13a5363efe47b.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-9ee1d5d15e6abbeb.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-52d5241975807511.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-9924c22ae1efcf66.rlib" "-Wl,--end-group" "/playground/.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" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/playground/target/debug/deps/playground-4c173013dcdff931" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs"
  = note: /usr/bin/ld: /playground/target/debug/deps/playground-4c173013dcdff931.playground.8c85a93c-cgu.0.rcgu.o: in function `core::array::collect_into_array':
          /rustc/5d6804469d80aaf26f98090ae016af45e267f58f/library/core/src/array/mod.rs:506: undefined reference to `core::mem::maybe_uninit::MaybeUninit<T>::uninit_array'
          /usr/bin/ld: /rustc/5d6804469d80aaf26f98090ae016af45e267f58f/library/core/src/array/mod.rs:485: undefined reference to `core::mem::zeroed'
          /usr/bin/ld: /rustc/5d6804469d80aaf26f98090ae016af45e267f58f/library/core/src/array/mod.rs:508: undefined reference to `core::mem::maybe_uninit::MaybeUninit<T>::slice_as_mut_ptr'
          /usr/bin/ld: /rustc/5d6804469d80aaf26f98090ae016af45e267f58f/library/core/src/array/mod.rs:515: undefined reference to `core::slice::<impl [T]>::get_unchecked_mut'
          /usr/bin/ld: /rustc/5d6804469d80aaf26f98090ae016af45e267f58f/library/core/src/array/mod.rs:515: undefined reference to `core::mem::maybe_uninit::MaybeUninit<T>::write'
          /usr/bin/ld: /rustc/5d6804469d80aaf26f98090ae016af45e267f58f/library/core/src/array/mod.rs:521: undefined reference to `core::mem::forget'
          /usr/bin/ld: /rustc/5d6804469d80aaf26f98090ae016af45e267f58f/library/core/src/array/mod.rs:525: undefined reference to `core::mem::maybe_uninit::MaybeUninit<T>::array_assume_init'
          /usr/bin/ld: /playground/target/debug/deps/playground-4c173013dcdff931: hidden symbol `_ZN4core5slice29_$LT$impl$u20$$u5b$T$u5d$$GT$17get_unchecked_mut17hab68e22870af8369E' 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)A-linkageArea: linking into static, shared libraries and binariesA-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