These are chat archives for rust-lang/rust

Aug 2018
Hayden Flinner
Aug 12 2018 02:44

Hey all, I was working on a regex that captured ANSI escape sequences, and I kept getting this error:

error: unknown character escape: [
  --> src/
92 |         let escapeCodes = Regex::new("\x1b\[[0-9;]*[a-zA-Z]/").unwrap();
   |                                            ^

This was really frustrating (maybe because it's late), but after trying to get by without it I eventually realized I could escape the backslash with another one (using R raw-strings didn't help). In other languages, using raw strings would have fixed this ( I think, especially based on every example of this regex I've seen only having one backslash before the [). Would a compiler helper here that said that you have to escape the \ be helpful, or more confusing?

David Vo
Aug 12 2018 02:57
@haydenflinner what happened when you tried to use a raw string? from what I can tell, using a raw string there should work.
Hayden Flinner
Aug 12 2018 03:00
Trying an r"" string just now worked, the long sequence of errors I got with my first try (C++'s R"") makes me think I was probably trying R"" the whole time earlier. Stupid, stupid stupid C++ habits
When you use R instead of r, you get the 'unknown escape seq', then some other errors following that I've been conditioned by CPP to ignore since after the first error in CPP they rapidly get completely irrelevant
Hayden Flinner
Aug 12 2018 03:41
Guess while I'm here I misewell ask this rookie question:
        let mut putTheseBack = Vec::new();
        result = escapeCodes.replace_all(&line, |captures: &Captures| {
            return captures.get(0).map_or(String::new(), |m| {
error: borrowed data cannot be stored outside of its closure
   --> src/
102 |         let mut putTheseBack = Vec::new();
    |             ---------------- borrowed data cannot be stored into here...
103 |         result = escapeCodes.replace_all(&line, |captures: &Captures| {
    |                                                 --------------------- ...because it cannot outlive this closure
104 |             return captures.get(0).map_or(String::new(), |m| {
    |                             ^^^ cannot be stored outside of its closure
If I take out the putTheseBack.push, life's good, the borrow checker's happy. But what could be the issue with storing copies of the Match m?
Denis Lisov
Aug 12 2018 07:18
Looks like you don't need as_str
Aug 12 2018 08:08
Hello! I am wandering if there is a way to only run integration tests using cargo ? Couldn't figure that out in cargo test --help...
Andrey Lesnikov
Aug 12 2018 08:26
Try cargo test tests - it should filter out all tests that don't have "tests" in their full paths
Aug 12 2018 09:17
Thanks for the pointer @ozkriff ! for cargo test tests to only run my integration tests, i had to modify my unit test module to not contain the word tests.
Hayden Flinner
Aug 12 2018 12:16
thanks, that tfixed it for a little bit, but I'm giving up on the whole approach haha
Aug 12 2018 18:22
I was not able to read a non text environment variable. Is there an example for?
I mean not able to convert to a static in the main.
Aug 12 2018 19:49
Of course dotenv does that! :)
Aug 12 2018 20:29
let mut tree_builder = repository.treebuilder(None).unwrap();

// This doesn't work
let tree_entry = tree_builder.insert("empty.txt", oid, 0o100644).unwrap();

// This works
//tree_builder.insert("empty.txt", oid, 0o100644).unwrap();
error[E0502]: cannot borrow `tree_builder` as immutable because it is also borrowed as mutable
  --> tests/
20 |     let tree_entry = tree_builder.insert("empty.txt", oid, 0o100644).unwrap();
   |                      ------------ mutable borrow occurs here
21 |     //tree_builder.insert("empty.txt", oid, 0o100644).unwrap();
22 |     let tree_oid = tree_builder.write().unwrap();
   |                    ^^^^^^^^^^^^ immutable borrow occurs here
23 | }
Hello all,

I am using git2 crate .
I get the error when try to assign the result value to tree_entry.
If i don't assign the result to any vairable, it works fine.

I am wandering why does the compiler think i am still holding a mutable reference in this case? I couldn't figure that out from the souce code...

Aug 12 2018 21:05
Actually, dotenv is not able to convert a String to const usize. So unuseful!