These are chat archives for rust-lang/rust

24th
Jan 2019
Denis Lisov
@tanriol
Jan 24 00:01
Really doubt that... I think that information may be not available in the executable.
Well, unless you're ok with an opaque string like TypeId { t: 7549865886324542212 } :-)
Martijn Bakker
@Gladdy
Jan 24 00:04
that is less than ideal :)
Coming from a cpp background here, for which it is available (https://en.cppreference.com/w/cpp/types/type_info/name). For now I'll just macro some types into a static hash table as something initial
Martijn Bakker
@Gladdy
Jan 24 01:42
Is there a way in Rust to implement a generic trait for multiple different types in a different way? eg.
trait MessageHandler<T> {
    fn handle<U>(state: &mut T, msg: U) {}
}

struct Handler;

impl<T> MessageHandler<T> for Handler where T : StateTrait {
    fn handle<U : AddMessageTrait>(state: &mut T, msg: U) {
        *state.field() += msg.field();
        println!("1 field value={}", state.field());
    }

    fn handle<U : MultMessageTrait>(state: &mut T, msg: U) {
        *state.field() *= msg.field();
        println!("2 field value={}", state.field());
    }
}
rustc nightly complains that they conflict (even if I pull out the U into MessageHandler<T,U>)
Furthermore, currently I still wrap the State and Message structs in traits because the specialization does not seem to like specification of explicit types.
but those are essentially pass-through and just add loads of boilerplate per state/message struct
Martijn Bakker
@Gladdy
Jan 24 02:01
and from "advanced traits" in the manual: "when a trait has a generic parameter, it can be implemented for a type multiple times, changing the concrete types of the generic type parameters each time. "
trsh
@trsh
Jan 24 07:42
Hi es there something like a universal solution to convert "ā,č" etc, to simple Alpha characters? For any language?
Christiaan676
@Christiaan676
Jan 24 09:45
@Gladdy You need multiple impl blocks
fn main () {
    let a = Object {value: 30};
    println!("{}", a.foo());

    let b = Object {value: "Hallo!".to_string()};
    println!("{}", b.foo());

}

trait Foo {
    fn foo(&self) -> String;
}

struct Object<T> {
    value: T
}

impl Foo for Object<String> {
    fn foo(&self) -> String {
        self.value.clone()
    }
}

impl Foo for Object<u32> {
    fn foo(&self) -> String {
        format!("{}",self.value)
    }
}
Martijn Bakker
@Gladdy
Jan 24 10:24
the difference is that it's my trait that's supposed to be generic, not the object I'm implementing it for
Tim Robinson
@1tgr
Jan 24 10:33
@trsh I think it's Unicode NFKD normalization followed by removing any non-ASCII characters
Martijn Bakker
@Gladdy
Jan 24 11:51
@Christiaan676 managed to get it to work by introducing an additional layer of generics and also splitting up the impl blocks, thanks!
Manuel Holtgrewe
@holtgrewe
Jan 24 12:41
Hi, I have a question with a very weird compiler error. The error happens deep under a lot of layers of software so this channel might not be the best one to ask in. I'm building a rust package in conda.
   Compiling tokio-timer v0.2.8

error: failed to run custom build command for `backtrace-sys v0.1.24`

process didn't exit successfully: `/opt/conda/conda-bld/digestiflow-cli_1548330171294/work/target/release/build/backtrace-sys-3c9a41016b6512eb/build-script-build` (exit code: 101)

--- stdout

TARGET = Some("x86_64-unknown-linux-gnu")

OPT_LEVEL = Some("3")

HOST = Some("x86_64-unknown-linux-gnu")

CC_x86_64-unknown-linux-gnu = None

CC_x86_64_unknown_linux_gnu = None

HOST_CC = None

CC = Some("gcc")

CFLAGS_x86_64-unknown-linux-gnu = None

CFLAGS_x86_64_unknown_linux_gnu = None

HOST_CFLAGS = None

CFLAGS = Some("-march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -pipe -I/opt/conda/conda-bld/digestiflow-cli_1548330171294/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placeho/include -fdebug-prefix-map=${SRC_DIR}=/usr/local/src/conda/${PKG_NAME}-${PKG_VERSION} -fdebug-prefix-map=${PREFIX}=/usr/local/src/conda-prefix -m64 -fPIC")

DEBUG = Some("false")

running: "gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-march=nocona" "-mtune=haswell" "-ftree-vectorize" "-fPIC" "-fstack-protector-strong" "-fno-plt" "-O2" "-pipe" "-I/opt/conda/conda-bld/digestiflow-cli_1548330171294/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placeho/include" "-fdebug-prefix-map=${SRC_DIR}=/usr/local/src/conda/${PKG_NAME}-${PKG_VERSION}" "-fdebug-prefix-map=${PREFIX}=/usr/local/src/conda-prefix" "-m64" "-fPIC" "-m64" "-I" "src/libbacktrace" "-I" "/opt/conda/conda-bld/digestiflow-cli_1548330171294/work/target/release/build/backtrace-sys-5fc2d3da7fb5f8d4/out" "-fvisibility=hidden" "-DBACKTRACE_ELF_SIZE=64" "-DBACKTRACE_SUPPORTED=1" "-DBACKTRACE_USES_MALLOC=1" "-DBACKTRACE_SUPPORTS_THREADS=0" "-DBACKTRACE_SUPPORTS_DATA=0" "-DHAVE_DL_ITERATE_PHDR=1" "-D_GNU_SOURCE=1" "-D_LARGE_FILES=1" "-Dbacktrace_full=__rbt_backtrace_full" "-Dbacktrace_dwarf_add=__rbt_backtrace_dwarf_add" "-Dbacktrace_initialize=__rbt_backtrace_initialize" "-Dbacktrace_pcinfo=__rbt_backtrace_pcinfo" "-Dbacktrace_syminfo=__rbt_backtrace_syminfo" "-Dbacktrace_get_view=__rbt_backtrace_get_view" "-Dbacktrace_release_view=__rbt_backtrace_release_view" "-Dbacktrace_alloc=__rbt_backtrace_alloc" "-Dbacktrace_free=__rbt_backtrace_free" "-Dbacktrace_vector_finish=__rbt_backtrace_vector_finish" "-Dbacktrace_vector_grow=__rbt_backtrace_vector_grow" "-Dbacktrace_vector_release=__rbt_backtrace_vector_release" "-Dbacktrace_close=__rbt_backtrace_close" "-Dbacktrace_open=__rbt_backtrace_open" "-Dbacktrace_print=__rbt_backtrace_print" "-Dbacktrace_simple=__rbt_backtrace_simple" "-Dbacktrace_qsort=__rbt_backtrace_qsort" "-Dbacktrace_create_state=__rbt_backtrace_create_state" "-Dbacktrace_uncompress_zdebug=__rbt_backtrace_uncompress_zdebug" "-o" "/opt/conda/conda-bld/digestiflow-cli_1548330171294/work/target/release/build/backtrace-sys-5fc2d3da7fb5f8d4/out/src/libbacktrace/alloc.o" "-c" "src/libbacktrace/alloc.c"

cargo:warning=gcc: error: unrecognized command line option ‘-fno-plt’

exit code: 1
This is how stuff breaks. It works to compile locally. It looks like the problem is with an old GCC version not supporting -fno-plt. Is this the main expected error cause for something like this? https://circleci.com/gh/bioconda/bioconda-recipes/41586?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link
Conda appears to install GCC 7.x (gcc_linux-64: 7.3.0-h553295d_3 conda-forge). Could it be that cargo somehow picks up the wrong, old system gcc?
toxicafunk
@toxicafunk
Jan 24 12:44
is this running on the same machine where it was compiled?
otherwise u probably need musl as a target
Manuel Holtgrewe
@holtgrewe
Jan 24 12:57
@toxicafunk ?
executive summary is that it relies on musl instead of gcc to support using the same binary on different systems
Manuel Holtgrewe
@holtgrewe
Jan 24 13:02
@toxicafunk I'm sorry for the confusion. compiling and running locally works. When I compile using the conda/Bioconda build system the compile step breaks.
toxicafunk
@toxicafunk
Jan 24 13:02
yes, I understand
rust will compile so u can use the bnary on systems with the same gcc where u compiled it
gcc version
but if, as u say, cuda uses a different version, then your binary will probably not work there
hence use musl as a compile target as explained in the link
toxicafunk
@toxicafunk
Jan 24 13:18
@holtgrewe did i explained myself correctly?
Justin Kilpatrick
@jkilpatr
Jan 24 13:37
has anyone ever seen utf8 encofing that works for curl etc but causes errors in rust?
Manuel Holtgrewe
@holtgrewe
Jan 24 14:20
@toxicafunk Yes, but apparently that was not the issue. It was conda-related, rather. The bioconda maintaniers are at it now. Thanks a lot, though, for your time and brain!
toxicafunk
@toxicafunk
Jan 24 14:21
if it is resolve please take the time to let us know how, might be useful to someone else
Manuel Holtgrewe
@holtgrewe
Jan 24 17:16
@toxicafunk The problem was with the bioconda build system, cf. bioconda/bioconda-recipes#13182 and bioconda/bioconda-recipes#12780 the wrong compiler was used.
toxicafunk
@toxicafunk
Jan 24 20:05
@holtgrewe thx for letting us know!