These are chat archives for rust-lang/rust

3rd
Oct 2017
mnivoliez
@mnivoliez
Oct 03 2017 13:33
Hello
Steve Klabnik
@steveklabnik
Oct 03 2017 13:40
hi
mnivoliez
@mnivoliez
Oct 03 2017 13:50
I need some help with borrowing please ^^
Denis Lisov
@tanriol
Oct 03 2017 13:51
What's the problem?
I got a problem with lifetime
I got a vector of ref
I would like to divided this vector in recursive call to obtain a binary tree
and the borrow checker yeld at me for line 87 and 94
certainly cause the r_vec and l_vec do not live long enought
Zakarum
@omni-viral
Oct 03 2017 13:53
I think the problem is here pub fn create_tree<'a>(obs: &'a Vec<&Sphere>) -> Cell<'a> {
try to add 'a to the &Sphere
mnivoliez
@mnivoliez
Oct 03 2017 13:54
same error
Zakarum
@omni-viral
Oct 03 2017 13:54
And remove it from Vec
mnivoliez
@mnivoliez
Oct 03 2017 13:55
But I don't understand why the lifetime yeld at me, r_vec may not live long enought bu the &Sphere does
Zakarum
@omni-viral
Oct 03 2017 13:55
create_tree asks for reference to Vec that lives 'a
Remove this restriction
It is unnecessary
mnivoliez
@mnivoliez
Oct 03 2017 13:56
ok I got this part
Denis Lisov
@tanriol
Oct 03 2017 13:56
left = Cell_Content::CELL(&create_tree(&l_vec)) seems wrong
Zakarum
@omni-viral
Oct 03 2017 13:57
Yes. You have local Cell. You can't get &'a from it
Denis Lisov
@tanriol
Oct 03 2017 13:57
You create a Cell with create_tree and try assigning a reference to it... but it's a temporary, it will be freed after the end of this expression.
Zakarum
@omni-viral
Oct 03 2017 13:57
CELL(&'a Cell<'a>), should be CELL(Cell<'a>),
mnivoliez
@mnivoliez
Oct 03 2017 13:58
I'm obliged to put it as ref for cyclic dependencies
the compiler doesn't allow struct of infinite size
Zakarum
@omni-viral
Oct 03 2017 13:58
Than you have to box it
Box Cell in CELL or Cell_Content in right and left fields
mnivoliez
@mnivoliez
Oct 03 2017 14:00
Boxing Cell in Cell_Content seems more appropriate
Thanks to you, it finnaly works. Thank you very much :)
Laurențiu Nicola
@lnicola
Oct 03 2017 16:30
hi, did anyone use pkg-config on Windows? I get this error: MSVC target detected. If you are using the MSVC ABI rust build, please use the GNU ABI build instead. but I'm already using a -gnu toolchain
Zakarum
@omni-viral
Oct 03 2017 16:47
Is there some means to mark code unreachable so rustc will yell at me if it fails to eliminate that part during compilation?
unreachable! just panics at runtime
I want static check
Steve Klabnik
@steveklabnik
Oct 03 2017 16:48
there's nothing that does a static check
there's also an intrinsic and the compiler will optimize based on it
Michal 'vorner' Vaner
@vorner
Oct 03 2017 16:50
What do you want to accomplish? Why write some code and then mark it as statically unreachable? Why write it at all?
Zakarum
@omni-viral
Oct 03 2017 17:08
It looks like this.
I have a type (A, B, C, D, E ... ).
For all of them I call some foo<T: Trait>() -> Option<X>.
Then I look to all options and expect to find exactly one Some(X) and unwrap it.
I want to be sure this code will be compiled into getting compile time constant
I don't know how to express it by utilizing types and traits
It would be possible if there were negative traits feature
Generally you mark arms of match with unreachable!
It would be good to have an ability to ask compiler to verify unreachability.
Steve Klabnik
@steveklabnik
Oct 03 2017 17:15
the compiler already warns about unreachable statements that it can understand
Zakarum
@omni-viral
Oct 03 2017 17:16
It doesn't understand if statement is unreachable only in some instantiations of a generic function
I want it to fail if I try to instantiate the function and marked statement is reachable for such instantiation
I understand it looks more like a hack. But it can be used as workaround if some assertion isn't expressable with any language feature
Well. unreachablitity may be strage marker. It may be likestatic_assert in c++
Antonin Carette
@k0pernicus
Oct 03 2017 18:22
Hello!
David Harvey-Macaulay
@alteous
Oct 03 2017 18:23
Hi :smile:
Antonin Carette
@k0pernicus
Oct 03 2017 18:24
I got a simple question about understanding Box: is Box « reserved » for big data structures (to not « hit » the stack limit), and to take advantage of the Sized trait (for example recursive data structures like specific graphs)?
David Harvey-Macaulay
@alteous
Oct 03 2017 18:25
@k0pernicus Box<T> is simply a single item T on the heap.
Laurențiu Nicola
@lnicola
Oct 03 2017 18:25
Yup. It's also useful for dynamic dispatch when T is a trait, or when you want to avoid copying a large value
David Harvey-Macaulay
@alteous
Oct 03 2017 18:26
All of your examples are valid uses for Box types.
Antonin Carette
@k0pernicus
Oct 03 2017 18:26
@lnicola Dynamic dispatch?
Like owning a Trait Object?
David Harvey-Macaulay
@alteous
Oct 03 2017 18:27
Yes.
Antonin Carette
@k0pernicus
Oct 03 2017 18:27
Ok, cool :-) Thanks a lot!
Laurențiu Nicola
@lnicola
Oct 03 2017 18:27
like using Box<Write> to write either to a file or to the console
Antonin Carette
@k0pernicus
Oct 03 2017 18:27
Hum, I see