Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update tests for new coherence rules, and add a swatch of new tests
probing the specifics of `Fundamental`.

Fixes #23086.
Fixes #23516.
  • Loading branch information
nikomatsakis committed Apr 1, 2015
commit b0af587b64786b45ac9651ee4608e1edbd53a733
22 changes: 22 additions & 0 deletions src/test/auxiliary/coherence_copy_like_lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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 <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.

#![crate_type = "rlib"]
#![feature(fundamental)]

use std::marker::MarkerTrait;

pub trait MyCopy : MarkerTrait { }
impl MyCopy for i32 { }

pub struct MyStruct<T>(T);

#[fundamental]
pub struct MyFundamentalStruct<T>(T);
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@

// aux-build:coherence_lib.rs

// Test that it's ok for T to appear first in the self-type, as long
// as it's covered somewhere.

// pretty-expanded FIXME #23616

// Test that the `Pair` type reports an error if it contains type
// parameters, even when they are covered by local types. This test
// was originally intended to test the opposite, but the rules changed
// with RFC 1023 and this became illegal.

extern crate coherence_lib as lib;
use lib::{Remote,Pair};

pub struct Cover<T>(T);

impl<T> Remote for Pair<T,Cover<T>> { }
//~^ ERROR E0210

fn main() { }
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

// aux-build:coherence_lib.rs

// Test that it's ok for T to appear second in the self-type, as long
// as it's covered somewhere.
// Test that the `Pair` type reports an error if it contains type
// parameters, even when they are covered by local types. This test
// was originally intended to test the opposite, but the rules changed
// with RFC 1023 and this became illegal.

// pretty-expanded FIXME #23616

Expand All @@ -20,6 +22,6 @@ use lib::{Remote,Pair};

pub struct Cover<T>(T);

impl<T> Remote for Pair<Cover<T>,T> { }
impl<T> Remote for Pair<Cover<T>,T> { } //~ ERROR E0210

fn main() { }
4 changes: 2 additions & 2 deletions src/test/compile-fail/coherence-cow-no-cover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

// aux-build:coherence_lib.rs

// Test that it's not ok for U to appear uncovered
// Test that it's not ok for T to appear uncovered

extern crate coherence_lib as lib;
use lib::{Remote,Pair};

pub struct Cover<T>(T);

impl<T,U> Remote for Pair<Cover<T>,U> { }
//~^ ERROR type parameter `U` must be used as the type parameter for some local type
//~^ ERROR type parameter `T` must be used as the type parameter for some local type

fn main() { }
7 changes: 7 additions & 0 deletions src/test/compile-fail/coherence-impls-copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,24 @@ impl !Sync for NotSync {}

impl Copy for TestE {}
impl Copy for MyType {}

impl Copy for &'static mut MyType {}
//~^ ERROR E0206

impl Copy for (MyType, MyType) {}
//~^ ERROR E0206
//~| ERROR E0117

impl Copy for &'static NotSync {}
//~^ ERROR E0206

impl Copy for [MyType] {}
//~^ ERROR E0206
//~| ERROR E0117

impl Copy for &'static [NotSync] {}
//~^ ERROR E0206
//~| ERROR E0117

fn main() {
}
8 changes: 4 additions & 4 deletions src/test/compile-fail/coherence-impls-send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ impl !Sync for NotSync {}
unsafe impl Send for TestE {}
unsafe impl Send for MyType {}
unsafe impl Send for (MyType, MyType) {}
//~^ ERROR E0321
//~^ ERROR E0117

unsafe impl Send for &'static NotSync {}
//~^ ERROR E0321

unsafe impl Send for [MyType] {}
//~^ ERROR E0321
//~^ ERROR E0117

unsafe impl Send for &'static [NotSync] {}
//~^ ERROR E0321
//~| ERROR conflicting implementations
//~^ ERROR E0117
//~| ERROR E0119

fn main() {
}
11 changes: 8 additions & 3 deletions src/test/compile-fail/coherence-impls-sized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ struct NotSync;
impl !Sync for NotSync {}

impl Sized for TestE {} //~ ERROR E0322

impl Sized for MyType {} //~ ERROR E0322
impl Sized for (MyType, MyType) {} //~ ERROR E0322

impl Sized for (MyType, MyType) {} //~ ERROR E0117

impl Sized for &'static NotSync {} //~ ERROR E0322
impl Sized for [MyType] {} //~ ERROR E0322

impl Sized for [MyType] {} //~ ERROR E0117
//~^ ERROR E0277
impl Sized for &'static [NotSync] {} //~ ERROR E0322

impl Sized for &'static [NotSync] {} //~ ERROR E0117

fn main() {
}
19 changes: 19 additions & 0 deletions src/test/compile-fail/coherence-overlap-issue-23516.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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 <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.

// Tests that we consider `Box<U>: !Sugar` to be ambiguous, even
// though we see no impl of `Sugar` for `Box`. Therefore, an overlap
// error is reported for the following pair of impls (#23516).

