These are chat archives for rust-lang/rust

20th
Jul 2017
Jonas Platte
@jplatte
Jul 20 2017 07:56
@dualmoon vec.iter().filter(|x| *x == elem).count()
Michal 'vorner' Vaner
@vorner
Jul 20 2017 08:39
Hello. I'm wondering, what tricks are known to speed up the compile-test-write cycle? I know it is something being worked on. I have incremental compilation enabled and use nighly, use cargo check when I don't need to run it. I know I could split the codebase into sub-crates with a workspace. Is there some other trick I'm missing?
Chrizzly
@Chris2011
Jul 20 2017 09:01

Hi, I have problems with my code, the code was written for rust 1.0.0 alpha, I tried to use 1.17.0 and 1.18.0 to compile it but I got this error:

Running command: [rustc, --out-dir, target\rust-libs, src\main\rust\com\github\drrb\javarust\lib\javarustbridge.rs]
error[E0432]: unresolved import rustc::middle::ty::CtxtArenas
--> src\main\rust\com\github\drrb\javarust\lib\compiler.rs:2:5
|
2 | use rustc::middle::ty::CtxtArenas;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Could not find ty in middle

It happens here: use rustc::middle::ty::CtxtArenas;. I don't think that you need the whole code, but let me knows it if you need it. Can someone help me to figure the problem out? Do I have to install a specific package?

