Could not compile `thread_local`


#1

Hi guys, I am getting this error while trying to run my project:

{ gic2chomsky-rust } master » cr
   Compiling thread_local v0.3.3
C:\Users\lgutierr\.babun\cygwin\home\lgutierr\.cargo\registry\src\github.com-88ac128001ac3a9a\thread_local-0.3.3\src\lib.rs:84:5: 84:27 error: unresolved import `std::panic::UnwindSafe`. There is no `UnwindSafe` in `std::panic` [E0432]
C:\Users\lgutierr\.babun\cygwin\home\lgutierr\.cargo\registry\src\github.com-88ac128001ac3a9a\thread_local-0.3.3\src\lib.rs:84 use std::panic::UnwindSafe;
                                                                                                                                   ^~~~~~~~~~~~~~~~~~~~~~
C:\Users\lgutierr\.babun\cygwin\home\lgutierr\.cargo\registry\src\github.com-88ac128001ac3a9a\thread_local-0.3.3\src\lib.rs:84:5: 84:27 help: run `rustc --explain E0432` to see a detailed explanation
C:\Users\lgutierr\.babun\cygwin\home\lgutierr\.cargo\registry\src\github.com-88ac128001ac3a9a\thread_local-0.3.3\src\lib.rs:386:25: 386:35 error: `UnwindSafe` is not a trait [E0404]
C:\Users\lgutierr\.babun\cygwin\home\lgutierr\.cargo\registry\src\github.com-88ac128001ac3a9a\thread_local-0.3.3\src\lib.rs:386 impl<T: ?Sized + Send + UnwindSafe> UnwindSafe for ThreadLocal<T> {}
                                                                                                                                                        ^~~~~~~~~~
C:\Users\lgutierr\.babun\cygwin\home\lgutierr\.cargo\registry\src\github.com-88ac128001ac3a9a\thread_local-0.3.3\src\lib.rs:386:25: 386:35 help: run `rustc --explain E0404` to see a detailed explanation
C:\Users\lgutierr\.babun\cygwin\home\lgutierr\.cargo\registry\src\github.com-88ac128001ac3a9a\thread_local-0.3.3\src\lib.rs:386:37: 386:47 error: `UnwindSafe` is not a trait [E0404]
C:\Users\lgutierr\.babun\cygwin\home\lgutierr\.cargo\registry\src\github.com-88ac128001ac3a9a\thread_local-0.3.3\src\lib.rs:386 impl<T: ?Sized + Send + UnwindSafe> UnwindSafe for ThreadLocal<T> {}
                                                                                                                                                                    ^~~~~~~~~~
C:\Users\lgutierr\.babun\cygwin\home\lgutierr\.cargo\registry\src\github.com-88ac128001ac3a9a\thread_local-0.3.3\src\lib.rs:386:37: 386:47 help: run `rustc --explain E0404` to see a detailed explanation
C:\Users\lgutierr\.babun\cygwin\home\lgutierr\.cargo\registry\src\github.com-88ac128001ac3a9a\thread_local-0.3.3\src\lib.rs:597:25: 597:35 error: `UnwindSafe` is not a trait [E0404]
C:\Users\lgutierr\.babun\cygwin\home\lgutierr\.cargo\registry\src\github.com-88ac128001ac3a9a\thread_local-0.3.3\src\lib.rs:597 impl<T: ?Sized + Send + UnwindSafe> UnwindSafe for CachedThreadLocal<T> {}
                                                                                                                                                        ^~~~~~~~~~
C:\Users\lgutierr\.babun\cygwin\home\lgutierr\.cargo\registry\src\github.com-88ac128001ac3a9a\thread_local-0.3.3\src\lib.rs:597:25: 597:35 help: run `rustc --explain E0404` to see a detailed explanation
C:\Users\lgutierr\.babun\cygwin\home\lgutierr\.cargo\registry\src\github.com-88ac128001ac3a9a\thread_local-0.3.3\src\lib.rs:597:37: 597:47 error: `UnwindSafe` is not a trait [E0404]
C:\Users\lgutierr\.babun\cygwin\home\lgutierr\.cargo\registry\src\github.com-88ac128001ac3a9a\thread_local-0.3.3\src\lib.rs:597 impl<T: ?Sized + Send + UnwindSafe> UnwindSafe for CachedThreadLocal<T> {}
                                                                                                                                                                    ^~~~~~~~~~
C:\Users\lgutierr\.babun\cygwin\home\lgutierr\.cargo\registry\src\github.com-88ac128001ac3a9a\thread_local-0.3.3\src\lib.rs:597:37: 597:47 help: run `rustc --explain E0404` to see a detailed explanation
error: cannot continue compilation due to previous error
Could not compile `thread_local`.

To learn more, run the command again with --verbose.
{ gic2chomsky-rust } master »

{ gic2chomsky-rust } master » cargo --version
cargo 0.9.0-nightly (8fc3fd8 2016-02-29)
{ gic2chomsky-rust } master » rustc --version
rustc 1.8.0 (db2939409 2016-04-11)

this is the code I was trying:

use std::fmt;
use std::collections::HashMap;
use std::collections::HashSet;
use regex::Regex;

extern crate regex;

#[derive(Debug)]
struct Chomsky<'a> {
    normal_forms: HashSet<&'a str>,
    productions: Vec<&'a str>
}

#[derive(Debug)]
struct Element<'a> {
    chomsky: &'a str,
    defined: bool
}

#[derive(Debug)]
struct CasePart<'a> {
    a: &'a str,
    b: &'a str
}

impl<'a> fmt::Display for CasePart<'a> {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "CasePart[a:{}, b: {}]", self.a, self.b)
    }
}

fn create(gic: &str) -> HashMap<&str, Vec<&str>> {
    let mut elements: Vec<&str> = Vec::new();
    let mut pending_elements_to_define: Vec<Element> = Vec::new();
    HashMap::new()
}

struct Generator;
impl Generator {
    fn generate<'a>(gic: &str, letter: &str) -> Chomsky<'a> {
        Chomsky {normal_forms: HashSet::new(), productions: vec!["X"]}
    }
}

impl<'a> fmt::Display for Element<'a> {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "Element[chomsky:{}, defined: {}]", self.chomsky, self.defined)
    }
}

impl<'a> fmt::Display for Chomsky<'a> {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        try!(write!(f, "normal_forms["));
        
        for nf in &self.normal_forms {
            write!(f, "({})", nf);
        }

        try!(write!(f, "], productions["));

        for p in &self.productions {
            try!(write!(f, "({})", p));
        }

        write!(f, "]")
    }
}

fn get_case_from_production<'a>(case_str: &'a str) -> &'a str {
    let cases: Vec<&str> = case_str.splitn(2, "->").collect::<Vec<&str>>();
    cases[1]
}

fn get_cases<'a>(production: &'a str) -> Vec<&'a str> {
    let cases: Vec<&'a str> = production.split("|").collect::<Vec<&str>>();
    cases
}

fn is_chomsky(s: &str) -> bool {
    let re = Regex::new(r"^([a-z]|[A-Z]{2})$").unwrap();
    re.is_match(s)
}

fn is_terminal(s: &str) -> bool {
    let re = Regex::new(r"^[A-Z]$").unwrap();
    re.is_match(s)
}

fn generate_elements_information_for_gic<'a>(
    gic: &'a str, elements: &mut Vec<&'a str>, 
    pending_elements_to_define: Vec<Element>) {
    for gic_case in &get_cases(get_case_from_production(gic)) {
        if is_chomsky(gic_case) {
            println!("gic_case: {}", gic_case);
            elements.push(gic_case);
        } else {
            let cp: CasePart = create_casepart_from(gic_case);

            if is_terminal(cp.a) {
                elements.push(cp.a);
            } else {
                let mut non_terminal: String = String::from("{");
                non_terminal.push_str(cp.a);
                non_terminal.push_str("}");

                elements.push(&non_terminal);
                // pending_elements_to_define.push(El)
            }
        }
    }
}

fn create_casepart_from(gic_case: &str) -> CasePart {
    let len = gic_case.len();
    CasePart {a: prefix(gic_case, len), b: sufix(gic_case, len)}
}

fn prefix(s: &str, k: usize) -> &str {
    &s[..k]
}

fn sufix(s: &str, k: usize) -> &str {
    &s[k..]
}

fn main() {

    // let my_string: String = "leonardo".to_string();
    // let same = prefix(&my_string, 3) == prefix(&my_string, 2);
    // println!("{}", same);

    /*
    let len: usize = my_string.len();
    println!("{}", prefix(&my_string, len / 2));

    println!("{}", sufix(&my_string, len / 2));
    */

    /*
    let s: &str = "S->ab|aaB|x";
    println!("thing: {}", get_case_from_production(&s));
    */

    // This prints ab\naaB
    /*
    for e in &get_cases(get_case_from_production(&s)) {
        println!("e: {}", e);
    }

    println!("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
    */

    /*
    println!("Value: {}", is_chomsky("a"));
    println!("Value: {}", is_chomsky("aa"));
    println!("Value: {}", is_chomsky("A"));
    println!("Value: {}", is_chomsky("AA"));
    */

}

#2

What version of Rust are you using. It looks like it’s older than what’s supported by thread_local.


#3
{ ~ }  » rustc --version
rustc 1.8.0 (db2939409 2016-04-11)
{ ~ }  » cargo --version
cargo 0.9.0-nightly (8fc3fd8 2016-02-29)

#4

It looks like the crate requires 1.9.0 or higher: https://github.com/Amanieu/thread_local-rs/blob/master/.travis.yml#L8


#5

How can specify 1.9.0 for my project?


#6

Sorry, I thought you were talking about a specific version of thread_local or another package.


#7

I am trying to install the latest version but I am getting this error:

C:\Users\lgutierr\Downloads>rustup-init.exe

Rust Visual C++ prerequisites

Rust requires the Microsoft C++ build tools for Visual Studio 2013 or later,
but they don't seem to be installed.

The easiest way to acquire the build tools is by installing Microsoft Visual
C++ Build Tools 2015 which provides just the Visual C++ build tools:

  http://landinghub.visualstudio.com/visual-cpp-build-tools

Alternately, you can install Visual Studio 2015 or Visual Studio 2013 and
during install select the "C++ tools":

  https://www.visualstudio.com/downloads/

Install the C++ build tools before proceeding.

If you will be targetting the GNU ABI or otherwise know what you are doing then
it is fine to continue installation without the build tools, but otherwise,
install the C++ build tools before proceeding.

Continue? (Y/n) Y


Welcome to Rust!

This will download and install the official compiler for the Rust programming
language, and its package manager, Cargo.

It will add the cargo, rustc, rustup and other commands to Cargo's bin
directory, located at:

  C:\Users\lgutierr\.cargo\bin

This path will then be added to your PATH environment variable by modifying the
HKEY_CURRENT_USER/Environment/PATH registry key.

You can uninstall at any time with rustup self uninstall and these changes will
be reverted.

Current installation options:

   default host triple: x86_64-pc-windows-msvc
     default toolchain: stable
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation


info: syncing channel updates for 'stable-x86_64-pc-windows-msvc'
error: could not download file from 'https://static.rust-lang.org/dist/channel-rust-stable.toml.sha256' to 'C:\Users\lgutierr\.rustup\tmp\kjjlkyurezyd4uzo_file
info: caused by: error during download
info: caused by: [7] Couldn't connect to server (Failed to connect to static.rust-lang.org port 443: Connection refused)

Press the Enter key to continue.

#8

static.rust-lang.org works for me. Maybe it was a temporary glitch? Does the problem persist? Then it’s perhaps a networking issue at your end.