pub trait Sugar { fn dummy(&self) { } }
pub trait Sweet { fn dummy(&self) { } }
impl<T:Sugar> Sweet for T { } //~ ERROR E0119
impl<U:Sugar> Sweet for Box<U> { }
fn main() { }
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Test that a local, generic type appearing within a
// *non-fundamental* remote type like `Vec` is not considered local.

// aux-build:coherence_lib.rs

// pretty-expanded FIXME #23616
Expand All @@ -17,6 +20,6 @@ use lib::Remote;

struct Local<T>(T);

impl<T> Remote for Vec<Local<T>> { }
impl<T> Remote for Vec<Local<T>> { } //~ ERROR E0210

fn main() { }
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Test that a local type (with no type parameters) appearing within a
// *non-fundamental* remote type like `Vec` is not considered local.

// aux-build:coherence_lib.rs

// pretty-expanded FIXME #23616
Expand All @@ -17,6 +20,6 @@ use lib::Remote;

struct Local;

impl Remote for Vec<Local> { }
impl Remote for Vec<Local> { } //~ ERROR E0117

fn main() { }
Original file line number Diff line number Diff line change
@@ -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 <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.

// Test that we are able to introduce a negative constraint that
// `MyType: !MyTrait` along with other "fundamental" wrappers.

// aux-build:coherence_copy_like_lib.rs

#![feature(rustc_attrs)]
#![allow(dead_code)]

extern crate coherence_copy_like_lib as lib;

use std::marker::MarkerTrait;

struct MyType { x: i32 }

trait MyTrait : MarkerTrait { }
impl<T: lib::MyCopy> MyTrait for T { }

// `MyFundamentalStruct` is declared fundamental, so we can test that
//
// MyFundamentalStruct<MyTrait>: !MyTrait
//
// Huzzah.
impl MyTrait for lib::MyFundamentalStruct<MyType> { }

#[rustc_error]
fn main() { } //~ ERROR compilation successful
Original file line number Diff line number Diff line change
@@ -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 <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.

// Test that we are able to introduce a negative constraint that
// `MyType: !MyTrait` along with other "fundamental" wrappers.

// aux-build:coherence_copy_like_lib.rs

#![feature(rustc_attrs)]
#![allow(dead_code)]

extern crate coherence_copy_like_lib as lib;

use std::marker::MarkerTrait;

struct MyType { x: i32 }

trait MyTrait : MarkerTrait { }
impl<T: lib::MyCopy> MyTrait for T { }

// `MyFundamentalStruct` is declared fundamental, so we can test that
//
// MyFundamentalStruct<&MyTrait>: !MyTrait
//
// Huzzah.
impl<'a> MyTrait for lib::MyFundamentalStruct<&'a MyType> { }

#[rustc_error]
fn main() { } //~ ERROR compilation successful
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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 <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.

// Test that we are able to introduce a negative constraint that
// `MyType: !MyTrait` along with other "fundamental" wrappers.

// aux-build:coherence_copy_like_lib.rs

#![feature(rustc_attrs)]

extern crate coherence_copy_like_lib as lib;

use std::marker::MarkerTrait;

struct MyType { x: i32 }

trait MyTrait : MarkerTrait { }

impl<T: lib::MyCopy> MyTrait for T { } //~ ERROR E0119

// Tuples are not fundamental.
impl MyTrait for lib::MyFundamentalStruct<(MyType,)> { }

#[rustc_error]
fn main() { }
33 changes: 33 additions & 0 deletions src/test/compile-fail/coherence_copy_like_err_struct.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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 <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.

// aux-build:coherence_copy_like_lib.rs

// Test that we are able to introduce a negative constraint that
// `MyType: !MyTrait` along with other "fundamental" wrappers.

extern crate coherence_copy_like_lib as lib;

use std::marker::MarkerTrait;

struct MyType { x: i32 }

trait MyTrait : MarkerTrait { }
impl<T: lib::MyCopy> MyTrait for T { } //~ ERROR E0119

// `MyStruct` is not declared fundamental, therefore this would
// require that
//
// MyStruct<MyType>: !MyTrait
//
// which we cannot approve.
impl MyTrait for lib::MyStruct<MyType> { }

fn main() { }
32 changes: 32 additions & 0 deletions src/test/compile-fail/coherence_copy_like_err_tuple.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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 <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.

// Test that we are able to introduce a negative constraint that
// `MyType: !MyTrait` along with other "fundamental" wrappers.

// aux-build:coherence_copy_like_lib.rs

extern crate coherence_copy_like_lib as lib;

use std::marker::MarkerTrait;

struct MyType { x: i32 }

trait MyTrait : MarkerTrait { }
impl<T: lib::MyCopy> MyTrait for T { } //~ ERROR E0119

// Tuples are not fundamental, therefore this would require that
//
// (MyType,): !MyTrait
//
// which we cannot approve.
impl MyTrait for (MyType,) { }

fn main() { }
Loading