Earlier quoted context omitted.
Thank your for the detailed answer. > Attempting to do it completely manually has no benefit that I can see Package managers and build tools can do basically whatever they want - run commands, execute binaries, download data, upload data, send telemetry - whatever any one of the package maintainers wants. I prefer to develop in an offline VM. When a new library is required I just download it using the host machine, c…
I totally understand your desire to develop things in a sandboxed environment but the source code for Rust/Cargo/Etc. is all available under their organization at GitHub. [0] It would be easy to audit and raise issues if you have any concerns. [0]: https://github.com/rust-lang
Announcing Rust 1.35.0
61–70 of 111 posts
Re: Announcing Rust 1.35.0
#62Coming from C++, this always throws me a bit: if (0..=10).contains(&5) { I assume we are taking a ref to "5" (and not passing by value) because "Range" is a generic type that might be too big to want to copy (or it may not be copyable at all). But taking a reference to a number for a simple operation like this feels... weird. It makes me worry that Rust is going to be passing around pointers to some stack-allocated "…
Re: Announcing Rust 1.35.0
#63Coming from C/C++. Is working with the online package manager (Cargo?) mandatory? Or is there a sustainable way of working/developing with Rust while completely offline? I'd like to start a project, manually import libraries (downloaded manually, no dependency hell), read documentation, etc. Is it possible?
You can work completely offline. All official tools support it. Rust team can't do much about ecosystem though. There are some libraries which download resource (say, large data table) over the network at build time. I consider these bugs, but maintainers of those libraries may disagree.
Re: Announcing Rust 1.35.0
#64Earlier quoted context omitted.
I think some would have reacted exactly with other await syntax proposals. The amount of feedback they got is overwhelming. I believe all of the unique ideas are all looked into by the team. The Lang team is doing a great job. all I wish now is to slow down and not grow the language to C++ levels.
I wish they spent time at making the code a tad bit less symbol-ic and more verb-ic, the amount of nonalphabetic symbols used is just immense and it's not easy to decipher quickly. C++ suffers from the same issue I think.
Re: Announcing Rust 1.35.0
#65Re: Announcing Rust 1.35.0
#661. How does this handle ranges whose length is larger than can be represented in an integer?
2. How does iterating a range work for floats? It looks like it just adds one [1], won't this mean that it will loop forever if the next representable float is +2?
1: https://doc.rust-lang.org/src/core/iter/range.rs.html#297
Re: Announcing Rust 1.35.0
#67Earlier quoted context omitted.
Will the calling convention pass this by value even if it isn't inlined? My hope is that the ABI would systematically decide: "passing a const ref to a type that fits in a machine word is silly, so we never do that."
I think so, but am not sure. The spec answer is “who knows” because it’s not defined, but practically I’m not 100% sure if the compiler does it always today.
https://play.rust-lang.org/?version=stable&mode=release&edit...
(see assembly output)
Edit 2: I lied: Rust doesn't perform such an optimization but LLVM does, -argpromote. But it only works if the callee is compiled in the same LLVM module as the caller (or with non-thin LTO), and is not visible outside that module. And since it has to respect pointer identity, it only works in a subset of cases.
Original post:
It arguably cannot, because you can cast the reference to a raw pointer and compare it to other pointers, though I don't think there's been a proper discussion on whether or not references are guaranteed to preserve pointer identity.
Edit 1: However, Rust's compilation model does theoretically allow the compiler to modify a function's ABI based on its implementation, at least in some cases, so it could theoretically perform the optimization only when calling functions which it knows don't care about pointer identity. That would avoid violating the aforementioned guarantee that may or may not exist, but it would be less reliable, as the compiler's analysis would inevitably lose track of some pointer values and treat them as escaping, thus potentially identity-sensitive, when they're actually not.
Re: Announcing Rust 1.35.0
#68Coming from C++, this always throws me a bit: if (0..=10).contains(&5) { I assume we are taking a ref to "5" (and not passing by value) because "Range" is a generic type that might be too big to want to copy (or it may not be copyable at all). But taking a reference to a number for a simple operation like this feels... weird. It makes me worry that Rust is going to be passing around pointers to some stack-allocated "…
what steveklabnik said. if I understand correctly, this is dealing with that 5 as if integers were a generic type. which is the expected "default" behavior (as in compiler design, not programmer daily use). a generic type would be stored on the heap, and references there make sense to avoid copies. what happens here is that integers are special because they are stored in the stack, they are immutable, and always copi…
Edit: But in this case the reference will be optimized away anyway, because the callee function will be inlined.
Edit 2: Actually, the optimization does exist at the LLVM level, though it only applies in some cases. See my other comment:
Re: Announcing Rust 1.35.0
#69RangeInclusive is an interesting API: 1. How does this handle ranges whose length is larger than can be represented in an integer? 2. How does iterating a range work for floats? It looks like it just adds one [1], won't this mean that it will loop forever if the next representable float is +2? 1: https://doc.rust-lang.org/src/core/iter/range.rs.html#297
2. The Iterator implementation for RangeInclusive requires the underlying type to implement Step [1], which floats do not. So you can't iterate over a range of floats (although you can still construct one).
[1] https://doc.rust-lang.org/nightly/std/iter/trait.Step.html
Re: Announcing Rust 1.35.0
#70RangeInclusive is an interesting API: 1. How does this handle ranges whose length is larger than can be represented in an integer? 2. How does iterating a range work for floats? It looks like it just adds one [1], won't this mean that it will loop forever if the next representable float is +2? 1: https://doc.rust-lang.org/src/core/iter/range.rs.html#297
impl Iterator for ops::RangeInclusive {
RangeInclusive implements Iterator only for types A which implement Step. Floating point types like f64 are not Step:https://doc.rust-lang.org/std/iter/trait.Step.html
Thus RangeInclusive is perfectly valid, but RangeInclusive cannot be used as an Iterator.
See also the bounds on contains():
https://doc.rust-lang.org/std/ops/struct.RangeInclusive.html...
f64 is PartialOrd, so a RangeInclusive can be asked if it contains a specified f64. This definition would also allow one to ask a RangeInclusive if it contains a specified IpAddr _or_ Ipv4Addr _or_ Ipv6Addr, since IpAddr is PartialOrd, PartialOrd, and PartialOrd.
Any type A which can be compared to any other type B automatically gets RangeInclusive::contains(B). Anything which doesn't can still be a RangeInclusive, it just won't have contains().