These are chat archives for rust-lang/rust

21st
Mar 2018
Francisco Sosa
@Francososa
Mar 21 2018 02:46
I keep getting this error when I try to run rust/cargo commands
= note: /usr/bin/ld: cannot find Scrt1.o: No such file or directory
          collect2: error: ld returned 1 exit status


error: aborting due to previous error
I've been fixing it with the following:
$ sudo find /usr/ -name Scrt1*
/usr/lib/x86_64-linux-gnu/Scrt1.o
/usr/libx32/Scrt1.o
/usr/lib32/Scrt1.o

$ LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LIBRARY_PATH
$ export LIBRARY_PATH
Is there something wrong with my installation? How can I fix this for good?
Zomerfaun
@zomerfaun
Mar 21 2018 02:51
@Francososa isn't it LD_LIBRARY_PATH instead of LIBRARY_PATH?
Francisco Sosa
@Francososa
Mar 21 2018 02:53
I've been looking into it. The solution I found used LIBRARY_PATH
Most answers about the difference between both refer to gcc
Scott Cesar
@Kordalien
Mar 21 2018 03:04
Does anyone know why the commented out line here causes the compiler to error out at recursion max?
Azriel Hoh
@azriel91
Mar 21 2018 03:05

LD_LIBRARY_PATH is when you're running a program that needs (shared) libraries to run
LIBRARY_PATH is when you're compiling a program, and needs to link to (static) libraries

@Francososa: I'm not sure if this is a good idea, but you can add those lines to ~/.profile to "make the problem go away"

Scott Cesar
@Kordalien
Mar 21 2018 03:05
use std::ops::Add;

#[derive(Debug)]
pub struct Vec3<N>{
    pub x : N,
    pub y : N,
    pub z : N
}

impl<'a, 'b, N> Add<&'b Vec3<N>> for &'a Vec3<N>
    where &'a N:Add<&'b N>{
    type Output = Vec3<<&'a N as Add<&'b N>>::Output>;

    fn add(self, other: &'b Vec3<N>) -> Vec3< <&'a N as Add<&'b N>>::Output >{
        Vec3 {
            x: &self.x + &other.x,
            y: &self.y + &other.y,
            z: &self.z + &other.z,
        }
    }
}

