]> git.lizzy.rs Git - rust.git/commitdiff
extend `where-allowed.rs` with many more cases
authorNiko Matsakis <niko@alum.mit.edu>
Mon, 13 Nov 2017 19:07:00 +0000 (14:07 -0500)
committerChristopher Vittal <christopher.vittal@gmail.com>
Wed, 15 Nov 2017 20:46:01 +0000 (15:46 -0500)
also merge disallowed and disallowed-2 into that set

src/test/compile-fail/impl-trait/disallowed-2.rs [deleted file]
src/test/compile-fail/impl-trait/disallowed.rs [deleted file]
src/test/compile-fail/impl-trait/where-allowed.rs

diff --git a/src/test/compile-fail/impl-trait/disallowed-2.rs b/src/test/compile-fail/impl-trait/disallowed-2.rs
deleted file mode 100644 (file)
index 46b3106..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-// 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 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![feature(conservative_impl_trait)]
-
-fn main() {
-    let _: impl Fn() = || {};
-    //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
-    let _ = || -> impl Fn() { || {} };
-    //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
-}
diff --git a/src/test/compile-fail/impl-trait/disallowed.rs b/src/test/compile-fail/impl-trait/disallowed.rs
deleted file mode 100644 (file)
index bf2e22a..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-// 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 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![feature(conservative_impl_trait)]
-
-type Factory<R> = impl Fn() -> R;
-//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
-
-type GlobalFactory<R> = 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
-}
-
-impl LazyToString for String {
-    fn lazy_to_string<'a>(&'a self) -> impl Fn() -> String {
-    //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
-        || self.clone()
-    }
-}
-
-#[derive(Copy, Clone)]
-struct Lazy<T>(T);
-
-impl std::ops::Add<Lazy<i32>> for Lazy<i32> {
-    type Output = impl Fn() -> Lazy<i32>;
-    //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
-
-    fn add(self, other: Lazy<i32>) -> Self::Output {
-        move || Lazy(self.0 + other.0)
-    }
-}
-
-impl<F> std::ops::Add<F>
-for impl Fn() -> Lazy<i32>
-//~^ 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() {}
index 5c2a8f89bf2e7494f8fc13ffdf7f77ab7a1e7918..be990b0e15d9690a92df403d3ba1fad680bf02a9 100644 (file)
 use std::fmt::Debug;
 
 // Allowed
-fn simple_universal(_: impl Debug) { panic!() }
+fn in_parameters(_: impl Debug) { panic!() }
 
 // Allowed
-fn simple_existential() -> impl Debug { panic!() }
+fn in_return() -> impl Debug { panic!() }
 
 // Allowed
-fn collection_universal(_: Vec<impl Debug>) { panic!() }
+fn in_adt_in_parameters(_: Vec<impl Debug>) { panic!() }
 
 // Allowed
-fn collection_existential() -> Vec<impl Debug> { panic!() }
+fn in_adt_in_return() -> Vec<impl Debug> { panic!() }
 
 // Disallowed
-fn fn_type_universal(_: fn(impl Debug)) { panic!() }
+fn in_fn_parameter_in_parameters(_: fn(impl Debug)) { panic!() }
 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 
 // Disallowed
-fn fn_type_existential() -> fn(impl Debug) { panic!() }
+fn in_fn_return_in_parameters(_: fn() -> impl Debug) { panic!() }
 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 
-// Allowed
-fn dyn_universal(_: &dyn Iterator<Item = impl Debug>) { panic!() }
+// Disallowed
+fn in_fn_parameter_in_return() -> fn(impl Debug) { panic!() }
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
+
+// Disallowed
+fn in_fn_return_in_return() -> fn() -> impl Debug { panic!() }
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
+
+// Disallowed
+fn in_dyn_Fn_parameter_in_parameters(_: &dyn Fn(impl Debug)) { panic!() }
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
+
+// Disallowed
+fn in_dyn_Fn_return_in_parameters(_: &dyn Fn() -> impl Debug) { panic!() }
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
+// FIXME -- no error currently
+
+// Disallowed
+fn in_dyn_Fn_parameter_in_return() -> &'static dyn Fn(impl Debug) { panic!() }
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
+
+// Disallowed
+fn in_dyn_Fn_return_in_return() -> &'static dyn Fn() -> impl Debug { panic!() }
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
+// FIXME -- no error currently
+
+// Disallowed
+fn in_impl_Fn_parameter_in_parameters(_: &impl Fn(impl Debug)) { panic!() }
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
+
+// Disallowed
+fn in_impl_Fn_return_in_parameters(_: &impl Fn() -> impl Debug) { panic!() }
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
+// FIXME -- no error currently
 
 // Disallowed
