Bug? rustc 1.13.0-nightly exit with linkage error


#1

Hi all,

Getting a linking with `cc` failed error.

Running rustc 1.13.0-nightly (32571c05c 2016-09-17).

summary

I’m trying to create a fn that returns an iterator using new impl Trait syntax. It works in tests that are in the same file (src/lib.rs), but a linkage error occurs when trying to call it (from src/bin/main.rs). Details in code snippets.

Also, as far as I can tell, this is a different linking error than: https://github.com/rust-lang/rust/issues/36260

Thanks for help, sorry if I’ve missed something obvious.

code

I have a dependency on owned-chars, not sure if that affects anything.

rustc 1.13.0-nightly (32571c05c 2016-09-17)

lib.rs:

#![feature(conservative_impl_trait)]

extern crate owned_chars;

use owned_chars::OwnedCharsExt;

pub fn to_digits(n: usize) -> impl Iterator<Item=usize> {
    // this fn has as linkage error
    n.to_string()
        .into_chars()
        .map(|c| c.to_digit(10).unwrap() as usize)
}

pub fn almost_to_digits(n:usize) -> impl Iterator<Item=char> {
    // removed the map, no linkage error
    n.to_string()
        .into_chars()

}

pub fn to_digits_vec(n: usize) -> Vec<usize> {
    // this fn is same as first, but collects to Vec. Works.
    n.to_string()
        .into_chars()
        .map(|c| c.to_digit(10).unwrap() as usize)
        .collect::<Vec<_>>()
}

#[cfg(test)]
mod tests {

    use super::*;

    #[test]
    fn it_works() {
        assert_eq!(to_digits(11).collect::<Vec<_>>(), vec![1,1]);
    }
}

bin/main.rs

extern crate impl_exit;

use impl_exit::{to_digits, almost_to_digits, to_digits_vec};

fn main() {
    // if .collect() is not called, linkage error doesn't occur.
    to_digits(11111).collect::<Vec<_>>();
    almost_to_digits(11111).collect::<Vec<_>>();
    to_digits_vec(11111);
}

###error

error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/hwchen/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/home/hwchen/projects/rust/impl-exit/target/debug/main.0.o" "-o" "/home/hwchen/projects/rust/impl-exit/target/debug/main" "-Wl,--gc-sections" "-pie" "-nodefaultlibs" "-L" "/home/hwchen/projects/rust/impl-exit/target/debug/deps" "-L" "/home/hwchen/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "-Wl,-Bdynamic" "/home/hwchen/projects/rust/impl-exit/target/debug/deps/libimpl_exit.rlib" "/home/hwchen/projects/rust/impl-exit/target/debug/deps/libowned_chars-d2d2f5faef62163d.rlib" "/home/hwchen/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-411f48d3.rlib" "/home/hwchen/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-411f48d3.rlib" "/home/hwchen/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-411f48d3.rlib" "/home/hwchen/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-411f48d3.rlib" "/home/hwchen/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcollections-411f48d3.rlib" "/home/hwchen/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_unicode-411f48d3.rlib" "/home/hwchen/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-411f48d3.rlib" "/home/hwchen/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-411f48d3.rlib" "/home/hwchen/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-411f48d3.rlib" "/home/hwchen/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-411f48d3.rlib" "/home/hwchen/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-411f48d3.rlib" "-l" "dl" "-l" "pthread" "-l" "gcc_s" "-l" "pthread" "-l" "c" "-l" "m" "-l" "rt" "-l" "util"
  = note: /home/hwchen/projects/rust/impl-exit/target/debug/main.0.o: In function `core::ops::impls::{{impl}}::call_once<(char),closure>':
/buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libcore/ops.rs:2644: undefined reference to `impl_exit::to_digits::_$u7b$$u7b$closure$u7d$$u7d$::hd8668ec4df498d58'
collect2: error: ld returned 1 exit status