These are chat archives for rust-lang/rust

20th
Oct 2018
Jie Liu
@icyhat
Oct 20 2018 02:09
Hello, there
Sebastian
@sertel
Oct 20 2018 10:43
@tanriol Can I have a look at the implementation of ? somehwere?
I’m interested whether ? is implemented via a “macro_rules”-macro. I would like to know if it is possible to write a macro that matches on a more advanced pattern. Something like:
macro_rules! try {
                ($var:ident = $expr:expr?; $($rest:expr);+) => …
}
David Vo
@auscompgeek
Oct 20 2018 10:49
@sertel since it's a language feature, it's implemented at the grammar level. it's not implemented using a macro.
Sebastian
@sertel
Oct 20 2018 10:49
Ah ok!
Thanks for that hint @auscompgeek
Denis Lisov
@tanriol
Oct 20 2018 10:49
Not a macro, the desugaring lives here
Sebastian
@sertel
Oct 20 2018 10:51
Oh, I see ? desugars to try
Denis Lisov
@tanriol
Oct 20 2018 10:51
Actually it desugars to a match
David Vo
@auscompgeek
Oct 20 2018 10:52
Say, does try! expand to ? nowadays?
Denis Lisov
@tanriol
Oct 20 2018 10:53
No, it does not, this one is a simple match on Result (source)
Sebastian
@sertel
Oct 20 2018 10:54
Ok, so the implementation of try actually moved into the desugaring pass
Is it possible for developers to provide their own desugaring passes?
Denis Lisov
@tanriol
Oct 20 2018 10:55
Don't mix up the matters :-) try! is a normal macro_rules! macro, while ? is implemented in the lowering pass.
No custom lowering passes, sorry.
Sebastian
@sertel
Oct 20 2018 13:38
Thanks for your help! (I know of course that try! is a macro_rules! but it expands to a match statement. Most likely the very same one that ? desugars to.)
Denis Lisov
@tanriol
Oct 20 2018 13:40
Not the very same one. try! is limited to Result and nothing else, while ? desugars to a match using the Try trait, which can be used with Result, Option and in the future possibly other types.
Sebastian
@sertel
Oct 20 2018 13:40
Ah ok, I was not aware of that.
Michael(LAI)
@Michael-Lfx
Oct 20 2018 16:32
Finally I managed to emulate Rust to the behavior of C++ version. But I am wandering whether there is an ideal solution. At first I tried lazy_static but it cannot replace the currentManager itself. https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=68b126dd172d1f14c3241f873b2af271
static SyncManager *currentManager = nullptr;
SyncManager *GetcurrentManager()
{
    return currentManager;
}

void SetcurrentManager(SyncManager *manager)
{
    currentManager = manager;
}
// normal usage
glWaintSync() {
    SyncManager *current = GetcurrentManager();
    if (current) {
        // do something
    }
}
Michal 'vorner' Vaner
@vorner
Oct 20 2018 16:43
I'm wondering. The target subdirectories tend to grow to somewhat large sizes. And they take space in my backups and I don't feel like I need to back up these. Is there a tool that somehow manages that ‒ grabs them, moves them to some other place that is not being backed up and symlinks it there, maybe even with some timed clean ups? I mean, I can put a bit of shell together to do just that, but a ready made solution would be more comfortable if someone knew of one.
Thiez
@Thiez
Oct 20 2018 16:45
Can't you configure your backups to omit certain folders? Otherwise you can look into this feature: rust-lang/cargo#1657
Michal 'vorner' Vaner
@vorner
Oct 20 2018 16:46
No, I can't, my backup tool is based on btrfs subvolumes. I mean, I could manually create a subvolume in each target directory, but that's manual a thing.
Thiez
@Thiez
Oct 20 2018 16:48
Okay, well if I understand the PR I just linked to correctly, you can set an environment variable that tells cargo where to build stuff. The downside is that stuff can go wrong when you run multiple builds concurrently with the same target folder
otherwise perhaps you can perhaps do something like alias cargo to CARGO_TARGET_DIR = /path/to/location/that/is/not/backed/up/$(basename $(pwd)) cargo or something along those lines
Thiez
@Thiez
Oct 20 2018 16:58
Do let me know if it works for you, I haven't tried this feature yet and would be interested if it works. If you find a good solution and you are so inclined you might even write a blog post about it, it sounds like the kind of thing that the people on r/rust would upvote ;)
Denis Lisov
@tanriol
Oct 20 2018 17:38
@Michael-Lfx Looks absolutely unsafe. Even you aren't using it in a safe way yourself.
Denis Lisov
@tanriol
Oct 20 2018 18:06
@Michael-Lfx You do understand that in your playground both contexts are dropped at the end of the unsafe blocks, and in blocks 3-6 you're touching freed memory, don't you?
Michal 'vorner' Vaner
@vorner
Oct 20 2018 18:08
@Thiez I know of that one and I use that for some other reason. The problem with running multiple builds in parallel is gone (they have locks now) and it works fine. But I don't think putting the target completely away would be comfortable if I have to eg. go looking for the build binary. I'll hack something together, but I'm not aiming at a good solution. I'm probably aiming for a quick and dirty as hell solution, so no bragging about that one 😇
Tyler J. Laing
@ZerothLaw
Oct 20 2018 18:47
Hi. I think I've found a bug in macros, but want to see if it is one first: https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=1a4e0c24f2e11a10539122693de91793
Nevermind, its the attributes itself, not the macro.