2017-11-10 12:02:06 -06:00
|
|
|
//! A simple test for testing many permutations of allowedness of
|
|
|
|
//! impl Trait
|
2022-07-28 15:18:32 -05:00
|
|
|
#![feature(impl_trait_in_fn_trait_return)]
|
2017-11-10 12:02:06 -06:00
|
|
|
use std::fmt::Debug;
|
|
|
|
|
|
|
|
// Allowed
|
2017-11-13 13:07:00 -06:00
|
|
|
fn in_parameters(_: impl Debug) { panic!() }
|
2017-11-10 12:02:06 -06:00
|
|
|
|
|
|
|
// Allowed
|
2017-11-13 13:07:00 -06:00
|
|
|
fn in_return() -> impl Debug { panic!() }
|
2017-11-10 12:02:06 -06:00
|
|
|
|
|
|
|
// Allowed
|
2017-11-13 13:07:00 -06:00
|
|
|
fn in_adt_in_parameters(_: Vec<impl Debug>) { panic!() }
|
2017-11-10 12:02:06 -06:00
|
|
|
|
|
|
|
// Disallowed
|
2017-11-13 13:07:00 -06:00
|
|
|
fn in_fn_parameter_in_parameters(_: fn(impl Debug)) { panic!() }
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2017-11-10 12:02:06 -06:00
|
|
|
|
|
|
|
// Disallowed
|
2017-11-13 13:07:00 -06:00
|
|
|
fn in_fn_return_in_parameters(_: fn() -> impl Debug) { panic!() }
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2017-11-10 12:02:06 -06:00
|
|
|
|
2017-11-13 13:07:00 -06:00
|
|
|
// Disallowed
|
|
|
|
fn in_fn_parameter_in_return() -> fn(impl Debug) { panic!() }
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2017-11-13 13:07:00 -06:00
|
|
|
|
|
|
|
// Disallowed
|
|
|
|
fn in_fn_return_in_return() -> fn() -> impl Debug { panic!() }
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2017-11-13 13:07:00 -06:00
|
|
|
|
|
|
|
// Disallowed
|
|
|
|
fn in_dyn_Fn_parameter_in_parameters(_: &dyn Fn(impl Debug)) { panic!() }
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2017-11-13 13:07:00 -06:00
|
|
|
|
|
|
|
// Disallowed
|
|
|
|
fn in_dyn_Fn_return_in_parameters(_: &dyn Fn() -> impl Debug) { panic!() }
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2017-11-13 13:07:00 -06:00
|
|
|
|
|
|
|
// Disallowed
|
|
|
|
fn in_dyn_Fn_parameter_in_return() -> &'static dyn Fn(impl Debug) { panic!() }
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2017-11-13 13:07:00 -06:00
|
|
|
|
2022-02-02 06:09:44 -06:00
|
|
|
// Allowed
|
2017-11-13 13:07:00 -06:00
|
|
|
fn in_dyn_Fn_return_in_return() -> &'static dyn Fn() -> impl Debug { panic!() }
|
|
|
|
|
|
|
|
// Disallowed
|
|
|
|
fn in_impl_Fn_parameter_in_parameters(_: &impl Fn(impl Debug)) { panic!() }
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2018-02-08 17:40:27 -06:00
|
|
|
//~^^ ERROR nested `impl Trait` is not allowed
|
2017-11-13 13:07:00 -06:00
|
|
|
|
|
|
|
// Disallowed
|
|
|
|
fn in_impl_Fn_return_in_parameters(_: &impl Fn() -> impl Debug) { panic!() }
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2017-11-10 12:02:06 -06:00
|
|
|
|
|
|
|
// Disallowed
|
2017-11-13 13:07:00 -06:00
|
|
|
fn in_impl_Fn_parameter_in_return() -> &'static impl Fn(impl Debug) { panic!() }
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2019-09-24 13:05:49 -05:00
|
|
|
//~| ERROR nested `impl Trait` is not allowed
|
2017-11-10 12:02:06 -06:00
|
|
|
|
2022-02-02 06:09:44 -06:00
|
|
|
// Allowed
|
2017-11-13 13:07:00 -06:00
|
|
|
fn in_impl_Fn_return_in_return() -> &'static impl Fn() -> impl Debug { panic!() }
|
2017-11-14 19:38:07 -06:00
|
|
|
|
|
|
|
// Disallowed
|
|
|
|
fn in_Fn_parameter_in_generics<F: Fn(impl Debug)> (_: F) { panic!() }
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2017-11-14 19:38:07 -06:00
|
|
|
|
|
|
|
// Disallowed
|
|
|
|
fn in_Fn_return_in_generics<F: Fn() -> impl Debug> (_: F) { panic!() }
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2017-11-14 19:38:07 -06:00
|
|
|
|
2017-11-13 13:07:00 -06:00
|
|
|
|
2017-11-10 12:02:06 -06:00
|
|
|
// Allowed
|
2017-11-13 13:07:00 -06:00
|
|
|
fn in_impl_Trait_in_parameters(_: impl Iterator<Item = impl Iterator>) { panic!() }
|
2017-11-10 12:02:06 -06:00
|
|
|
|
|
|
|
// Allowed
|
2017-11-13 13:07:00 -06:00
|
|
|
fn in_impl_Trait_in_return() -> impl IntoIterator<Item = impl IntoIterator> {
|
2017-11-10 12:02:06 -06:00
|
|
|
vec![vec![0; 10], vec![12; 7], vec![8; 3]]
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disallowed
|
2017-11-13 13:07:00 -06:00
|
|
|
struct InBraceStructField { x: impl Debug }
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2017-11-13 13:07:00 -06:00
|
|
|
|
|
|
|
// Disallowed
|
|
|
|
struct InAdtInBraceStructField { x: Vec<impl Debug> }
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2017-11-10 12:02:06 -06:00
|
|
|
|
|
|
|
// Disallowed
|
2017-11-13 13:07:00 -06:00
|
|
|
struct InTupleStructField(impl Debug);
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2017-11-10 12:02:06 -06:00
|
|
|
|
|
|
|
// Disallowed
|
2017-11-13 13:07:00 -06:00
|
|
|
enum InEnum {
|
|
|
|
InBraceVariant { x: impl Debug },
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2017-11-13 13:07:00 -06:00
|
|
|
InTupleVariant(impl Debug),
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2017-11-13 13:07:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Allowed
|
|
|
|
trait InTraitDefnParameters {
|
|
|
|
fn in_parameters(_: impl Debug);
|
2017-11-10 12:02:06 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Disallowed
|
2017-11-13 13:07:00 -06:00
|
|
|
trait InTraitDefnReturn {
|
|
|
|
fn in_return() -> impl Debug;
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2017-11-13 13:07:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Allowed and disallowed in trait impls
|
|
|
|
trait DummyTrait {
|
|
|
|
type Out;
|
2018-08-11 12:44:35 -05:00
|
|
|
fn in_trait_impl_parameter(_: impl Debug);
|
2017-11-13 13:07:00 -06:00
|
|
|
fn in_trait_impl_return() -> Self::Out;
|
|
|
|
}
|
|
|
|
impl DummyTrait for () {
|
|
|
|
type Out = impl Debug;
|
2019-07-31 18:41:54 -05:00
|
|
|
//~^ ERROR `impl Trait` in type aliases is unstable
|
2017-11-13 13:07:00 -06:00
|
|
|
|
|
|
|
fn in_trait_impl_parameter(_: impl Debug) { }
|
|
|
|
// Allowed
|
|
|
|
|
|
|
|
fn in_trait_impl_return() -> impl Debug { () }
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2017-11-13 13:07:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Allowed
|
|
|
|
struct DummyType;
|
|
|
|
impl DummyType {
|
|
|
|
fn in_inherent_impl_parameters(_: impl Debug) { }
|
|
|
|
fn in_inherent_impl_return() -> impl Debug { () }
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disallowed
|
|
|
|
extern "C" {
|
|
|
|
fn in_foreign_parameters(_: impl Debug);
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2017-11-13 13:07:00 -06:00
|
|
|
|
|
|
|
fn in_foreign_return() -> impl Debug;
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2017-11-13 13:07:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Allowed
|
|
|
|
extern "C" fn in_extern_fn_parameters(_: impl Debug) {
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allowed
|
|
|
|
extern "C" fn in_extern_fn_return() -> impl Debug {
|
|
|
|
22
|
|
|
|
}
|
|
|
|
|
|
|
|
type InTypeAlias<R> = impl Debug;
|
2019-07-31 18:41:54 -05:00
|
|
|
//~^ ERROR `impl Trait` in type aliases is unstable
|
2017-11-13 13:07:00 -06:00
|
|
|
|
|
|
|
type InReturnInTypeAlias<R> = fn() -> impl Debug;
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2019-11-07 13:12:34 -06:00
|
|
|
//~| ERROR `impl Trait` in type aliases is unstable
|
2017-11-13 13:07:00 -06:00
|
|
|
|
|
|
|
// Disallowed in impl headers
|
|
|
|
impl PartialEq<impl Debug> for () {
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2017-11-13 13:07:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Disallowed in impl headers
|
|
|
|
impl PartialEq<()> for impl Debug {
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2017-11-13 13:07:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Disallowed in inherent impls
|
|
|
|
impl impl Debug {
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2017-11-13 13:07:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Disallowed in inherent impls
|
|
|
|
struct InInherentImplAdt<T> { t: T }
|
|
|
|
impl InInherentImplAdt<impl Debug> {
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2017-11-13 13:07:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Disallowed in where clauses
|
|
|
|
fn in_fn_where_clause()
|
|
|
|
where impl Debug: Debug
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2017-11-13 13:07:00 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disallowed in where clauses
|
|
|
|
fn in_adt_in_fn_where_clause()
|
|
|
|
where Vec<impl Debug>: Debug
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2017-11-13 13:07:00 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disallowed
|
|
|
|
fn in_trait_parameter_in_fn_where_clause<T>()
|
|
|
|
where T: PartialEq<impl Debug>
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2017-11-13 13:07:00 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disallowed
|
|
|
|
fn in_Fn_parameter_in_fn_where_clause<T>()
|
|
|
|
where T: Fn(impl Debug)
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2017-11-13 13:07:00 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disallowed
|
|
|
|
fn in_Fn_return_in_fn_where_clause<T>()
|
|
|
|
where T: Fn() -> impl Debug
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2017-11-13 13:07:00 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-04-06 10:21:08 -05:00
|
|
|
// Disallowed
|
|
|
|
struct InStructGenericParamDefault<T = impl Debug>(T);
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2021-04-06 10:21:08 -05:00
|
|
|
|
|
|
|
// Disallowed
|
|
|
|
enum InEnumGenericParamDefault<T = impl Debug> { Variant(T) }
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2021-04-06 10:21:08 -05:00
|
|
|
|
|
|
|
// Disallowed
|
|
|
|
trait InTraitGenericParamDefault<T = impl Debug> {}
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2021-04-06 10:21:08 -05:00
|
|
|
|
|
|
|
// Disallowed
|
|
|
|
type InTypeAliasGenericParamDefault<T = impl Debug> = T;
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2021-04-06 10:21:08 -05:00
|
|
|
|
|
|
|
// Disallowed
|
|
|
|
impl <T = impl Debug> T {}
|
|
|
|
//~^ ERROR defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
|
|
|
|
//~| WARNING this was previously accepted by the compiler but is being phased out
|
2022-02-17 21:18:42 -06:00
|
|
|
//~| ERROR `impl Trait` only allowed in function and inherent method return types
|
2021-07-20 22:23:22 -05:00
|
|
|
//~| ERROR no nominal type found
|
2021-04-06 10:21:08 -05:00
|
|
|
|
|
|
|
// Disallowed
|
|
|
|
fn in_method_generic_param_default<T = impl Debug>(_: T) {}
|
|
|
|
//~^ ERROR defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
|
|
|
|
//~| WARNING this was previously accepted by the compiler but is being phased out
|
2022-02-17 21:18:42 -06:00
|
|
|
//~| ERROR `impl Trait` only allowed in function and inherent method return types
|
2021-04-06 10:21:08 -05:00
|
|
|
|
2017-11-13 13:07:00 -06:00
|
|
|
fn main() {
|
|
|
|
let _in_local_variable: impl Fn() = || {};
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2017-11-13 13:07:00 -06:00
|
|
|
let _in_return_in_local_variable = || -> impl Fn() { || {} };
|
2022-02-17 21:18:42 -06:00
|
|
|
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
|
2017-11-10 12:02:06 -06:00
|
|
|
}
|