-fn dyn_fn_trait(_: &dyn Fn(impl Debug)) { panic!() }
+fn in_impl_Fn_parameter_in_return() -> &'static impl Fn(impl Debug) { panic!() }
 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 
+// Disallowed
+fn in_impl_Fn_return_in_return() -> &'static impl Fn() -> impl Debug { panic!() }
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
+// FIXME -- no error currently
+
 // Allowed
-fn nested_universal(_: impl Iterator<Item = impl Iterator>) { panic!() }
+fn in_impl_Trait_in_parameters(_: impl Iterator<Item = impl Iterator>) { panic!() }
 
 // Allowed
-fn nested_existential() -> impl IntoIterator<Item = impl IntoIterator> {
+fn in_impl_Trait_in_return() -> impl IntoIterator<Item = impl IntoIterator> {
     vec![vec![0; 10], vec![12; 7], vec![8; 3]]
 }
 
 // Disallowed
-fn universal_fn_trait(_: impl Fn(impl Debug)) { panic!() }
+struct InBraceStructField { x: impl Debug }
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
+
+// Disallowed
+struct InAdtInBraceStructField { x: Vec<impl Debug> }
 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 
 // Disallowed
-struct ImplMember { x: impl Debug }
+struct InTupleStructField(impl Debug);
 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 
 // Disallowed
-trait Universal {
-    // FIXME, should error?
-    fn universal(impl Debug);
+enum InEnum {
+    InBraceVariant { x: impl Debug },
+    //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
+    InTupleVariant(impl Debug),
+    //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
+}
+
+// Allowed
+trait InTraitDefnParameters {
+    fn in_parameters(_: impl Debug);
 }
 
 // Disallowed
-trait Existential {
-    fn existential() -> impl Debug;
+trait InTraitDefnReturn {
+    fn in_return() -> impl Debug;
+    //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
+}
+
+// Allowed and disallowed in trait impls
+trait DummyTrait {
+    type Out;
+    fn in_trait_impl_parameter(impl Debug);
+    fn in_trait_impl_return() -> Self::Out;
+}
+impl DummyTrait for () {
+    type Out = impl Debug;
+    //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
+
+    fn in_trait_impl_parameter(_: impl Debug) { }
+    // Allowed
+
+    fn in_trait_impl_return() -> impl Debug { () }
+    //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
+}
+
+// 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);
+    //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
+    // FIXME currently allowed
+
+    fn in_foreign_return() -> impl Debug;
+    //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
+    // FIXME currently allowed
+}
+
+// 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;
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
+
+type InReturnInTypeAlias<R> = fn() -> impl Debug;
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
+
+// Disallowed in impl headers
+impl PartialEq<impl Debug> for () {
+    //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
+}
+
+// Disallowed in impl headers
+impl PartialEq<()> for impl Debug {
+    //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
+}
+
+// Disallowed in inherent impls
+impl impl Debug {
+    //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
+}
+
+// Disallowed in inherent impls
+struct InInherentImplAdt<T> { t: T }
+impl InInherentImplAdt<impl Debug> {
+    //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
+}
+
+// Disallowed in where clauses
+fn in_fn_where_clause()
+    where impl Debug: Debug
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
+{
+}
+
+// Disallowed in where clauses
+fn in_adt_in_fn_where_clause()
+    where Vec<impl Debug>: Debug
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
+{
+}
+
+// Disallowed
+fn in_trait_parameter_in_fn_where_clause<T>()
+    where T: PartialEq<impl Debug>
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
+{
+}
+
+// Disallowed
+fn in_Fn_parameter_in_fn_where_clause<T>()
+    where T: Fn(impl Debug)
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
+{
+}
+
+// Disallowed
+fn in_Fn_return_in_fn_where_clause<T>()
+    where T: Fn() -> impl Debug
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
+{
+}
+
+fn main() {
+    let _in_local_variable: impl Fn() = || {};
+    //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
+    let _in_return_in_local_variable = || -> impl Fn() { || {} };
     //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 }
 
-fn main() {}