about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChristopher Vittal <christopher.vittal@gmail.com>2017-11-10 13:02:06 -0500
committerChristopher Vittal <christopher.vittal@gmail.com>2017-11-15 15:46:01 -0500
commit06dff800614cab4e662ace032a2e61568db8bbdf (patch)
tree3ad71f55d103de486295c360751e24919a05c917
parentbdff9463a0afbbdcd52825ead6b6f9f1245652db (diff)
downloadrust-06dff800614cab4e662ace032a2e61568db8bbdf.tar.gz
rust-06dff800614cab4e662ace032a2e61568db8bbdf.zip
Add/Modify tests for argument position impl Trait
-rw-r--r--src/test/compile-fail/impl-trait/disallowed.rs5
-rw-r--r--src/test/compile-fail/impl-trait/impl-generic-mismatch.rs32
-rw-r--r--src/test/compile-fail/impl-trait/many-cases.rs71
-rw-r--r--src/test/run-pass/impl-trait/equality-universal.rs39
-rw-r--r--src/test/run-pass/impl-trait/example-calendar.rs31
-rw-r--r--src/test/rustdoc/issue-43869.rs4
6 files changed, 160 insertions, 22 deletions
diff --git a/src/test/compile-fail/impl-trait/disallowed.rs b/src/test/compile-fail/impl-trait/disallowed.rs
index 0467c49b031..bf2e22aa8e6 100644
--- a/src/test/compile-fail/impl-trait/disallowed.rs
+++ b/src/test/compile-fail/impl-trait/disallowed.rs
@@ -10,11 +10,6 @@
 
 #![feature(conservative_impl_trait)]
 
-fn arguments(_: impl Fn(),
-//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
-             _: Vec<impl Clone>) {}
-//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
-
 type Factory<R> = impl Fn() -> R;
 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 
diff --git a/src/test/compile-fail/impl-trait/impl-generic-mismatch.rs b/src/test/compile-fail/impl-trait/impl-generic-mismatch.rs
new file mode 100644
index 00000000000..41583d3b795
--- /dev/null
+++ b/src/test/compile-fail/impl-trait/impl-generic-mismatch.rs
@@ -0,0 +1,32 @@
+// Copyright 2017 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(universal_impl_trait)]
+use std::fmt::Debug;
+
+trait Foo {
+    fn foo(&self, &impl Debug);
+}
+
+impl Foo for () {
+    fn foo<U: Debug>(&self, _: &U) { }
+    //~^ Error method `foo` has incompatible signature for trait
+}
+
+trait Bar {
+    fn bar<U: Debug>(&self, &U);
+}
+
+impl Bar for () {
+    fn bar(&self, _: &impl Debug) { }
+    //~^ Error method `bar` has incompatible signature for trait
+}
+
+fn main() {}
diff --git a/src/test/compile-fail/impl-trait/many-cases.rs b/src/test/compile-fail/impl-trait/many-cases.rs
new file mode 100644
index 00000000000..5c2a8f89bf2
--- /dev/null
+++ b/src/test/compile-fail/impl-trait/many-cases.rs
@@ -0,0 +1,71 @@
+// Copyright 2017 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.
+
+//! A simple test for testing many permutations of allowedness of
+//! impl Trait
+#![feature(conservative_impl_trait, universal_impl_trait, dyn_trait)]
+use std::fmt::Debug;
+
+// Allowed
+fn simple_universal(_: impl Debug) { panic!() }
+
+// Allowed
+fn simple_existential() -> impl Debug { panic!() }
+
+// Allowed
+fn collection_universal(_: Vec<impl Debug>) { panic!() }
+
+// Allowed
+fn collection_existential() -> Vec<impl Debug> { panic!() }
+
+// Disallowed
+fn fn_type_universal(_: 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!() }
+//~^ 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 dyn_fn_trait(_: &dyn Fn(impl Debug)) { panic!() }
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
+
+// Allowed
+fn nested_universal(_: impl Iterator<Item = impl Iterator>) { panic!() }
+
+// Allowed
+fn nested_existential() -> 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!() }
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
+
+// Disallowed
+struct ImplMember { x: 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);
+}
+
+// Disallowed
+trait Existential {
+    fn existential() -> impl Debug;
+    //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
+}
+
+fn main() {}
diff --git a/src/test/run-pass/impl-trait/equality-universal.rs b/src/test/run-pass/impl-trait/equality-universal.rs
new file mode 100644
index 00000000000..ccf24b77a6b
--- /dev/null
+++ b/src/test/run-pass/impl-trait/equality-universal.rs
@@ -0,0 +1,39 @@
+// Copyright 2017 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(universal_impl_trait)]
+use std::fmt::Display;
+
+fn check_display_eq(iter: impl IntoIterator<Item = impl Display>) {
+    let mut collected = String::new();
+    for it in iter {
+        let disp = format!("{} ", it);
+        collected.push_str(&disp);
+    }
+    assert_eq!("0 3 27 823 4891 1 0", collected.trim());
+}
+
+fn main() {
+    let i32_list = [0i32, 3, 27, 823, 4891, 1, 0];
+    let i32_list_vec = vec![0i32, 3, 27, 823, 4891, 1, 0];
+    let u32_list = [0u32, 3, 27, 823, 4891, 1, 0];
+    let u32_list_vec = vec![0u32, 3, 27, 823, 4891, 1, 0];
+    let u16_list = [0u16, 3, 27, 823, 4891, 1, 0];
+    let str_list = ["0", "3", "27", "823", "4891", "1", "0"];
+    let str_list_vec = vec!["0", "3", "27", "823", "4891", "1", "0"];
+
+    check_display_eq(&i32_list);
+    check_display_eq(i32_list_vec);
+    check_display_eq(&u32_list);
+    check_display_eq(u32_list_vec);
+    check_display_eq(&u16_list);
+    check_display_eq(&str_list);
+    check_display_eq(str_list_vec);
+}
diff --git a/src/test/run-pass/impl-trait/example-calendar.rs b/src/test/run-pass/impl-trait/example-calendar.rs
index 84d86cfdf65..0b612c2d3ff 100644
--- a/src/test/run-pass/impl-trait/example-calendar.rs
+++ b/src/test/run-pass/impl-trait/example-calendar.rs
@@ -1,4 +1,4 @@
-// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// Copyright 2016-2017 The Rust Project Developers. See the COPYRIGHT
 // file at the top-level directory of this distribution and at
 // http://rust-lang.org/COPYRIGHT.
 //
