Rustfmt: -> impl Trait not supported

Created on 8 Sep 2016  路  12Comments  路  Source: rust-lang/rustfmt

I get this error

src/main.rs:11:38: 11:42 error: expected type, found keyword `impl`
src/main.rs:11    fn long_running_future(a: u32) -> impl Future<Item = u32, Error = ()> { futures::done(Ok(a)) }
                                                    ^~~~

while trying to format the following bit of code that compiles and runs just fine

#![feature(conservative_impl_trait)]

extern crate futures;
extern crate futures_cpupool;

use std::sync::mpsc::channel;
use futures::Future;
use futures_cpupool::CpuPool;

fn long_running_future(a: u32) -> impl Future<Item = u32, Error = ()> { futures::done(Ok(a)) }


fn main() {

    // Create a worker thread pool with four threads
    let pool = CpuPool::new(4);

    // Execute some work on the thread pool, optionally closing over data.
    let a = pool.spawn(long_running_future(2));
    let b = pool.spawn(long_running_future(100));

    // Express some further computation once the work is completed on the thread
    // pool.
    let c = a.join(b).map(|(a, b)| a + b).wait().unwrap();

    // Print out the result
    println!("{:?}", c);
}
good first issue

Most helpful comment

I have a branch with the Syntex update almost ready, once that lands, this should be easy to fix.

All 12 comments

see also #1145

Someone with knowledge of all the changes in syntex_syntax (this project is now ten version behind) needs to do the upgrade - I attempted it but its non-trivial

I have a branch with the Syntex update almost ready, once that lands, this should be easy to fix.

A fast fix:
file src/types.rs
change :
ast::TyKind::ImplTrait(..) => Some(String::from("impl TODO")),

to:
ast::TyKind::ImplTrait(ref it) => it.rewrite(context, width, offset).map(|it_str| format!("impl {}", it_str)),

Is this available in a release? I see that play no longer messes up impl trait, but I know that I recently updated and still saw this behavior.

@nikomatsakis it should be in the release I did at the weekend (0.6.3, iirc).

@nikomatsakis Has this resurfaced? I'm seeing -> impl Future<> converted into impl TODO in the latest nightly.

@wagerlabs I can't reproduce that, I'm getting impl Future just fine

@nrc What's your rustfmt version? I'm getting this behavior with 0.6.2.

Upgrading to 0.9 via cargo install rustfmt --force fixes this.

0.6 is pretty old. I'm using master, which is nightly-0.1.4

@nrc How do you keep rustfmt in sync with nightly builds? Do you cargo install rustfmt-nightly --force periodically?

@wagerlabs I think you have to, yes. (I actually build from source pretty much every day, so I'm not a good person to ask about this)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MoSal picture MoSal  路  5Comments

gnzlbg picture gnzlbg  路  3Comments

tkilbourn picture tkilbourn  路  5Comments

cramertj picture cramertj  路  4Comments

ratmice picture ratmice  路  3Comments