"try!" macro stops working after rust update

Here is a simple test file that still works in a manner:

use std::num;
use std::str::FromStr;
use std::convert::From;

#[derive(Debug)]
struct Error(String);

impl From<num::ParseFloatError> for Error {
    fn from(err: num::ParseFloatError) -> Error {
        Error(format!("{}", err))
    }
}

fn parse(s: &String) -> Result<f64, Error> {
    Ok(try!(<f64 as FromStr>::from_str(&s[..])))
}

fn main() {
    println!("{:?}", parse(&"10.01".to_string()));
}

However, after I built the last rustc from git (now it rustc 1.1.0-dev (1114fcd94 2015-04-23)), it stopped compiling with the following error:

<std macros>:6:1: 6:32 error: the trait `core::convert::From<core::num::ParseFloatError>` is not implemented for the type `Error` [E0277]
<std macros>:6 $ crate:: convert:: From:: from ( err ) ) } } )
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<std macros>:1:1: 6:48 note: in expansion of try!
exp.rs:15:8: 15:48 note: expansion site
error: aborting due to previous error

I can’t find out what happened. Why can't the compiler find my attribute implementation?

+4
source share
1 answer

This seems to be a mistake: std::num::ParseFloatErrorand <f64 as FromStr>::Errare different types:

impl From<num::ParseFloatError> for Error , <f64 as FromStr>::from_str(...) .

# 24748 . # 24747 , .

, core::num::ParseFloatError. core extern crate core; .

+4

Source: https://habr.com/ru/post/1584325/


All Articles