fn main(){
    let x = &Vec3{x:1,y:2,z:3};
    println!("As expected {:?}", x+&(x+x));
    //println!("This however crashes {:?}", &(x+x)+x);
    let x : &Vec3<i32> = &Vec3{x:1,y:2,z:3};
    println!("but this doesn't {:?}", &(x+x)+x);
}
Francisco Sosa
@Francososa
Mar 21 2018 03:13
@azriel91 The other one I tried but didn't work was export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib:$LD_LIBRARY_PATH
On the Tips section
Azriel Hoh
@azriel91
Mar 21 2018 03:13
@Francososa: on my system (Ubuntu 17.10), I've got this:
$ cat /etc/ld.so.conf.d/x86_64-linux-gnu.conf
# Multiarch support
/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu
Scott Cesar
@Kordalien
Mar 21 2018 03:13
I know the problem is that it starts searching down Vec3<Vec3<Vec3<...>>> but I can't intuit whats breaking there
Francisco Sosa
@Francososa
Mar 21 2018 03:14
If you get an error like error while loading shared libraries while starting up rustfmt you should try the following:
export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib:$LD_LIBRARY_PATH
Azriel Hoh
@azriel91
Mar 21 2018 03:15
yeap that's for running a command, I suspect you're hitting the errors when you're trying to compile something?
Francisco Sosa
@Francososa
Mar 21 2018 03:15
@azriel91 Yeah, I got the same:
$ cat /etc/ld.so.conf.d/x86_64-linux-gnu.conf
# Multiarch support
/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu
Yeah, after cargo run
Azriel Hoh
@azriel91
Mar 21 2018 03:17
@Francososa do you also have this:
$ cat /etc/ld.so.conf                        
include /etc/ld.so.conf.d/*.conf
Francisco Sosa
@Francososa
Mar 21 2018 03:17
yeah
Azriel Hoh
@azriel91
Mar 21 2018 03:21
@Francososa rust-lang/cargo#3103 says that they ran sudo apt-get install build-essential to fix it
Francisco Sosa
@Francososa
Mar 21 2018 03:45
@azriel91 Thanks, will try that out now
Francisco Sosa
@Francososa
Mar 21 2018 03:51
Seems like I had already tried that one
Azriel Hoh
@azriel91
Mar 21 2018 04:01
hm, maybe this is related: https://github.com/rust-lang/rust/issues/31150#issuecomment-174322451
also, wonder what @tmbb's "local setup" problem was
Azriel Hoh
@azriel91
Mar 21 2018 05:07

@Kordalien: I tried to work out what is going on, maybe this helps:

Rust is trying to check if the Add<&'b Vec3<i32>> implementation for &'a Vec3<_> is satisfied. The _ can be any type where &'a _ implements Add<'b i32>. I'm guessing Rust is plugging in any & _ type that implements Add, one of which is &'a Vec3<_>. I.e. it's trying to check if &'a Vec3<_> implements Add<&'b i32'>, to confirm whether or not Vec3<_> in the first level &'a Vec3<Vec3<_>> implements Add<i32'>.

To do that, it needs to figure out what the second level _ is, which again may be anything where & _ implements Add<&'b i32>, and then it recurses.

eh I'm not sure I understand what I wrote.

Scott Cesar
@Kordalien
Mar 21 2018 05:15
I agree that the search for a matching Add is what's breaking it
what I'm not sure about is any technique I could use to depriortize itself in the search path
it has to be some behavioral peculiarity of the where clause as well, since implementing the same function but not targeting references
doesn't have this issue afaik
Just confirmed it doesen't
so it's something in the where clause/Output specification which breaks.
My current guess is the Output computation is what's looping
but I can't figure out what instruction is causing it
Azriel Hoh
@azriel91
Mar 21 2018 06:00
&(x + x) as &Vec3<i32> + x allows it to compile
Moggers
@Moggers
Mar 21 2018 06:23
        if let (Ok(texture_guard), Ok(buffers_guard)) =
            (self.target_texture.lock(), self.buffers.lock())
        {
            if let (&Some(texture), &Some((framebuffer, renderbuffer))) =
                (texture_guard.deref(), buffers_guard.deref())
can anyone suggest a better way to write this?
Scott Cesar
@Kordalien
Mar 21 2018 06:40
true
it's the same as the other direct hint
whats curious is that it requires a hint
which is either a mistake in the definiton, or some form of problem with the prioritization of choices to search for add on
Scott Cesar
@Kordalien
Mar 21 2018 06:49
(Well, slightly more direct, giving the hint x:&Vec3<i32> shows that search can prove it through 1 hop (output of x+x stays constrained to something provable as Vec3<i32>, it's when I need it to make two hops, derive x, derive x+x (three?, find an impl of plus on the derived type for &(x+x)) that it fails
Ayushya Chitransh
@AyushyaChitransh
Mar 21 2018 11:07
what happens about the ownership when creating a new struct variable from an existing struct variable. Does the old value get copied?
As in this one:
let user2 = User {
    email: String::from("another@example.com"),
    username: String::from("anotherusername567"),
    active: user1.active,
    sign_in_count: user1.sign_in_count,
};
Ayushya Chitransh
@AyushyaChitransh
Mar 21 2018 11:14
I think it is inherently calling .clone() trait. But I am not sure.
Andrey Lesnikov
@ozkriff
Mar 21 2018 11:20
I only see that a new struct literal uses active and sign_in_count fields of user1 variable. What are the types of these fields?
Judging by their names, they are bool/i32/etc - primitive types. And Copy trait is implemented for primitive types (as it's cheap to copy them), so they are just implicitly copied.
Ayushya Chitransh
@AyushyaChitransh
Mar 21 2018 11:58
I am reading from the documentation about structs. The data type are as follows:

struct User {
    username: String,
    email: String,
    sign_in_count: u64,
    active: bool,
}
Yes, you are right. Those variables might have been directly copied. That leads to another question, what if I try to assign new username from an existing username. I think i'll just try that.
Andrey Lesnikov
@ozkriff
Mar 21 2018 12:17
String is not Copy type, so you'll move this field from user1 to user2 and it will not longer be available through user1.
though if you change email: user1.email, to explicit clone call email: user1.email.clone(), it'll work fine
Ayushya Chitransh
@AyushyaChitransh
Mar 21 2018 13:16
okay. I get it now. Thanks @ozkriff