Denis Lisov
@tanriol
Jul 20 2017 09:20
The compiler internals are not available in stable Rust...
Unfortunately, I don't know that part, but the CtxtArenas have been split in commit 0e43b378c11d1f575a06607b4264ab07cd2cc79c
Chrizzly
@Chris2011
Jul 20 2017 09:25
Yeah I saw that this is unstable. Ok
so it should work with a nightly version, maybe?
Denis Lisov
@tanriol
Jul 20 2017 09:35
I'm pretty sure there were significant changes in the compiler internals since 1.0.0 alphas. Do you really need to revive that plugin and not create something better, say, RLS-based?
Chrizzly
@Chris2011
Jul 20 2017 09:35
The problem is, that I wanted to build it and try it out but and of course to use it. After it didn't worked, I wanted to refactor it, but I don't have any knowledge about rust. I only wanted to be a user of this plugin.
At the end, I want to get it working.
unfortunately the original developer is not responding...
but yeah it seems so that this is not working at all before a big refactoring...
Denis Lisov
@tanriol
Jul 20 2017 09:43
If you want to support Rust in an IDE (in your case, NetBeans?), I'd suggest integrating with RLS
There's a bug for language server protocol support in NetBeans, but looks like no progress yet.
Chrizzly
@Chris2011
Jul 20 2017 09:47
Yes I know, atm the only plugin who supports it is NBTS (TypeScript for NetBeans). Maybe the developer started Rust as RLS because there are some rs files already in the code. And the javarustbridge.rs is the file who compiles, sry who tries to compile ^^
Btw, it was me who created the bugzilla ticket :D
I'm Chrizzly, ChrisLe, Chris2011 etc.
anyway
Michal 'vorner' Vaner
@vorner
Jul 20 2017 10:04
You probably still could download that alpha version of the compiler. I don't know since when, but the old releases are available.
Denis Lisov
@tanriol
Jul 20 2017 10:08
@vorner And limit language used in your projects to what was supported then? Feels like a quite bad idea...
Michal 'vorner' Vaner
@vorner
Jul 20 2017 10:08
Well, if the idea was to simply run it, not modify it...
Also, if the only other option is „throw it out“, even a bad idea is an option.
Denis Lisov
@tanriol
Jul 20 2017 10:09
The project he's trying to revive is IDE support for NetBeans which embeds the Rust compiler
And if your IDE support produces diagnostics according to a pre-1.0 language version... it's not exactly usable, IMO.
Michal 'vorner' Vaner
@vorner
Jul 20 2017 10:11
Of course. But it could be an option to get something started and then start experimenting with it, or switching the internals to something else. Or to determine if it is completely lost battle.
If you can compile it, see what it does, experiment with it, then porting to something newer might be easier.
Chrizzly
@Chris2011
Jul 20 2017 10:45
Yes I thought about it to use the old alpha version or younger ones, to test whether it will happen there too.
Thx for the info.
lemonxah
@lemonxah
Jul 20 2017 13:52
been trying to google, read some git issues but not sure what the final state was of HKT in rust
is that something that might still make it into the language or its too hard to get right?
Sergey Noskov
@Albibek
Jul 20 2017 13:54
afaik it awaits another middle representation layer(Chalk) to be implemented
stevensonmt
@stevensonmt
Jul 20 2017 14:01
when testing a regex on a site like regex101.com, what is the closest engine to rust's, golang?
lemonxah
@lemonxah
Jul 20 2017 14:07
is there a way to match on a ref?
Max Frai
@max-frai
Jul 20 2017 14:07
@stevensonmt go
@lemonxah match { Some(ref data) => ... } ?
stevensonmt
@stevensonmt
Jul 20 2017 14:08
thanks, that's what I assumed.
lemonxah
@lemonxah
Jul 20 2017 14:09
impl<A: Semigroup> Semigroup for Option<A> {
    fn mappend(&self, other: &Self) -> Self {
        match (*self, *other) {
            (None, b) => b,
            (a, None) => a,
            (Some(a), Some(b)) => Some(a.mappend(b)),
        }
    }
}
@max-frai as i understand the match wants to move .. then you get cannot move out of borrowed content
but i dont want to move my data into this function
Max Frai
@max-frai
Jul 20 2017 14:11
can you show the error message?
lemonxah
@lemonxah
Jul 20 2017 14:12
src/fun/semigroup/mod.rs|11 col 16 error 507| cannot move out of borrowed content
and when not using the * i get src/fun/semigroup/mod.rs|12 col 14 error 308| mismatched types
Denis Lisov
@tanriol
Jul 20 2017 14:16
You don't need the *
lemonxah
@lemonxah
Jul 20 2017 14:16
ok but then it doesn't match the types of None and Some
Max Frai
@max-frai
Jul 20 2017 14:16
ref b, ref a ?
Denis Lisov
@tanriol
Jul 20 2017 14:16
Then you need to modify the patterns... something like (&None, b) => b
And (&Some(ref a), &Some(ref b)) => Some(a.mappend(b))
i am sorry if this is a stupid question i am still learning :)
but how do you go from &A to A
Denis Lisov
@tanriol
Jul 20 2017 14:27
Ouch. Seems like I've missed the main problem.
lemonxah
@lemonxah
Jul 20 2017 14:28
yeah sorry i thought it be best if i put it in a playground
stevensonmt
@stevensonmt
Jul 20 2017 14:28
I'm trying to get what seems like a simple regex match of any string that ends with ? followed by zero or more whitespace characters. It matches here but not when I run a test locally. Suggestions?
Denis Lisov
@tanriol
Jul 20 2017 14:29
@lemonxah Something like this
Max Frai
@max-frai
Jul 20 2017 14:32
@stevensonmt show the code
stevensonmt
@stevensonmt
Jul 20 2017 14:34
extern crate regex;

use regex::Regex;

pub fn reply(prompt: &str) -> String {
    let question = Regex::new(r"\?\s*$").unwrap();
    let yelling = Regex::new(r"^[A-Z\s*]+[%\^\*@#\$*\(\s]*[^a-z]*$|[^a-z][0-9]*!$").unwrap();
    let silence = Regex::new(r"\s+$").unwrap();

    let reply = match silence.is_match(prompt) || prompt.len() == 0 {
                true => "Fine. Be that way!",
                _ => match question.is_match(prompt) {
                    true => match yelling.is_match(prompt) {
                        true => "Whoa, chill out!",
                        _ => "Sure.",
                    },
                    _ => match yelling.is_match(prompt) {
                        true => "Whoa, chill out!",
                        _ => "Whatever.",
                    },
                },
            };
    String::from(reply)
}
This is from the exercism/rust bob exercise. It matches correctly for every test except the question ending in whitespace and the statement ending with whitespace.
Nevermind. It was the silence regex that was missing the first caret.
So they were matching as silence first. Dumb.
Zakarum
@omni-viral
Jul 20 2017 15:04
I have a stupid question.
I need to split a slice. Handle left part. Assign right part to the original variable. Loop until slice is empty.
Everything goes OK for &[T]
But in case of &mut [T] borrow checker fails
What should I do?
Zakarum
@omni-viral
Jul 20 2017 15:10
error[E0506]: cannot assign to `slice` because it is borrowed
  --> src/main.rs:20:9
   |
