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

generic_const_exprs: associated type with const parameter set by associated const gives "undefined reference" linker errors #100217

Closed
shelvacu opened this issue Aug 7, 2022 · 1 comment · Fixed by #100315
Labels
C-bug Category: This is a bug.

Comments

@shelvacu
Copy link

shelvacu commented Aug 7, 2022

MVCE:

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

trait TraitOne {
    const MY_NUM:usize;
    type MyErr : std::fmt::Debug;

    fn do_one_stuff(arr: [u8; Self::MY_NUM]) -> Result<(), Self::MyErr>;
}

trait TraitTwo {
    fn do_two_stuff();
}

impl<O: TraitOne> TraitTwo for O
where [(); Self::MY_NUM]: {
    fn do_two_stuff() { O::do_one_stuff([5; Self::MY_NUM]).unwrap() }
}

struct Blargotron;

#[derive(Debug)]
struct ErrTy<const N:usize> ([(); N]);

impl TraitOne for Blargotron {
    const MY_NUM:usize = 3;
    type MyErr = ErrTy<{Self::MY_NUM}>;

    fn do_one_stuff(_arr: [u8; Self::MY_NUM]) -> Result<(), Self::MyErr> { Ok(()) }
}

fn main() {
    Blargotron::do_two_stuff();
}

(longer than I'd usually like an MVCE to be, but I couldn't find any more ways to shorten it)

Output with linker error:
$ cargo +nightly run
   Compiling rustbugrepro v0.1.0 (/home/shelvacu/rustbugrepro)
