These are chat archives for rust-lang/rust

15th
Oct 2017
Alexander Ivanov
@alehander42
Oct 15 2017 17:06
hey is there a way to generate token list with rustc?
Zakarum
@omni-viral
Oct 15 2017 17:19
@blankhart How is that default drop isn't ok for this stack?
It seems pretty ok
blankhart
@blankhart
Oct 15 2017 17:23
I am getting a stack overflow because the compiler doesn't implement a tail-recursive default drop.
  // Produces a stack overflow
  #[test]
  fn drop_en_masse() {

    let frames = 100000;
    let mut list = List::new();

    // Iterate over interval [0, frames)
    for x in 0..frames {
      list.push(x);
    }

    // Implicit call to drop here

  }
The version I showed here is a variation of the one here: http://cglab.ca/~abeinges/blah/too-many-lists/book/first-drop.html
Zakarum
@omni-viral
Oct 15 2017 17:27
You can work around by putting you List<T> into struct Stack<T>(List<T>). Add methods of List to Stack and then implement Drop for Stack
impl<T> Drop for Stack<T> {
  fn drop(&mut self) {
    while let Some(_) = self.pop() {}
  }
}
blankhart
@blankhart
Oct 15 2017 17:32
thanks yeah that is what the too many lists book did. i am just starting with rust so was playing with the example and trying to figure out how much of a headache i will have if i continue with the language. i asked the question only because i didn't see why the compiler wasn't able to figure out what to do where it was already tracking the fields as moved or independently droppable for default drop. the discussion in the RFC is more intelligent than i was. thanks for following up!
Denis Lisov
@tanriol
Oct 15 2017 17:35
@blankhart The low-level data structure implementation is quite unergonomic in Rust, yes. However, people usually don't need to reimplement them afresh in every project.
blankhart
@blankhart
Oct 15 2017 17:46
yes you bet, and i shouldn't have phrased it that way as i meant no criticism of the language or the compiler. i just happened to be evaluating rust for the specific purpose of (as a hobby) learning about algorithms and systems programming at the same time by reimplementing low level data structures from scratch. the question was more directed to making sure i understood what was going on
xhallix
@xhallix
Oct 15 2017 18:18
How can I reuse a variable that has been declared as mut?
I have a json object which needs to be modified and is therefore borrowed as a &mut myobj
now I need to do something like myobj.is_null but this won't work since this variable already has a `mut binding``
Denis Lisov
@tanriol
Oct 15 2017 18:24
@xhallix Do you mean "is mutably borrowed" instead of "mut binding"?
xhallix
@xhallix
Oct 15 2017 18:24
@tanriol
let mut curr_obj = json!(null);
let mut obj_ref = &mut curr_obj;
Denis Lisov
@tanriol
Oct 15 2017 18:27
@blankhart Note that the low-level implementations of data structures often does not play nice with Rust's single ownership requirements - for example, when you have a double linked list, or a tree with pointers to parent, the pointer cycles will probably require you to go unsafe.
@xhallix You usually don't need to create such a reference variable, but if you do, you'll be able to use curr_obj again when it goes out of scope:
let mut curr_obj = json!(null);
{
    let mut obj_ref = &mut curr_obj;
    // No `curr_obj` usage here
}
// You can use it again
xhallix
@xhallix
Oct 15 2017 18:30
Yep but I need to use it within the same scope . I think than I should rethink my implementation if this is not possible
thanks : )
Denis Lisov
@tanriol
Oct 15 2017 18:31
If you show your problem, I may be able to suggest something better :-)
blankhart
@blankhart
Oct 15 2017 21:29
thank you @tanriol . i thought that kind of thing would make it interesting. i will get a helmet before i hurt my head.
Morgan Nesbitt
@MorganNesbitt
Oct 15 2017 22:37
has anyone here tried to statically link diesel mysql? I've talked to Sean already a bit and still cant figure it out.
i'm trying to get my build on alpine linux and the musl build compiles but its not statically linking.
the original mysqlclient-sys build script is https://github.com/sgrif/mysqlclient-sys/blob/master/build.rs