20 |         slice = foo(slice);
   |         ^^^^^^^^^^^^-----^
   |         |           |
   |         |           borrow of `slice` occurs here
   |         assignment to borrowed `slice` occurs here
slice has type &mut. So to forbit reusing it is borrowed. But I don't want to reuse it. I want to reassign it
Zakarum
@omni-viral
Jul 20 2017 15:18
Although I can write an ugly workaround using Option
https://play.rust-lang.org/?gist=6c5132634eaec26050979ea78b31ba76&version=stable
Zakarum
@omni-viral
Jul 20 2017 15:24
hmmm. If I just rebind reference before borrowing then I can reassign previous reference
slice = slice.split_at_mut(0).1; // Borrow check failed
slice = { let slice = slice; slice.split_at_mut(0).1 }; // OK
stevensonmt
@stevensonmt
Jul 20 2017 16:36
Are you sure that works? Seems like it would go out of scope.
Joonas Koivunen
@koivunej
Jul 20 2017 18:37
does anyone remember or know if there is an RFC describing how the panic and unwinding is implemented?
Michal 'vorner' Vaner
@vorner
Jul 20 2017 19:26
I can't say for sure, but I think there wouldn't be. Partly because the panicking is rather old, but mostly, the RFCs describe how the language should look like and act, not how to accomplish that. There isn't an RFC on how this or that optimisation is implemented or what data structures the borrow checker uses.
Joonas Koivunen
@koivunej
Jul 20 2017 19:28
i did find a closed issue on "rfc on how panic works" or what ever it was called but to clarify, I was after the "unwinding" part, in which order drops are called etc
Michal 'vorner' Vaner
@vorner
Jul 20 2017 19:29
I'd bet on the same order as in normal function exit. Otherwise lifetimes or other things could get broken.
Therefore, the intermost function first, and in the reverse order of creation.
Joonas Koivunen
@koivunej
Jul 20 2017 19:31
yes, that's what my intution says as well. I was just hoping to find a reference :)
Michal 'vorner' Vaner
@vorner
Jul 20 2017 19:35
Well, if the rust book can be taken as a reference… https://doc.rust-lang.org/book/first-edition/drop.html it says they get dropped in the reverse order. It doesn't say „if it doesn't panic“, or any other exception, so I'd assume always in the reverse order.
Joonas Koivunen
@koivunej
Jul 20 2017 19:37
@vorner oh nice, didn't think to check drop part of the book. thanks!
vorner @vorner also looked at the reference, but that one is very brief around that
Joonas Koivunen
@koivunej
Jul 20 2017 19:40
it'd look like there is no more LIFO hints in the second-edition
Michal 'vorner' Vaner
@vorner
Jul 20 2017 19:49
This one talks about the order in which elements of structs are dropped, but only hints at local variables being dropped in LIFO order. It doesn't say where that comes from, though. https://github.com/rust-lang/rfcs/blob/e2f6b2022345fd5aa6136859b219c8be967120c7/text/1857-stabilize-drop-order.md
Daan Rijks
@ijks
Jul 20 2017 19:59
Did you try the Rustonomicon yet? https://doc.rust-lang.org/nomicon/
Joonas Koivunen
@koivunej
Jul 20 2017 20:05
@ijks it is not in the unwinding part at least; I settled on the first-edition/drop.html