// Copyright 2016 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 or the MIT license // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. #![feature(conservative_impl_trait)] fn arguments(_: impl Fn(), //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types _: Vec) {} //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types type Factory = impl Fn() -> R; //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types type GlobalFactory = fn() -> impl FnOnce() -> R; //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types trait LazyToString { fn lazy_to_string<'a>(&'a self) -> impl Fn() -> String; //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types } // Note that the following impl doesn't error, because the trait is invalid. impl LazyToString for String { fn lazy_to_string<'a>(&'a self) -> impl Fn() -> String { || self.clone() } } #[derive(Copy, Clone)] struct Lazy(T); impl std::ops::Add> for Lazy { type Output = impl Fn() -> Lazy; //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types fn add(self, other: Lazy) -> Self::Output { move || Lazy(self.0 + other.0) } } impl std::ops::Add for impl Fn() -> Lazy //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types where F: Fn() -> impl FnOnce() -> i32 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types { type Output = Self; fn add(self, other: F) -> Self::Output { move || Lazy(self().0 + other()()) } } fn main() {}