News for hackers. Stuff that matters.
Re:Mrustc: a Rust compiler written in C++ by weberc2 on Sunday September 24, 2017 @11:48AM (#15325123)
I understand not copying mutable pointers; I don't understand preventing copies of pointers to immutable data. I also don't see why affine types allow rust to get away without a GC in a way that scoped-based memory doesn't.
Re:Mrustc: a Rust compiler written in C++ by steveklabnik on Sunday September 24, 2017 @03:44PM (#15326170)
&T is Copy, so I'm not sure what you mean with the first bit.

For the second one, consider Box<T> vs uniq_ptr<T>; Rust can statically prevent use after-move, C++ cannot, and you'll get a NPE. That is, you can totally get rid of a GC through only RAII, but you can't guarantee memory safety (as far as we know!) without affine/linear types.

Re:Mrustc: a Rust compiler written in C++ by dbaupp on Monday September 25, 2017 @08:58PM (#15335378)
To be clear, Rust does scope-based memory management and does allow copying pointers to immutable data.

Affine typing (plus the rest of Rust's system) on top of scoped memory management is needed to avoid problems like returning a pointers into something that is deallocated at the end of a function:

  int &foo() {
    std::vector<int> v = ...;
    return v[0];
  } // return value is dangling
And similarly, avoiding having pointers into things that are destroyed when their parent is modified:

  std::vector<std::unique_ptr<int>> v = ...;
  int &ref = *v[0];
  v.clear();
  // ref is dangling