Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

Using failure with #![termination_trait] (fn main() -> Result<T>) #130

Open
U007D opened this issue Jan 15, 2018 · 10 comments
Open

Using failure with #![termination_trait] (fn main() -> Result<T>) #130

U007D opened this issue Jan 15, 2018 · 10 comments

Comments

@U007D
Copy link
Contributor

U007D commented Jan 15, 2018

I'm running into a couple of issues trying to use failure with #![termination_trait].

#![feature(termination_trait)]

extern crate failure;

use std::io::{Error as IoError, ErrorKind as IoErrorKind};
use failure::{Fail, Error as FailureError};

type Result<T> = std::result::Result<T, Fail>;

fn main() -> Result<()> {
    Err(IoError::from(IoErrorKind::InvalidData))?
}

results in:

error[E0277]: the trait bound `failure::Fail + 'static: std::marker::Sized` is not satisfied
  --> src/main.rs:10:1
   |
10 | / fn main() -> Result<()> {
11 | |     Err(IoError::from(IoErrorKind::InvalidData))?
12 | | }
   | |_^ `failure::Fail + 'static` does not have a constant size known at compile-time
   |
   = help: the trait `std::marker::Sized` is not implemented for `failure::Fail + 'static`
   = note: required by `std::result::Result`

error: aborting due to previous error

Switching the Result declaration to type Result<T> = std::result::Result<T, FailureError> yields:

error[E0277]: the trait bound `failure::Error: std::error::Error` is not satisfied
  --> src/main.rs:15:25
   |
10 |   fn main() -> Result<()> {
   |  _________________________^
11 | |     Err(IoError::from(IoErrorKind::InvalidData))?
12 | | }
   | |_^ the trait `std::error::Error` is not implemented for `failure::Error`
   |
   = note: required because of the requirements on the impl of `std::Termination` for `std::result::Result<(), failure::Error>`

error: aborting due to previous error

Is there a solution for this? If not, should this be a failure or a termination_trait issue?

Many thanks,
U007D

@withoutboats
Copy link
Contributor

The issue you're getting is that you've used Fail as the error type, which is just a trait. You should use the Error type from failure instead, type Result<T> = Result<T, failure::Error>;.

I'll leave this open, please report back whether or not you run into more issues, I want to make sure failure works with this feature.

@U007D
Copy link
Contributor Author

U007D commented Jan 15, 2018

I tried it using failure::Error too. But I see now that I accidentally pasted the Fail error message twice--I'd intended to post the message from using failure::Error. I've fixed my original posting.

@withoutboats
Copy link
Contributor

It looks like the termination trait requires that we implement the old error type. This is unfortunate. :-(

@U007D
Copy link
Contributor Author

U007D commented Jan 16, 2018

Indeed. Although it is still feature-gated. I'm never sure where is the right place to leave comments, but the termination_trait PR is here. Is this issue something that you could weigh in on to help it be compatible with failure before stabilizing?

@bkchr
Copy link

bkchr commented Jan 17, 2018

When I finally have some time, I will improve the implementation to support failure :)

@U007D
Copy link
Contributor Author

U007D commented Jan 17, 2018

Hi, @bkchr,

Awesome, thank you. Is this something I could help with?

@bkchr
Copy link

bkchr commented Jan 17, 2018

It's just changing the implementation, I think we should go the way @withoutboats proposed by restricting the type to Debug.

@U007D
Copy link
Contributor Author

U007D commented Jan 17, 2018

Niko's recent "hacking on the compiler" writings inspired me to try building the compiler... So I forked rust and built it for the first time 🎉.

I ran ./x.py test before and after the change and got the same results both times. FYI, not all tests run because of a linker error; but of the ones that do run (hundreds), all pass except 1 (run-make/relocation-model).

https://github.com/U007D/rust/commit/b9b2ca8bd04e932a361adff2af813bd0f9f07e54

Assuming this diff looks right to you two, where should I target the PR? Back to rust-lang/rust/master? Or are you working from a branch that I should merge back to, @bkchr?

@bkchr
Copy link

bkchr commented Jan 18, 2018

@U007D Back to rust/master. My recent changes does not include anything you changed :)

@U007D
Copy link
Contributor Author

U007D commented Jan 18, 2018

Done.

bors referenced this issue in rust-lang/rust Feb 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants