Skip to content

Test needed for linker error in associated function with generic_const_exprs #96699

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

Closed
Iwancof opened this issue May 4, 2022 · 1 comment · Fixed by #112990
Closed

Test needed for linker error in associated function with generic_const_exprs #96699

Iwancof opened this issue May 4, 2022 · 1 comment · Fixed by #112990
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-generic_const_exprs `#![feature(generic_const_exprs)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-incomplete-features This issue requires the use of incomplete features. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Iwancof
Copy link

Iwancof commented May 4, 2022

In the situation using the generic_const_exprs feature to specify the number of array elements, a linker error occurred in the Trait implementation.
We minimized it as much as possible, but it could be more simplified.

This is just a guess, but I think it is probably because the function signature is wrong.
The error content claims that there is no "compiler_bug2::Trait1::crash_here", although it should be "<compiler_bug2::Struct1<[i32; 1]> as compiler_bug2::Trait1<[i32; 1]>>::crash_here".

Code

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

const fn min(a: usize, b: usize) -> usize {
    if a < b {
        a
    } else {
        b
    }
}

trait Trait1<Inner1>
where
    Self: Sized,
{
    fn crash_here()
    where
        Inner1: Default,
    {
        Inner1::default();
    }
}

struct Struct1<T>(T);
impl<T> Trait1<T> for Struct1<T> {}

trait Trait2<Inner2>
where
    Self: Sized,
{
    type Assoc: Trait1<Inner2>;

    fn call_crash()
    where
        Inner2: Default,
    {
        // if Inner2 implements Default, we can call crash_here.
        Self::Assoc::crash_here();
    }
}

struct Struct2<const SIZE1: usize, const SIZE2: usize> {}
/*
where
    [(); min(SIZE1, SIZE2)]:,
{
    elem: [i32; min(SIZE1, SIZE2)],
}
*/

impl<const SIZE1: usize, const SIZE2: usize> Trait2<[i32; min(SIZE1, SIZE2)]>
    for Struct2<SIZE1, SIZE2>
{
    type Assoc = Struct1<[i32; min(SIZE1, SIZE2)]>;
    // dose Struct1<[i32; min(SIZE1, SIZE2)]> implement Default?
}

fn main() {
    pattern2();

    print_fully_name(<Struct2<1, 2> as Trait2<[i32; min(1, 2)]>>::Assoc::crash_here);
    // <compiler_bug2::Struct1<[i32; 1]> as compiler_bug2::Trait1<[i32; 1]>>::crash_here
}

fn pattern1() {
    // no crash
    <Struct2<1, 2> as Trait2<[i32; min(1, 2)]>>::Assoc::crash_here();
    <Struct2<1, 2> as Trait2<[i32; min(1, 2)]>>::call_crash();
}

fn pattern2() {
    // crash
    <Struct2<1, 2> as Trait2<[i32; min(1, 2)]>>::call_crash();

    // undefined reference to `compiler_bug2::Trait1::crash_here'
}

fn pattern3() {
    // no crash
    <Struct2<1, 2> as Trait2<[i32; min(1, 2)]>>::Assoc::crash_here();
}

fn print_fully_name<T>(_: T) {
    println!("{}", std::any::type_name::<T>());
}

Meta

rustc --version --verbose:


rustc 1.62.0-nightly (e1b71feb5 2022-05-03)
binary: rustc
commit-hash: e1b71feb592ba64805689e2b15b9fa570182c442
commit-date: 2022-05-03
host: x86_64-unknown-linux-gnu
release: 1.62.0-nightly
LLVM version: 14.0.1

Error output


error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "-m64" "/tmp/rustcccDCGE/symbols.o" "compiler_bug2.compiler_bug2.0850f77e-cgu.0.rcgu.o" "compiler_bug2.compiler_bug2.0850f77e-cgu.1.rcgu.o" "compiler_bug2.compiler_bug2.0850f77e-cgu.10.rcgu.o" "compiler_bug2.compiler_bug2.0850f77e-cgu.2.rcgu.o" "compiler_bug2.compiler_bug2.0850f77e-cgu.3.rcgu.o" "compiler_bug2.compiler_bug2.0850f77e-cgu.4.rcgu.o" "compiler_bug2.compiler_bug2.0850f77e-cgu.5.rcgu.o" "compiler_bug2.compiler_bug2.0850f77e-cgu.6.rcgu.o" "compiler_bug2.compiler_bug2.0850f77e-cgu.7.rcgu.o" "compiler_bug2.compiler_bug2.0850f77e-cgu.8.rcgu.o" "compiler_bug2.compiler_bug2.0850f77e-cgu.9.rcgu.o" "compiler_bug2.42ye6huydnlg6fs2.rcgu.o" "-Wl,--as-needed" "-L" "/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-202fc93d8ccaebf2.rlib" "/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-1333333cbe389678.rlib" "/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-93491bde8b3642ba.rlib" "/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-d338f5690e3fda2f.rlib" "/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-2cd7f06709609788.rlib" "/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-05bd833c6cc845b5.rlib" "/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-5543e955d2b2e107.rlib" "/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-a963b8f78c0365f5.rlib" "/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-626bd4749ba5679b.rlib" "/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-1c5c08d77aa4ee1f.rlib" "/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-43c97e136c6f66b3.rlib" "/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-3ad551729ddf5bdf.rlib" "/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-46de9b9399df1cae.rlib" "/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-aa03de290f9594ce.rlib" "/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-020914c5936c5f85.rlib" "/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-89782a6344bc3ddf.rlib" "/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-2a6a2797f7a73818.rlib" "/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-0e3656b1fda5fd7b.rlib" "-Wl,--end-group" "/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-16d69221f10b0282.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "compiler_bug2" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-nodefaultlibs"
  = note: /usr/bin/ld: compiler_bug2.compiler_bug2.0850f77e-cgu.3.rcgu.o: in function `compiler_bug2::Trait2::call_crash':
          compiler_bug2.0850f77e-cgu.3:(.text._ZN13compiler_bug26Trait210call_crash17hf0a368e161c9e687E+0x2): undefined reference to `compiler_bug2::Trait1::crash_here'
          /usr/bin/ld: compiler_bug2: hidden symbol `_ZN13compiler_bug26Trait110crash_here17hea054f4e014057d2E' 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; 2 warnings emitted

@Iwancof Iwancof added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 4, 2022
@JohnTitor
Copy link
Member

Triage: the issue no longer occurs with the latest nightly (I guess #100315 is related), could you check on your end?

@JohnTitor JohnTitor added the A-const-generics Area: const generics (parameters and arguments) label Mar 3, 2023
@cjgillot cjgillot added F-generic_const_exprs `#![feature(generic_const_exprs)]` requires-incomplete-features This issue requires the use of incomplete features. labels Mar 6, 2023
@BoxyUwU BoxyUwU changed the title Linker error in associated function with generic_const_exprs Test needed for linker error in associated function with generic_const_exprs May 10, 2023
@BoxyUwU BoxyUwU added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. labels May 10, 2023
JohnTitor added a commit to JohnTitor/rust that referenced this issue Jun 24, 2023
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
bors added a commit to rust-lang-ci/rust that referenced this issue Jun 25, 2023
…llaumeGomez

Rollup of 4 pull requests

Successful merges:

 - rust-lang#112918 (display PID of process holding lock)
 - rust-lang#112990 (Add a regression test for rust-lang#96699)
 - rust-lang#113011 (Add enum for `can_access_statics` boolean)
 - rust-lang#113018 (Fix test for rust-lang#96258)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors closed this as completed in 691580f Jun 25, 2023
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) C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-generic_const_exprs `#![feature(generic_const_exprs)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-incomplete-features This issue requires the use of incomplete features. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants