From 7213ef1a8fd3cb7e479d53fdb287c6c612b9fb93 Mon Sep 17 00:00:00 2001 From: Flavio Percoco Date: Tue, 27 Jan 2015 01:07:31 +0100 Subject: [PATCH] Test all the things --- .../coherence-default-trait-impl.rs | 25 ++++++++++ .../syntaxt-default-trait-impls.rs | 18 +++++++ ...-default-trait-impl-constituent-types-2.rs | 30 +++++++++++ ...ck-default-trait-impl-constituent-types.rs | 36 +++++++++++++ ...typeck-default-trait-impl-negation-send.rs | 31 ++++++++++++ ...typeck-default-trait-impl-negation-sync.rs | 50 +++++++++++++++++++ .../typeck-default-trait-impl-negation.rs | 42 ++++++++++++++++ ...typeck-default-trait-impl-outside-crate.rs | 18 +++++++ src/test/pretty/default-trait-impl.rs | 19 +++++++ 9 files changed, 269 insertions(+) create mode 100644 src/test/compile-fail/coherence-default-trait-impl.rs create mode 100644 src/test/compile-fail/syntaxt-default-trait-impls.rs create mode 100644 src/test/compile-fail/typeck-default-trait-impl-constituent-types-2.rs create mode 100644 src/test/compile-fail/typeck-default-trait-impl-constituent-types.rs create mode 100644 src/test/compile-fail/typeck-default-trait-impl-negation-send.rs create mode 100644 src/test/compile-fail/typeck-default-trait-impl-negation-sync.rs create mode 100644 src/test/compile-fail/typeck-default-trait-impl-negation.rs create mode 100644 src/test/compile-fail/typeck-default-trait-impl-outside-crate.rs create mode 100644 src/test/pretty/default-trait-impl.rs diff --git a/src/test/compile-fail/coherence-default-trait-impl.rs b/src/test/compile-fail/coherence-default-trait-impl.rs new file mode 100644 index 000000000000..bcc3353ba020 --- /dev/null +++ b/src/test/compile-fail/coherence-default-trait-impl.rs @@ -0,0 +1,25 @@ +// Copyright 2015 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. + +// ignore-tidy-linelength + +#![feature(optin_builtin_traits)] + +trait MyTrait {} + +impl MyTrait for .. {} + +impl MyTrait for .. {} +//~^ ERROR conflicting implementations for trait `MyTrait` + +impl MyTrait for (i32, i32) {} +//~^ ERROR implementations for traits providing default implementations are only allowed on + +fn main() {} diff --git a/src/test/compile-fail/syntaxt-default-trait-impls.rs b/src/test/compile-fail/syntaxt-default-trait-impls.rs new file mode 100644 index 000000000000..a33cd0edca5b --- /dev/null +++ b/src/test/compile-fail/syntaxt-default-trait-impls.rs @@ -0,0 +1,18 @@ +// Copyright 2015 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(optin_builtin_traits)] + +trait MyDefaultImpl {} + +impl MyDefaultImpl for .. {} +//~^ ERROR default trait implementations are not allowed to have genercis + +fn main() {} diff --git a/src/test/compile-fail/typeck-default-trait-impl-constituent-types-2.rs b/src/test/compile-fail/typeck-default-trait-impl-constituent-types-2.rs new file mode 100644 index 000000000000..a27f7f7ebbe0 --- /dev/null +++ b/src/test/compile-fail/typeck-default-trait-impl-constituent-types-2.rs @@ -0,0 +1,30 @@ +// Copyright 2015 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(optin_builtin_traits)] + +trait MyTrait {} + +impl MyTrait for .. {} + +struct MyS; + +struct MyS2; + +impl !MyTrait for MyS2 {} + +fn is_mytrait() {} + +fn main() { + is_mytrait::(); + + is_mytrait::<(MyS2, MyS)>(); + //~^ ERROR the trait `MyTrait` is not implemented for the type `MyS2` +} diff --git a/src/test/compile-fail/typeck-default-trait-impl-constituent-types.rs b/src/test/compile-fail/typeck-default-trait-impl-constituent-types.rs new file mode 100644 index 000000000000..556a0a1a0f34 --- /dev/null +++ b/src/test/compile-fail/typeck-default-trait-impl-constituent-types.rs @@ -0,0 +1,36 @@ +// Copyright 2015 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(optin_builtin_traits)] + +trait MyTrait {} + +impl MyTrait for .. {} +impl !MyTrait for *mut T {} + +struct MyS; + +struct MyS2; + +impl !MyTrait for MyS2 {} + +struct MyS3; + +fn is_mytrait() {} + +fn main() { + is_mytrait::(); + + is_mytrait::(); + //~^ ERROR the trait `MyTrait` is not implemented for the type `MyS2` + + is_mytrait::>(); + //~^ ERROR the trait `MyTrait` is not implemented for the type `*mut MyS3` +} diff --git a/src/test/compile-fail/typeck-default-trait-impl-negation-send.rs b/src/test/compile-fail/typeck-default-trait-impl-negation-send.rs new file mode 100644 index 000000000000..db4d1fe485b3 --- /dev/null +++ b/src/test/compile-fail/typeck-default-trait-impl-negation-send.rs @@ -0,0 +1,31 @@ +// Copyright 2015 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(optin_builtin_traits)] + +struct MySendable { + t: *mut u8 +} + +unsafe impl Send for MySendable {} + +struct MyNotSendable { + t: *mut u8 +} + +impl !Send for MyNotSendable {} + +fn is_send() {} + +fn main() { + is_send::(); + is_send::(); + //~^ ERROR the trait `core::marker::Send` is not implemented for the type `MyNotSendable` +} diff --git a/src/test/compile-fail/typeck-default-trait-impl-negation-sync.rs b/src/test/compile-fail/typeck-default-trait-impl-negation-sync.rs new file mode 100644 index 000000000000..d613589e7d77 --- /dev/null +++ b/src/test/compile-fail/typeck-default-trait-impl-negation-sync.rs @@ -0,0 +1,50 @@ +// Copyright 2015 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. + +// ignore-tidy-linelength + +#![feature(optin_builtin_traits)] + +use std::marker::Managed; +use std::cell::UnsafeCell; + +struct MySync { + t: *mut u8 +} + +unsafe impl Sync for MySync {} + +struct MyNotSync { + t: *mut u8 +} + +impl !Sync for MyNotSync {} + +struct MyTypeWUnsafe { + t: UnsafeCell +} + +struct MyTypeManaged { + t: Managed +} + +fn is_sync() {} + +fn main() { + is_sync::(); + is_sync::(); + //~^ ERROR the trait `core::marker::Sync` is not implemented for the type `MyNotSync` + + is_sync::(); + //~^ ERROR the trait `core::marker::Sync` is not implemented for the type `core::cell::UnsafeCell` + + is_sync::(); + //~^ ERROR the trait `core::marker::Sync` is not implemented for the type `core::marker::Managed` +} diff --git a/src/test/compile-fail/typeck-default-trait-impl-negation.rs b/src/test/compile-fail/typeck-default-trait-impl-negation.rs new file mode 100644 index 000000000000..4b91d0b7a736 --- /dev/null +++ b/src/test/compile-fail/typeck-default-trait-impl-negation.rs @@ -0,0 +1,42 @@ +// Copyright 2015 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(optin_builtin_traits)] + +trait MyTrait {} + +impl MyTrait for .. {} + +unsafe trait MyUnsafeTrait {} + +unsafe impl MyUnsafeTrait for .. {} + +struct ThisImplsTrait; + +impl !MyUnsafeTrait for ThisImplsTrait {} + + +struct ThisImplsUnsafeTrait; + +impl !MyTrait for ThisImplsUnsafeTrait {} + +fn is_my_trait() {} +fn is_my_unsafe_trait() {} + +fn main() { + is_my_trait::(); + is_my_trait::(); + //~^ ERROR the trait `MyTrait` is not implemented for the type `ThisImplsUnsafeTrait` + + is_my_unsafe_trait::(); + //~^ ERROR the trait `MyUnsafeTrait` is not implemented for the type `ThisImplsTrait` + + is_my_unsafe_trait::(); +} diff --git a/src/test/compile-fail/typeck-default-trait-impl-outside-crate.rs b/src/test/compile-fail/typeck-default-trait-impl-outside-crate.rs new file mode 100644 index 000000000000..10ba8c741648 --- /dev/null +++ b/src/test/compile-fail/typeck-default-trait-impl-outside-crate.rs @@ -0,0 +1,18 @@ +// Copyright 2015 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. + +// ignore-tidy-linelength + +#![feature(optin_builtin_traits)] + +impl Copy for .. {} +//~^ ERROR cannot create default implementations for traits outside the crate they're defined in; define a new trait instead. + +fn main() {} diff --git a/src/test/pretty/default-trait-impl.rs b/src/test/pretty/default-trait-impl.rs new file mode 100644 index 000000000000..a5246b9300c9 --- /dev/null +++ b/src/test/pretty/default-trait-impl.rs @@ -0,0 +1,19 @@ +// Copyright 2014 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(optin_builtin_traits)] + +// pp-exact + +trait MyTrait { } + +impl MyTrait for .. { } + +pub fn main() { }