Skip to content

Link fails with hidden symbol isn't defined #86710

Closed
@hrektts

Description

@hrektts

This code (playground)

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

use std::marker::PhantomData;

fn main() {
    let x = FooImpl::<BarImpl<1>> {
        phantom: PhantomData,
    };
    let _ = x.foo::<BarImpl<1>>();
}

trait Foo<T>
where
    T: Bar,
{
    fn foo<U>(&self)
    where
        T: Operation<U>,
        <T as Operation<U>>::Output: Bar;
}

struct FooImpl<T>
where
    T: Bar,
{
    phantom: PhantomData<T>,
}

impl<T> Foo<T> for FooImpl<T>
where
    T: Bar,
{
    fn foo<U>(&self)
    where
        T: Operation<U>,
        <T as Operation<U>>::Output: Bar,
    {
        <<T as Operation<U>>::Output as Bar>::error_occurs_here();
    }
}

trait Bar {
    fn error_occurs_here();
}

struct BarImpl<const N: usize>;

impl<const N: usize> Bar for BarImpl<N> {
    fn error_occurs_here() {}
}

trait Operation<Rhs> {
    type Output;
}

//// Part-A: This causes error.
impl<const M: usize, const N: usize> Operation<BarImpl<M>> for BarImpl<N>
where
    BarImpl<{ N + M }>: Sized,
{
    type Output = BarImpl<{ N + M }>;
}

//// Part-B: This doesn't cause error.
// impl<const M: usize, const N: usize> Operation<BarImpl<M>> for BarImpl<N> {
//     type Output = BarImpl<M>;
// }

//// Part-C: This also doesn't cause error.
// impl<const M: usize, const N: usize> Operation<BarImpl<M>> for BarImpl<N> {
//     type Output = BarImpl<{ M }>;
// }

could not be compiled due to the following linker error:

error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "-m64" "/playground/target/debug/deps/playground-9e6e8e1c38e39d0a.playground.1o3xt69o-cgu.0.rcgu.o" "/playground/target/debug/deps/playground-9e6e8e1c38e39d0a.3tb83olt5p35wugo.rcgu.o" "-Wl,--as-needed" "-L" "/playground/target/debug/deps" "-L" "/playground/target/debug/build/libsqlite3-sys-d6ebd997e97c2f71/out" "-L" "/playground/target/debug/build/ring-0f34a5d678bd7990/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-fe747fceaa31b38a.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-5f5ff14665a8d5c5.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-12d0fbc5e9627456.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-1e1b451846357b80.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-844126776fe6ca1c.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-04e683b2eadd5848.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-9bb1f4aeee9adc2d.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-e7854498379a317c.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-652931817310ff98.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-15dd18e98e8fe12b.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-227c54975f77a73b.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-64e063177653d86f.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-bfd62449f4013547.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-1079ae9f5c548531.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-3bca990b4e08c950.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-2588c44e3ecacf72.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-c8ded1707ad10767.rlib" "-Wl,--end-group" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-b4feacc7dd8903c2.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-9e6e8e1c38e39d0a" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs"
  = note: /usr/bin/ld: /playground/target/debug/deps/playground-9e6e8e1c38e39d0a.playground.1o3xt69o-cgu.0.rcgu.o: in function `<playground::FooImpl<T> as playground::Foo<T>>::foo':
          /playground/src/main.rs:40: undefined reference to `<playground::BarImpl<_> as playground::Bar>::error_occurs_here'
          /usr/bin/ld: /playground/target/debug/deps/playground-9e6e8e1c38e39d0a: hidden symbol `_ZN64_$LT$playground..BarImpl$LT$_$GT$$u20$as$u20$playground..Bar$GT$17error_occurs_here17h8ba8c706699797a1E' isn't defined
          /usr/bin/ld: final link failed: bad value
          collect2: error: ld returned 1 exit status

This error disappears by commenting out part A and uncommenting either part B or part C.

Meta

rustc --version --verbose:

rustc 1.55.0-nightly (5a7834050 2021-06-23)
binary: rustc
commit-hash: 5a7834050f3a0ebcd117b4ddf0bc1e8459594309
commit-date: 2021-06-23
host: x86_64-unknown-linux-gnu
release: 1.55.0-nightly
LLVM version: 12.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)C-bugCategory: This is a bug.F-generic_const_exprs`#![feature(generic_const_exprs)]`

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions