Skip to content

more generic const expr linker errors #84669

Closed
@pubfnbar

Description

@pubfnbar

You can also see a somewhat similar compilation error on Rust Playground here.

Code

I tried this code:

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

trait Foo {
    type Output;

    fn foo() -> Self::Output;
}

impl Foo for [u8; 3] {
    type Output = [u8; 1 + 2];

    fn foo() -> [u8; 3] {
        [1u8; 3]
    }
}

fn bug<const N: usize>()
where [u8; N]: Foo<Output: AsRef<[u8]>> {
    <[u8; N]>::foo().as_ref();
}

fn main() {
    bug::<3>();
}

And I get this compilation error:

error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "-arch" "arm64" "-L" "/Users/myname/.rustup/toolchains/nightly-2021-03-28-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib" "/Users/myname/bugtest/target/debug/deps/bugtest.1l75jh480o98q933.rcgu.o" "/Users/myname/bugtest/target/debug/deps/bugtest.29be2t6ezmvhm7x2.rcgu.o" "/Users/myname/bugtest/target/debug/deps/bugtest.29of54finq6ox97.rcgu.o" "/Users/myname/bugtest/target/debug/deps/bugtest.2iaggdnd2g35tj31.rcgu.o" "/Users/myname/bugtest/target/debug/deps/bugtest.2wo69rum8xfzuiqs.rcgu.o" "/Users/myname/bugtest/target/debug/deps/bugtest.3cltyvso2dds2imp.rcgu.o" "/Users/myname/bugtest/target/debug/deps/bugtest.3e4w749tfnwu28u1.rcgu.o" "/Users/myname/bugtest/target/debug/deps/bugtest.40osd4py8cczi6yx.rcgu.o" "/Users/myname/bugtest/target/debug/deps/bugtest.4hmr4l0vej5j5cb5.rcgu.o" "/Users/myname/bugtest/target/debug/deps/bugtest.ckraeqngv8n20df.rcgu.o" "/Users/myname/bugtest/target/debug/deps/bugtest.d2f9yytss8rozrq.rcgu.o" "-o" "/Users/myname/bugtest/target/debug/deps/bugtest" "/Users/myname/bugtest/target/debug/deps/bugtest.1dy116sy1e7uommm.rcgu.o" "-Wl,-dead_strip" "-nodefaultlibs" "-L" "/Users/myname/bugtest/target/debug/deps" "-L" "/Users/myname/.rustup/toolchains/nightly-2021-03-28-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib" "/Users/myname/.rustup/toolchains/nightly-2021-03-28-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libstd-48f9d8def3882461.rlib" "/Users/myname/.rustup/toolchains/nightly-2021-03-28-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libpanic_unwind-6079d1139c997fe3.rlib" "/Users/myname/.rustup/toolchains/nightly-2021-03-28-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libobject-c2e7b03d6524647a.rlib" "/Users/myname/.rustup/toolchains/nightly-2021-03-28-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libaddr2line-6d367b36defa47f3.rlib" "/Users/myname/.rustup/toolchains/nightly-2021-03-28-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libgimli-2805d7b872f6e3af.rlib" "/Users/myname/.rustup/toolchains/nightly-2021-03-28-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_demangle-2ecadf20a5fa947b.rlib" "/Users/myname/.rustup/toolchains/nightly-2021-03-28-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libhashbrown-a5a4c3d34eaf9770.rlib" "/Users/myname/.rustup/toolchains/nightly-2021-03-28-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_alloc-27919dc680852c01.rlib" "/Users/myname/.rustup/toolchains/nightly-2021-03-28-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libunwind-8af13a9ae07830cf.rlib" "/Users/myname/.rustup/toolchains/nightly-2021-03-28-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcfg_if-13e83b8b77a460a7.rlib" "/Users/myname/.rustup/toolchains/nightly-2021-03-28-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/liblibc-517771ac81b6a136.rlib" "/Users/myname/.rustup/toolchains/nightly-2021-03-28-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/liballoc-2d719eb433b05a5a.rlib" "/Users/myname/.rustup/toolchains/nightly-2021-03-28-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_core-d3b246a19a31e168.rlib" "/Users/myname/.rustup/toolchains/nightly-2021-03-28-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcore-91a60db5335b92da.rlib" "/Users/myname/.rustup/toolchains/nightly-2021-03-28-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcompiler_builtins-f02722469d4c1a9c.rlib" "-lSystem" "-lresolv" "-lc" "-lm" "-liconv"
  = note: Undefined symbols for architecture arm64:
            "core::array::_$LT$impl$u20$core..convert..AsRef$LT$$u5b$T$u5d$$GT$$u20$for$u20$$u5b$T$u3b$$u20$N$u5d$$GT$::as_ref::hf637b91746c7c47d", referenced from:
                bugtest::bug::h9267a81d6c91b555 in bugtest.ckraeqngv8n20df.rcgu.o
          ld: symbol(s) not found for architecture arm64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

Version it worked on

It most recently worked on: rustc 1.53.0-nightly (5e65467 2021-03-26)

Version with regression

rustc --version --verbose:

rustc 1.53.0-nightly (9b0edb7fd 2021-03-27)
binary: rustc
commit-hash: 9b0edb7fddacd6a60a380c1ce59159de597ab270
commit-date: 2021-03-27
host: aarch64-apple-darwin
release: 1.53.0-nightly
LLVM version: 12.0.0

@rustbot modify labels: +regression-from-stable-to-nightly -regression-untriaged

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)F-generic_const_exprs`#![feature(generic_const_exprs)]`P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions