« first day (1862 days earlier)      last day (1609 days later) » 

11:07 AM
@JasonLiu Try simplifying your code, until you have a minimal reproduction
It's quite hard to follow that logic, and I would guess that is the reason that you haven't easily spotted the bug
I would guess that it is printing None, then goes back into the loop, which sets it to Some again,
 
12:06 PM
@PeterHall ``` if rp.is_some() {
*rp = rp.as_ref().unwrap().next.clone();
println!("{:?} {:?}", rp, rp.as_ref().unwrap().next);
}
if the rp changed after *rp = rp.as_ref().unwrap().next.clone(); , then should print None None, instead of infinite loop print Some(ListNode { val: 1, next: None }) None
only didn't changing value would make sense base on those prints
 
 
2 hours later…
2:29 PM
 
3:10 PM
You cannot execute anything from a macro input. A macro replaces some Rust code with some other Rust code, just like the C preprocessor, for example. — French Boiethios 8 mins ago
@Shepmaster Actually that's possible, writing in a file, compiling it as a dylib, etc. But I won't go in that direction :P
 
@FrenchBoiethios eww
 
I know...
 
> RAW_IDENTIFIER : r# IDENTIFIER_OR_KEYWORD Except crate, extern, self, super, Self
now, why those exceptions...
 
Rust magic
That's a small list, the OP could just try to match one of these
 
There's a surprising-to-me amount of upvotes on marginal questions
 
2
A: How to import from a file in a subfolder of src?

French BoiethiosThe subfolder must be declared as a module. You can do that using 3 different ways: Inline: declare the sorting_algorithms module inside your main.rs: // In main.rs: mod sorting_algorithms { pub mod bubble; } This is the simplest in my opinion. Put a mod.rs file inside the subfolder, wi...

@FrenchBoiethios ^ I'd put the mod.rs version last
I think the named module is the more idiomatic post rust 2018
 
3:30 PM
Every time I have to search to find it's called rev instead of reverse. And I can't code without having the doc of Option and Vec open... I can't remember...
 
@DenysSéguret don't worry that why doc exist
 
@DenysSéguret sounds like you need to code even more!
Do you have an IDE with autocomplete?
 
@Shepmaster yeah...
@Shepmaster it's not ideal. I should find time to improve it but it's always a lot of boring manipulations and it never 100% works
 
I get bit by Iterator::by_ref vs Option::as_mut
Like, the first requires &mut too
and I think the second should be as_mut_ref
 
Related: I'm still not at ease with the ref mut things in pattern matching. It's often at the third compilation try that I remember to use it... it doesn't feel consistent
 
3:35 PM
I wonder what the world would look like if all the things people think about macros were true (re-reading this one)
 
const functions in macros...
 
@DenysSéguret I often type ref mut foo instead of mut ref foo (I honestly am not sure which is right, now that I type it again). Is that what you mean?
 
@Shepmaster this too... but that wasn't what I was meaning. I meant the ref keyword is used so rarely it doesn't feel natural when you have to use it
There are probably whole rust programs without a ref
 
@DenysSéguret nowadays, yes :-)
BACK IN MY DAY...
 
Cool, I can pretend I'm the youngster
 
3:44 PM
I wish that removing ref was a clippy/rustfix thing
 
@DenysSéguret ref and @ both could be safely removed from the language
if I would ever get to the point where I have enough time to write an RFC about these, I would..
hopefully it will happen at the end of December..
 
@PeterVaro Are you sure you can today do all mutating pattern matchings without ref ?
 
I'm not sure of anything in this world, but so far all my test cases I came up with could be transformed into something that worked without the ref
 
@PeterVaro disagree
2
Q: Was Rust's ref keyword avoidable?

Joel BerkeleyWhy does Rust have the ref keyword? Could match value.try_thing() { &Some(ref e) => do_stuff(e), // ... } not be equally expressed by match value.try_thing() { &Some(e) => do_stuff(&e), // ... }

 
but then again, I think it requires more investigation
 
3:48 PM
The @ I think was possible, except that it can't be removed now
Since it's parsed as a token, it's used
5
Q: What does an @ symbol mean in a declarative macro?

Peter HallI have seen the @ symbol used in macros but I cannot find mention of it in the Rust Book or in any official documentation or blog posts. For example, in this Stack Overflow answer it is used like this: macro_rules! instructions { (enum $ename:ident { $($vname:ident ( $($vty: ty),* ))...

 
@Shepmaster I will take a look into this -- but I'm not promising it will happen any time soon, I don't have 5 extra minutes on my hands literally
 
said while chatting ;-)
 
(but anyway, I added this to my future RFCs folder)
@Shepmaster the irony, eh? ;)
 
I'm pretty sure that some pattern matching cannot be done without ref
 
@FrenchBoiethios that was the point I attempted to make in my answer; do you have any other examples I could add?
 
4:01 PM
Your answer shows that this keyword isn't needed in your example
I think that I've a better example: an enum where you want to move in some branch and take by reference in some others
 
@FrenchBoiethios Could you make that into a playground example?
(The more counter examples I have the better the chances to figure out whether my theory is correct..)
 
@PeterVaro Meh
 
4:16 PM
Maybe it's not needed. It could be removed in a further edition then :P
Let's try to merge a RFC
 
as I said, I will have time to work on this in the second half of December
I've been thinking about this for quite some time now
 
fn main() {
    let mut val = Some((1, 2));

    if let Some((ref mut a, mut b)) = &mut val {
        *a += 1;
        b += 1;
        println!("{}, {}", a, b);
    }

    println!("{:?}", val);
}
 
@Shepmaster What's your point?
 
@Shepmaster like this:
(very useful, I must say..)
:)
sorry, that's not the same..
 
@PeterVaro indeed
 
4:22 PM
fn main() {
    let mut val = Some((1, 2));

    if let Some((a, mut b)) = &mut val {
        *a += 1;
        b += 1;
        println!("{}, {}", a, b);
    }

    println!("{:?}", val);
}
but this is, isn't it?
2, 3 and then 2, 2
(I usually go to the more complex solution first, before I find the simpler one..)
 
does match outputs
What's annoying about this is that I've definitely attempted to remove ref from some code and failed
but cannot easily find that at the moment
 
as I said, I tried loads of examples before, I searched through the entire standard lib
and I was able to remove ref from most of them
(I haven't finished my work, but I will, as I mentioned above..)
but if you could help me and show me any counter examples I would really, really appreciate it
 
4:50 PM
but why do you write such thing ?
you really hate yourself :p
 
5:40 PM
Feedback requested...
@shepmaster, thanks for the link.but, I was just highlighting case where multi digit integer would not work. — basic_bgnr 1 min ago
So, the answer uses an inefficient algorithm
And I've now told the poster about it, but it seems they aren't interested in improving their answer.
I believe that people tend to copy-paste answers without much reading
so, what's a reasonable course of action?
Edit to change the algorithm seems too much
Downvoting seems half-acceptable
 
5:54 PM
nothing to do
but this code is stupid
 
I mean, I think it's inefficient, but the original problem is underspecified.
so handling multiple digit integers is possible
 
you could had why base 10
and many more
 
6:21 PM
fn main() {
    let a = vec![10, 20, 300];

    println!("{:?}", concat(&a));
}

fn magic(n: u32, acc: u32) -> u32 {
    let ret = n % 10;
    let n = n / 10;
    if n != 0 {
        magic(n, acc) * 10 + ret
    } else {
        acc * 10 + ret
    }
}

fn concat(vec: &[u32]) -> u32 {
    vec.iter()
        .copied()
        .fold(0, |acc, elem| magic(elem, acc))
}
 
7:03 PM
@LukasKalbertodt ಠ_ಠ
 
@Shepmaster Half the fun of asking these questions is waiting for your reaction 😀
 
 
1 hour later…
8:20 PM
ugh
pub trait Trait: Trait + Trait {
This is why we can't have nice things
 
Huh?
Just.. awful example code?
Ahhahahah
And.. it has... like, real, valid names for the... fields?
 
@Zarenor it's valid, and what the library has
each Trait is in a different module
 
Oh my god. I didn't realize (until I just followed the link) that this is
actual
library
code
Now I want to make
trait Trait: T + r + a + i + t {}
But maybe that's me being daft.
 
8:38 PM
@Zarenor gonna have to allow non-idiomatic names, so that's right out
 
XD
But 'Trait : Trait + Trait' technically passes the lint
(But not the laugh test)
 

« first day (1862 days earlier)      last day (1609 days later) »