error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "-m64" "/tmp/rustcpdm3oV/symbols.o" "/home/shelvacu/rustbugrepro/target/debug/deps/rustbugrepro-b454c4cbfd8105b6.1ihqumwagrufjop0.rcgu.o" "/home/shelvacu/rustbugrepro/target/debug/deps/rustbugrepro-b454c4cbfd8105b6.1mup2xyy24n4gk36.rcgu.o" "/home/shelvacu/rustbugrepro/target/debug/deps/rustbugrepro-b454c4cbfd8105b6.23s252vpk659ujid.rcgu.o" "/home/shelvacu/rustbugrepro/target/debug/deps/rustbugrepro-b454c4cbfd8105b6.2stlozizc5uxjd7b.rcgu.o" "/home/shelvacu/rustbugrepro/target/debug/deps/rustbugrepro-b454c4cbfd8105b6.32r5fw7gu7hn650.rcgu.o" "/home/shelvacu/rustbugrepro/target/debug/deps/rustbugrepro-b454c4cbfd8105b6.3m9r4hpnytp8i5eg.rcgu.o" "/home/shelvacu/rustbugrepro/target/debug/deps/rustbugrepro-b454c4cbfd8105b6.3y6kclqhz0icogsf.rcgu.o" "/home/shelvacu/rustbugrepro/target/debug/deps/rustbugrepro-b454c4cbfd8105b6.4gqxo0wsc252b81i.rcgu.o" "/home/shelvacu/rustbugrepro/target/debug/deps/rustbugrepro-b454c4cbfd8105b6.5gj6i7t0wm9u39r7.rcgu.o" "/home/shelvacu/rustbugrepro/target/debug/deps/rustbugrepro-b454c4cbfd8105b6.8gtzyztqdis5wfk.rcgu.o" "/home/shelvacu/rustbugrepro/target/debug/deps/rustbugrepro-b454c4cbfd8105b6.b2wiaz2930r642i.rcgu.o" "/home/shelvacu/rustbugrepro/target/debug/deps/rustbugrepro-b454c4cbfd8105b6.h4vu5fvuiuflzws.rcgu.o" "/home/shelvacu/rustbugrepro/target/debug/deps/rustbugrepro-b454c4cbfd8105b6.20c23rlj3dtxnb5h.rcgu.o" "-Wl,--as-needed" "-L" "/home/shelvacu/rustbugrepro/target/debug/deps" "-L" "/home/shelvacu/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/home/shelvacu/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-9a60c77fcb3cb120.rlib" "/home/shelvacu/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-5b44c7aad80856ae.rlib" "/home/shelvacu/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-ff65b550b4dcd2ac.rlib" "/home/shelvacu/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-7f1169f253822fce.rlib" "/home/shelvacu/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-a981dbda6aeca1f9.rlib" "/home/shelvacu/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-fc1281d9e6392569.rlib" "/home/shelvacu/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-1fbfdea3abefe497.rlib" "/home/shelvacu/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-9c50e59a7c82c7d4.rlib" "/home/shelvacu/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-49ab78c1bdf400c6.rlib" "/home/shelvacu/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-640f18ffcf376a48.rlib" "/home/shelvacu/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-8448e4d3e976ee3c.rlib" "/home/shelvacu/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-cb13682f9c2a7246.rlib" "/home/shelvacu/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-cfa8f6cd7fbf314f.rlib" "/home/shelvacu/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-0f3268324638da83.rlib" "/home/shelvacu/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-9dba3f083c9eb142.rlib" "/home/shelvacu/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-aaaa00ed48be7dc8.rlib" "/home/shelvacu/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-522518611024dce5.rlib" "/home/shelvacu/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-05898138a596088a.rlib" "-Wl,--end-group" "/home/shelvacu/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-6088bc0426d36242.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/home/shelvacu/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/shelvacu/rustbugrepro/target/debug/deps/rustbugrepro-b454c4cbfd8105b6" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-nodefaultlibs"
  = note: /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/shelvacu/rustbugrepro/target/debug/deps/rustbugrepro-b454c4cbfd8105b6.b2wiaz2930r642i.rcgu.o: in function `<O as rustbugrepro::TraitTwo>::do_two_stuff':
          /home/shelvacu/rustbugrepro/src/main.rs:17: undefined reference to `core::result::Result<T,E>::unwrap'
          /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/shelvacu/rustbugrepro/target/debug/deps/rustbugrepro-b454c4cbfd8105b6: hidden symbol `_ZN4core6result19Result$LT$T$C$E$GT$6unwrap17h3f789d9c8ef9bb3fE' isn't defined
          /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../x86_64-pc-linux-gnu/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: could not compile `rustbugrepro` due to previous error

Rustc version:

$ rustc +nightly -vV
rustc 1.65.0-nightly (2befdefdd 2022-08-06)
binary: rustc
commit-hash: 2befdefdda0f2bc5ff93f7f95633c98841409098
commit-date: 2022-08-06
host: x86_64-unknown-linux-gnu
release: 1.65.0-nightly
LLVM version: 14.0.6

Also looked at other issues, one of these may be a dupe but none match the structure of the MVCE or the same linker error:

@shelvacu shelvacu added the C-bug Category: This is a bug. label Aug 7, 2022
@shelvacu
Copy link
Author

shelvacu commented Aug 7, 2022

Also repro's on windows:

Windows linker error
> cargo +nightly run
   Compiling rustbugrepro v0.1.0 (C:\Dev\rustbugrepro)
error: linking with `link.exe` failed: exit code: 1120
  |
  = note: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.28.29910\\bin\\HostX64\\x64\\link.exe" "/NOLOGO" "C:\\Users\\Shelvacu\\AppData\\Local\\Temp\\rustcRQUigQ\\symbols.o" "C:\\Dev\\rustbugrepro\\target\\debug\\deps\\rustbugrepro.1udni13he2xyym0b.rcgu.o" "C:\\Dev\\rustbugrepro\\target\\debug\\deps\\rustbugrepro.2s6b7q3vkeq1d64i.rcgu.o" "C:\\Dev\\rustbugrepro\\target\\debug\\deps\\rustbugrepro.3c0cr0eh1zukshsb.rcgu.o" "C:\\Dev\\rustbugrepro\\target\\debug\\deps\\rustbugrepro.3e6jxlkjoc5gzna9.rcgu.o" "C:\\Dev\\rustbugrepro\\target\\debug\\deps\\rustbugrepro.3eyd2duakhmjtemq.rcgu.o" "C:\\Dev\\rustbugrepro\\target\\debug\\deps\\rustbugrepro.3x2wpsi5dzeyr9uo.rcgu.o" "C:\\Dev\\rustbugrepro\\target\\debug\\deps\\rustbugrepro.4f1h8qdlhhqmrp7n.rcgu.o" "C:\\Dev\\rustbugrepro\\target\\debug\\deps\\rustbugrepro.51cqp6hddvxj1d9k.rcgu.o" "C:\\Dev\\rustbugrepro\\target\\debug\\deps\\rustbugrepro.5a201y9vd5xd6ruq.rcgu.o" "C:\\Dev\\rustbugrepro\\target\\debug\\deps\\rustbugrepro.5b08j8gri1710q23.rcgu.o" "C:\\Dev\\rustbugrepro\\target\\debug\\deps\\rustbugrepro.8i8rqrj0zicqix1.rcgu.o" "C:\\Dev\\rustbugrepro\\target\\debug\\deps\\rustbugrepro.kvlka6m9mh6xz16.rcgu.o" "C:\\Dev\\rustbugrepro\\target\\debug\\deps\\rustbugrepro.3zpxynnxwesoe9xt.rcgu.o" "/LIBPATH:C:\\Dev\\rustbugrepro\\target\\debug\\deps" "/LIBPATH:C:\\Users\\Shelvacu\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\Shelvacu\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-8f2958805c366b35.rlib" "C:\\Users\\Shelvacu\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-fed034f75e1fd7b9.rlib" "C:\\Users\\Shelvacu\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_demangle-dec7786bc54848e7.rlib" "C:\\Users\\Shelvacu\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd_detect-fd5241549c83eef9.rlib" "C:\\Users\\Shelvacu\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libhashbrown-5688c8846aadbd5c.rlib" "C:\\Users\\Shelvacu\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libminiz_oxide-ea5978b20cdb3144.rlib" "C:\\Users\\Shelvacu\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libadler-5095f98b1de89a77.rlib" "C:\\Users\\Shelvacu\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_alloc-806aa9f85f297b4a.rlib" "C:\\Users\\Shelvacu\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-6401deea286d934a.rlib" "C:\\Users\\Shelvacu\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcfg_if-5a2a92015c9f63a6.rlib" "C:\\Users\\Shelvacu\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-68fca0524476f675.rlib" "C:\\Users\\Shelvacu\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-bd07379605777ddb.rlib" "C:\\Users\\Shelvacu\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_core-69892fa511d5a698.rlib" "C:\\Users\\Shelvacu\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-798bc7c2d986ac97.rlib" "C:\\Users\\Shelvacu\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-d2245e599df4d1e5.rlib" "advapi32.lib" "userenv.lib" "kernel32.lib" "ws2_32.lib" "bcrypt.lib" "msvcrt.lib" "/NXCOMPAT" "/LIBPATH:C:\\Users\\Shelvacu\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "/OUT:C:\\Dev\\rustbugrepro\\target\\debug\\deps\\rustbugrepro.exe" "/OPT:REF,NOICF" "/DEBUG" "/NATVIS:C:\\Users\\Shelvacu\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:C:\\Users\\Shelvacu\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:C:\\Users\\Shelvacu\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis" "/NATVIS:C:\\Users\\Shelvacu\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libstd.natvis"
  = note: rustbugrepro.kvlka6m9mh6xz16.rcgu.o : error LNK2019: unresolved external symbol _ZN4core6result19Result$LT$T$C$E$GT$6unwrap17h12707c38822a18b6E referenced in function _ZN44_$LT$O$u20$as$u20$rustbugrepro..TraitTwo$GT$12do_two_stuff17hce79e834541c2b02E
          C:\Dev\rustbugrepro\target\debug\deps\rustbugrepro.exe : fatal error LNK1120: 1 unresolved externals


error: could not compile `rustbugrepro` due to previous error

rustc version:

> rustc +nightly -vV
rustc 1.64.0-nightly (affe0d3a0 2022-08-05)
binary: rustc
commit-hash: affe0d3a00e92fa7885e3f5d2c5073fde432d154
commit-date: 2022-08-05
host: x86_64-pc-windows-msvc
release: 1.64.0-nightly
LLVM version: 14.0.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
1 participant