From 06dff800614cab4e662ace032a2e61568db8bbdf Mon Sep 17 00:00:00 2001 From: Christopher Vittal Date: Fri, 10 Nov 2017 13:02:06 -0500 Subject: Add/Modify tests for argument position impl Trait --- src/test/compile-fail/impl-trait/disallowed.rs | 5 -- .../impl-trait/impl-generic-mismatch.rs | 32 ++++++++++ src/test/compile-fail/impl-trait/many-cases.rs | 71 ++++++++++++++++++++++ 3 files changed, 103 insertions(+), 5 deletions(-) create mode 100644 src/test/compile-fail/impl-trait/impl-generic-mismatch.rs create mode 100644 src/test/compile-fail/impl-trait/many-cases.rs (limited to 'src/test/compile-fail') 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) {} -//~^ 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 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 or the MIT license +// , 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(&self, _: &U) { } + //~^ Error method `foo` has incompatible signature for trait +} + +trait Bar { + fn bar(&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 or the MIT license +// , 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) { panic!() } + +// Allowed +fn collection_existential() -> Vec { 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) { 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) { panic!() } + +// Allowed +fn nested_existential() -> 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() {} -- cgit 1.4.1-3-g733a5