« first day (1889 days earlier)      last day (1593 days later) » 

9:06 AM
Another danger of macros: people forgetting that expressions are copied, not used...
 
10:03 AM
stackoverflow.com/questions/59353066/… That one is interesting. I immediately thought "Well, that easy! Let's add another layer and create a function that calls a-the-function but doesn't have a-the-variable in scope! But then the compiler unhelpfully complains you should use a closure instead.
Then I thought, well, let's make it a method on a unit type, and the compiler then wrongly suggests I also should use a closure… :/
 
This looks like a language or compiler bug
If both things are allowed to exist at the same time in the same scope, then we need to be sure the right one is always chosen
Is the function really in scope or is it implicitly moved before the other declaration ?
(like a const)
 
10:48 AM
This one at least looks like a bug: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=762d714bf664d6c78a1d86da92d83bca

There is no way you can use a closure here
 
what's the bug ? The error message ? It's the same problem to me
 
 
1 hour later…
11:57 AM
That one tells you to use a closure, but I can't just replace a method by a closure.
 
 
2 hours later…
2:17 PM
Dupe check:
Regex answers are junk. They are mostly just "here's a regex"
 
@Shepmaster The correct answer should obviously be "Ugghhh, don't use a regex for that"
 
@mcarton I upvoted your "answer" ;-)
 
 
1 hour later…
3:45 PM
I'll state the obvious solution: there's nothing forcing your variable to have the same name as the function. Change it. — Shepmaster 2 hours ago
but then you have b and c and how do you do when you're at z and you need to create a function ?
 
Unicode characters? -galaxy brain-
 
I still applaud OP for having asked the question instead of just renaming without losing time (what I would have done). OP and me learnt something.
 
yeah, me too. I was not aware of that name hoist thing.
 
It's in that category of "you shouldn't need to know about this because you shouldn't ever trigger it" :-)
 
LOL, exactly.
 
3:53 PM
I'm just happy to learn that in fact JavaScript and Rust are the same language
 
At a few recent trainings, I've gotten the question along the lines of "does the order of function declaration / function call matter" and I always have to pause because I feel like it's been so long since I've had to deal with a language where that's true (e.g. C), but perhaps JS proves me wrong...
 
depends what you call a function declaration
In JS you can declare a function with let a = ()=>2; or var a = ()=>2; and both are different between themselves and different from function a(){ return 2;} in scope
 
backwards compatibility is dumb
 
But anybody not doing JS should forget all this, there's no reason to encumber one's head
 
/me returns to using Rust
 
4:01 PM
BTW this morning I had another flashback. From c macros. I made a PR on another crate to fix an expansion bug leading to a compilation problem on windows
macros looking like function lead to dumb problems like this. And on lifetimes too.
 
@DenysSéguret why's that need to be a macro to start with?
 
I dunno exactly. I'm not the author of that macro
 
but one of my libs use it and I received a bug report this morning:
error[E0382]: use of moved value: `val`
   --> /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/termimad-0.8.3/src/compound_style.rs:149:55
    |
144 |     pub fn queue<W, D>(&self, w: &mut W, val: D) -> Result<()>
    |                     -                    --- move occurs because `val` has type `D`, which does not implement the `Copy` trait
    |                     |
    |                     consider adding a `Copy` constraint to this type argument
...
149 |         Ok(queue!(w, PrintStyledContent(self.apply_to(val)))?)
hence my PR on the macro
 
 
4 hours later…
7:37 PM
well, well, well
@LukasKalbertodt congrats
2
 
Nice!
Wait, they can commit directly to master? :O
 
@DenysSéguret Coming from JS, so far its differing let, var and const behaviours were actually of help while reading the Rust Book :)
 
@FrenchBoiethios Nah, basically no one can (although I might be able to because of infra team?). Just that they can review changes to the stdlib
 
7:54 PM
@Shepmaster Thanks :) Really excited what will come now :D I hope I can invest enough time to be useful!
@FrenchBoiethios Alex said: "meant to be a PR but I fat-fingered it". In case that clarifies anything ^_^
 
@FrenchBoiethios oh, you mean that commit — that repo isn't rust-lang/rust, so it has different permissions
 
I'm about to label broot as 1.0.
 
@DenysSéguret no worries, you've got 2-2^64 major versions left!
 
speaking of this...
@DenysSéguret In that case, all identifiers in that namespace should follow the same rule. What if I have a function-valued variable? It should be treated equally with the mix of functions in the same scope. — Kaz 19 mins ago
How to tell this person that the equal treatment he asks for doesn't seem very convenient...
 
"Compilers should be single pass"
 
8:09 PM
all bytes should be born equal
b2==b3 should be true!
 
But some bytes are more equal than others. ;)
 
> a function-valued variable
What would that mean?
fn foo() {}
let a = foo; // ?
 
That's how I understood it too
 
9:04 PM
I'm in chapter 8, section 8.1: doc.rust-lang.org/book/…
> Rust needs to know what types will be in the vector at compile time so it knows exactly how much memory on the heap will be needed to store each element.
this follows an example where a vector is built from an enum type to circumvent the "only one type in a vector" rule
I don't understand how the compiler can know how much memory will be needed when using the enum with, for instance, strings. If I were to dynamically build that vector with strings from a file at runtime, or from user input, how can the compiler know how much memory is needed?
 
@FélixGagnon-Grenier There's (at least) two pieces of memory involved
a String takes up 3x 64-bits (on a 64-bit machine) on the stack
And a dynamic amount of memory in the heap
The same is true for a Vec (a String is implemented as a Vec<u8> under the hood)
so, at compile time, a given Vec will know that each element will take up N bytes, but not how many elements there are
This is what it means by to store each element
 
oh good emphasis thanks
 

« first day (1889 days earlier)      last day (1593 days later) »