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

more generic const expr linker errors #84669

Closed
pubfnbar opened this issue Apr 28, 2021 · 5 comments · Fixed by #100315
Closed

more generic const expr linker errors #84669

pubfnbar opened this issue Apr 28, 2021 · 5 comments · Fixed by #100315
Labels
A-const-generics Area: const generics (parameters and arguments) F-generic_const_exprs `#![feature(generic_const_exprs)]` P-medium Medium priority requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@pubfnbar
Copy link
Contributor

pubfnbar commented Apr 28, 2021

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

@rustbot rustbot added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Apr 28, 2021
@hameerabbasi
Copy link
Contributor

Bisected:

searched nightlies: from nightly-2021-03-01 to nightly-2021-04-28
regressed nightly: nightly-2021-03-28
searched commits: from 5e65467 to 9b0edb7
regressed commit: 9b0edb7

bisected with cargo-bisect-rustc v0.6.0

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --test-dir=. --start=2021-03-01

I believe the cause is either #81351 or #82626. cc @lcnr.

@apiraino
Copy link
Contributor

Assigning priority as discussed as part of the Prioritization Working Group procedure and removing I-prioritize.

@rustbot label -I-prioritize +P-medium +requires-nightly -regression-from-stable-to-nightly

@rustbot rustbot added P-medium Medium priority requires-nightly This issue requires a nightly compiler in some way. and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. labels Apr 28, 2021
@apiraino apiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 28, 2021
@jonas-schievink
Copy link
Contributor

With associated_type_bounds removed:

#![feature(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, <[u8; N] as Foo>::Output: AsRef<[u8]> {
    <[u8; N]>::foo().as_ref();
}

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

Note that removing the const_generics feature gate makes it compile and run without a problem.

@jonas-schievink jonas-schievink added A-const-generics Area: const generics (parameters and arguments) F-const_generics `#![feature(const_generics)]` labels Apr 28, 2021
@lcnr
Copy link
Contributor

lcnr commented Apr 29, 2021

looks like we aren't normalizing type Output = [u8; 1 + 2]; here. That shouldn't happen.

#81351 is what introduced this but i would expect us to fix this by adding a call to normalize somewhere before creating symbols.

@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

see #83972 (comment), should still be fixed 😆

@BoxyUwU BoxyUwU changed the title Const generics & associated type bound regression more generic const expr linker errors Jun 28, 2022
@bors bors closed this as completed in aeb5067 Aug 11, 2022
devcexx added a commit to devcexx/ws2812-avr that referenced this issue Aug 14, 2022
This change was able to be done after the release of
Rust Nightly 2022-08-12 that fixed
rust-lang/rust#84669.
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) F-generic_const_exprs `#![feature(generic_const_exprs)]` P-medium Medium priority requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
7 participants