@@ -8,7 +8,12 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(conservative_impl_trait, fn_traits, step_trait, unboxed_closures)]
+#![feature(conservative_impl_trait,
+           universal_impl_trait,
+           fn_traits,
+           step_trait,
+           unboxed_closures
+)]
 
 //! Derived from: <https://raw.githubusercontent.com/quickfur/dcal/master/dcal.d>.
 //!
@@ -457,9 +462,9 @@ fn test_group_by() {
 ///
 /// Groups an iterator of dates by month.
 ///
-fn by_month<It>(it: It)
-                ->  impl Iterator<Item=(u32, impl Iterator<Item=NaiveDate> + Clone)> + Clone
-where It: Iterator<Item=NaiveDate> + Clone {
+fn by_month(it: impl Iterator<Item=NaiveDate> + Clone)
+           ->  impl Iterator<Item=(u32, impl Iterator<Item=NaiveDate> + Clone)> + Clone
+{
     it.group_by(|d| d.month())
 }
 
@@ -474,9 +479,9 @@ fn test_by_month() {
 ///
 /// Groups an iterator of dates by week.
 ///
-fn by_week<It>(it: It)
-               -> impl Iterator<Item=(u32, impl DateIterator)> + Clone
-where It: DateIterator {
+fn by_week(it: impl DateIterator)
+          -> impl Iterator<Item=(u32, impl DateIterator)> + Clone
+{
     // We go forward one day because `isoweekdate` considers the week to start on a Monday.
     it.group_by(|d| d.succ().isoweekdate().1)
 }
@@ -548,8 +553,7 @@ const COLS_PER_WEEK: u32 = 7 * COLS_PER_DAY;
 ///
 /// Formats an iterator of weeks into an iterator of strings.
 ///
-fn format_weeks<It>(it: It) -> impl Iterator<Item=String>
-where It: Iterator, It::Item: DateIterator {
+fn format_weeks(it: impl Iterator<Item = impl DateIterator>) -> impl Iterator<Item=String> {
     it.map(|week| {
         let mut buf = String::with_capacity((COLS_PER_DAY * COLS_PER_WEEK + 2) as usize);
 
@@ -627,7 +631,7 @@ fn test_month_title() {
 ///
 /// Formats a month.
 ///
-fn format_month<It: DateIterator>(it: It) -> impl Iterator<Item=String> {
+fn format_month(it: impl DateIterator) -> impl Iterator<Item=String> {
     let mut month_days = it.peekable();
     let title = month_title(month_days.peek().unwrap().month());
 
@@ -659,8 +663,9 @@ fn test_format_month() {
 ///
 /// Formats an iterator of months.
 ///
-fn format_months<It>(it: It) -> impl Iterator<Item=impl Iterator<Item=String>>
-where It: Iterator, It::Item: DateIterator {
+fn format_months(it: impl Iterator<Item = impl DateIterator>)
+                -> impl Iterator<Item=impl Iterator<Item=String>>
+{
     it.map(format_month)
 }
 
diff --git a/src/test/rustdoc/issue-43869.rs b/src/test/rustdoc/issue-43869.rs
index 4670c5386c8..70a5a7a3f7a 100644
--- a/src/test/rustdoc/issue-43869.rs
+++ b/src/test/rustdoc/issue-43869.rs
@@ -55,9 +55,6 @@ pub fn test_44731_1() -> Result<Box<impl Clone>, ()> {
     Ok(Box::new(j()))
 }
 
-pub fn test_44731_2() -> Box<Fn(impl Clone)> {
-    Box::new(|_: u32| {})
-}
 
 pub fn test_44731_3() -> Box<Fn() -> impl Clone> {
     Box::new(|| 0u32)
@@ -78,6 +75,5 @@ pub fn test_44731_4() -> Box<Iterator<Item=impl Clone>> {
 // @has issue_43869/fn.o.html
 // @has issue_43869/fn.test_44731_0.html
 // @has issue_43869/fn.test_44731_1.html
-// @has issue_43869/fn.test_44731_2.html
 // @has issue_43869/fn.test_44731_3.html
 // @has issue_43869/fn.test_44731_4.html