« first day (2607 days earlier)      last day (865 days later) » 

7:11 AM
0
Q: How to remove Rust clippy warning `consider using the `vec![]` macro: `let mut https: Vec<u8> = vec![..];`

Ayush MishraI have below rust code. let mut https: Vec<u8>= Vec::new(); https.push(b'/'); When I am running cargo clippy, I am getting below warning warning: calls to `push` immediately after creation https.push(b'/'); ^ help: consider using the `vec![]` macro: `let mut https: Vec<u8> = ...

answer literally just read what clippy say
> Author | Rust | Substrate | Blockchain Developer
I guess we gonna have several bad question from subtrate user
 
 
5 hours later…
11:59 AM
Whelp. We're sure witnessing an increase in blerkchain development.
 
This person is the author of a book "Blockchain For Rust Developers: The Ultimate Beginner’s Guide to build your own Blockchain application with Rust"
 
Sure it's fine and dandy that people are using Rust for these things. But could people also stop for a moment to think whether it makes any sense to use a blockchain in their use case that isn't wave catching.
 
 
2 hours later…
2:17 PM
@DenysSéguret yes I read the amazon com too: "Well, the book is really short and doesn't even have page numbers! The information seems like it was stripped from an online blog! " haha
 
 
1 hour later…
3:24 PM
const generic is so nice
I have the feeling there is a pre and after const_generic
can't wait GaTs
 
 
1 hour later…
4:52 PM
@Stargateur I agree, but think it will be two phases. The one we are in now, and the one after we can do crazy calculations in const generics
e.g. fn x<const N: usize>(_: [u8; N]) -> [u8; N + 1]
 
@Shepmaster So crazy :P
 
:-) I mean, the compiler doesn't have a measure of craziness
and that is crazy when N == usize::MAX
 
@Shepmaster we still can't do that ? damm I quit Rust
the "default integer type" question hit a lot today
advance of code effect again I guess
 
@Shepmaster Here's a question which seems to ask for some Rust knowledge: stackoverflow.com/questions/70217888/…
 
there was the same question not 2 day ago
 
5:02 PM
Ok, let's look at all questions which havent be asked 2 days ago
 
1
Q: How does Boxed closure calls work just like closure calls?

rajWhy does calling boxed closures work just like calling closures? Is it because of Deref implementation of Box ? Would it work on all smart pointers? As I tried some examples to better understand it, I get the following error. fn main() { let mut x = String::new(); let y = || { let...

same user
just a little different no ?
I mean that the same problem no ?
 
5:14 PM
The other answer seems to be lacking the detail about the mutable context. Maybe. There are too many moving parts here.
(and my answer was just dumb)
 
that problem simply never exist in practice
you never to that
the compiler is just by default using default fn call
any real case the function would be correctly inferring
 
I agree that the problem isn't important is practice. It's still vexing to not understand what happens
 
I am very hangover, at that point where I need to share that with y'all
 
@DenysSéguret I think it's because FnOnce need to consume
and deref doesn't allow that
FnInce is impl for Box doc.rust-lang.org/std/ops/…
but I thing it's only work with (*ww)
must be a very special case
 
5:32 PM
@Stargateur Sounds like a plausible explanation. I've found so little in the doc about the topic that I have no idea how to confirm that
@FélixAdriyelGagnon-Grenier Did you drink ?
 
yes. some lads from the hockey team thought it wise to order 24 shots somewhere around 1 am.
which would be great for a hockey team, but we were only 4 remaining at that time.
 
I just realize that hockey is the Canadian Rugby
 
(but we were drinking wine and beer, not shots)
 
yeah we all play hockey, it is known
 
5:34 PM
yes, it is. But I mean, when you play rugby you always break some parts and you always drink a lot
 
I remember having been brought to the hospital after a match, but not directly after, more like at 5am after having celebreated
 
hahaha. "alright lads, ima just have this here last beer before getting this stiched up"
 
@DenysSéguret I the very least I think you should undelete your answer at least to tell some possible clue I found and your wordaround (*ww)
 
@Stargateur Nah, make an answer yourself. Half mine was stupid.
(you may copy paste the less stupid parts)
or I make it CW
 
5:41 PM
no time, 20 m left
 
@Stargateur It's community wiki now
 
good idea
 
The compiler is too goot, it doesn't want me to write this:
fn main() {
let mut a:usize = 3;
a -= 5;
}
(it works with a stupid test)
Oh, I've made a program which works very differently in release mode compared to debug mode
 
5:57 PM
always be extra carefull substract size
always compare who is bigger
 
The goal was to have a crashing program (to test another program calling it). And I failed at that: it crashes in Debug mode but not in Release
 
hahha
underflow are check in debug
just do a panic
 
In fact this is interesting. I get very different results now in release mode, it does the substract with underflow without crashing
 
in release yes
 
3
Q: What happens in Rust programming language when an integer arithmetic operation overflows?

Hari Krishnan UAs far as I know, in C programming language(and many C - based languages), when an arithmetic operation overflows over an N-bit integer, this overflow shortens the result to modulo N-th power of 2, retaining only the LSB's of the resultant. What happens when such an integer arithmetic operation o...

6
A: How can integer overflow protection be turned off?

ShepmasterFrancis Gagné's answer is absolutely the correct answer for your case, but there is a compiler option to disable overflow checks. I don't see any reason to use it, but it exists and might as well be known about: #![allow(arithmetic_overflow)] fn main() { dbg!(u8::MAX + u8::MAX); } Via Cargo...

 
6:03 PM
thus underflow are often unspecified behavior in C If I recall, even some are UB
I don't know for rust underflow
 
@Stargateur unsigned is mod arithmetic by definition, so no "overflow". signed overflow is always ub
 
@GManNickG yeah something like that
 
5
Q: Is signed integer overflow in safe Rust in release mode considered as undefined behavior?

ZhiyaoRust treats signed integer overflow differently in debug and release mode. When it happens, Rust panics in debug mode while silently performs two's complement wrapping in release mode. As far as I know, C/C++ treats signed integer overflow as undefined behavior partly because: At that time of ...

 
im happy we can have custom profiles now, i've often done a manual "check" build which is release but with all debug & overflow assertions on.
 
6:06 PM
yeah that a nice adition
can't believe lto = true is still not default in release
 
i also added codegen-units = 1 because i hate fast compile times
 
6:19 PM
Oh, hey. Found an infinite loop in the compiler
that's exciting
 
 
1 hour later…
7:37 PM
:o
 
Interesting
 
7:57 PM
Benchmarking after having added the implementation: +Inf%
 
8:49 PM
@Shepmaster Is this Advent of Code related?
I was just thinking of doing something similar
 
indeed it was — for which day were you thinking of?
 
Day 3, part 2 :-)
 
yep
ultimately abandoned an iterator in favor of just using Vec and slices
 
I'll have a look after solving it! :-)
 
and I linked to the overall repo in case you want to see my first days
@Jason What was really annoying is that I knew it wasn't going to work
but i was waiting for the compiler to tell me so
 
9:00 PM
Ha, I recall someone mentioning this morning "I could not solve it in a non-trash way."
I've been wanting to do it that way, but if I can't, that's unfortunate.
 
my planned workaround was to use trait objects
which breaks the infinite type issue
but I also needed the ability to iterate over it twice
which meant I needed Clone
and trait objects + clone is annoying
 

« first day (2607 days earlier)      last day (865 days later) »