Earlier quoted context omitted.
You often don't need it at all; fn foo(x: f32) { println!("{}", x); } fn main() { let x = 5.0; foo(x); } It will look at the signature for foo, and infer that x must be f32.
Whoa! Isn't this kind of inference dangerous? It seems that whichever call comes first is used to infer the type, so a single added line of code can change the type of a variable… fn foo32(x: f32) { println!("{}", x); } fn foo64(x: f64) { println!("{}", x); } fn bar64() { let x = 5.0; // f64 foo64(x); foo32(x); } fn bar32() { let x = 5.0; // f32, not f64 foo32(x); foo64(x); }
Announcing Rust 1.20
151–160 of 277 posts
Re: Announcing Rust 1.20
#152Earlier quoted context omitted.
I don't know the precise history, but at one point, it did have a "gc" type, which I believe was demarcated by the `@` sigil. So, for example, `@T` was a garbage collected pointer to `T`. IIRC, the actual garbage collector was simplistic, and was mostly just reference counting under the hood. At some point (in 2014, I think), the GC type went away. Since then, there has never been any serious talk of adding an option…
This is pretty accurate; however, a very long time ago there was a tracing GC!
Re: Announcing Rust 1.20
#153Earlier quoted context omitted.
I'd take a similar approach. After all `unsafe` use cases include the implementation of data structures.
I've argued this issue before. The answer isn't generics, Coq, or some fancy type system nobody will understand or use properly. There are only a few inherent trouble spots in pure Rust code safety. The big two are: - Partially initialized arrays. "Vec" has to be unsafe because growing an array involves uninitialized slots. You just need a way to say "this array is initialized from 0..N only", where N is in a data st…
Re: Announcing Rust 1.20
#154Earlier quoted context omitted.
I'd take a similar approach. After all `unsafe` use cases include the implementation of data structures.
I've argued this issue before. The answer isn't generics, Coq, or some fancy type system nobody will understand or use properly. There are only a few inherent trouble spots in pure Rust code safety. The big two are: - Partially initialized arrays. "Vec" has to be unsafe because growing an array involves uninitialized slots. You just need a way to say "this array is initialized from 0..N only", where N is in a data st…
Re: Announcing Rust 1.20
#155Earlier quoted context omitted.
I've argued this issue before. The answer isn't generics, Coq, or some fancy type system nobody will understand or use properly. There are only a few inherent trouble spots in pure Rust code safety. The big two are: - Partially initialized arrays. "Vec" has to be unsafe because growing an array involves uninitialized slots. You just need a way to say "this array is initialized from 0..N only", where N is in a data st…
A hashmap being implemented on top of vectors is a pretty common implementation. Not sure what Rust uses though.
Re: Announcing Rust 1.20
#156Earlier quoted context omitted.
This is pretty accurate; however, a very long time ago there was a tracing GC!
Are you sure? I thought @ was reference counted in 0.6 and then removed after. Was it before that?
Re: Announcing Rust 1.20
#157Earlier quoted context omitted.
You often don't need it at all; fn foo(x: f32) { println!("{}", x); } fn main() { let x = 5.0; foo(x); } It will look at the signature for foo, and infer that x must be f32.
Whoa! Isn't this kind of inference dangerous? It seems that whichever call comes first is used to infer the type, so a single added line of code can change the type of a variable… fn foo32(x: f32) { println!("{}", x); } fn foo64(x: f64) { println!("{}", x); } fn bar64() { let x = 5.0; // f64 foo64(x); foo32(x); } fn bar32() { let x = 5.0; // f32, not f64 foo32(x); foo64(x); }
Here's the compiler error that you'd get:
error[E0308]: mismatched types
--> src/main.rs:7:13
|
7 | foo32(x);
| ^ expected f32, found f64
error[E0308]: mismatched types
--> src/main.rs:13:13
|
13 | foo64(x);
| ^ expected f64, found f32Re: Announcing Rust 1.20
#158Interestingly, because Firefox chooses to use stable Rust exclusively, this is the version of Rust that will be used to deliver Quantum when Firefox 57 releases on November 14 (by which time Rust 1.21 will be out (releasing October 12), but Firefox 57 will be in beta by September 20).
Are there any blogs about how Rust is integrated into Firefox (a mostly C++ program) - i.e. how the Rust runtime is invoked, garbage collection etc?
[1]: http://rust-belt-rust.com/ [2]: http://rust-belt-rust.com/sessions.html
Re: Announcing Rust 1.20
#159Earlier quoted context omitted.
I used to be a huge fan of C++. I loved how you could work with a somewhat OO language while still wielding dark powers like: manual memory management, mix-n-match polymorphism (aka. virtual inheritance ), templates, type-erasing. Then I got a full time job working with a large C++ codebase. Since then I've been dealing with: - uninitialized variables / members - NULL checks - buffer overflows, especially with C-stri…
That's my main beef with C++. You read a book and it's beautiful - no uninitialized memory, safety, no C arrays/strings, RAII everywhere, it's clean, fast.....then you get to the "real world" and realize that 99% of C++ programmers are pretty f###ing horrible at their job and should've just stuck to naked C because at least then you'd be able to pin-point the bugs easier. So C++ is a wonderful language - in a world t…
Re: Announcing Rust 1.20
#160Earlier quoted context omitted.
I'd take a similar approach. After all `unsafe` use cases include the implementation of data structures.
I've argued this issue before. The answer isn't generics, Coq, or some fancy type system nobody will understand or use properly. There are only a few inherent trouble spots in pure Rust code safety. The big two are: - Partially initialized arrays. "Vec" has to be unsafe because growing an array involves uninitialized slots. You just need a way to say "this array is initialized from 0..N only", where N is in a data st…
The solution is a formal semantics for unsafe Rust, so that programmers can prove that their unsafe Rust code is safe to use by whatever means they prefer. (Mine would be by hand.)
---
Reply to dmix:
A formal semantics doesn't have to be particularly fancy, although in Rust's case, it will in most likelihood not be straightforward either.