Update tests for new coherence rules, and add a swatch of new tests
probing the specifics of `Fundamental`. Fixes #23086. Fixes #23516.
This commit is contained in:
parent
35c261aea0
commit
b0af587b64
23 changed files with 431 additions and 36 deletions
22
src/test/auxiliary/coherence_copy_like_lib.rs
Normal file
22
src/test/auxiliary/coherence_copy_like_lib.rs
Normal file
|
@ -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);
|
|
@ -10,16 +10,19 @@
|
||||||
|
|
||||||
// aux-build:coherence_lib.rs
|
// 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
|
// 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;
|
extern crate coherence_lib as lib;
|
||||||
use lib::{Remote,Pair};
|
use lib::{Remote,Pair};
|
||||||
|
|
||||||
pub struct Cover<T>(T);
|
pub struct Cover<T>(T);
|
||||||
|
|
||||||
impl<T> Remote for Pair<T,Cover<T>> { }
|
impl<T> Remote for Pair<T,Cover<T>> { }
|
||||||
|
//~^ ERROR E0210
|
||||||
|
|
||||||
fn main() { }
|
fn main() { }
|
|
@ -10,8 +10,10 @@
|
||||||
|
|
||||||
// aux-build:coherence_lib.rs
|
// aux-build:coherence_lib.rs
|
||||||
|
|
||||||
// Test that it's ok for T to appear second in the self-type, as long
|
// Test that the `Pair` type reports an error if it contains type
|
||||||
// as it's covered somewhere.
|
// 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
|
// pretty-expanded FIXME #23616
|
||||||
|
|
||||||
|
@ -20,6 +22,6 @@ use lib::{Remote,Pair};
|
||||||
|
|
||||||
pub struct Cover<T>(T);
|
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() { }
|
fn main() { }
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
// aux-build:coherence_lib.rs
|
// 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;
|
extern crate coherence_lib as lib;
|
||||||
use lib::{Remote,Pair};
|
use lib::{Remote,Pair};
|
||||||
|
@ -18,6 +18,6 @@ use lib::{Remote,Pair};
|
||||||
pub struct Cover<T>(T);
|
pub struct Cover<T>(T);
|
||||||
|
|
||||||
impl<T,U> Remote for Pair<Cover<T>,U> { }
|
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() { }
|
fn main() { }
|
||||||
|
|
|
@ -23,17 +23,24 @@ impl !Sync for NotSync {}
|
||||||
|
|
||||||
impl Copy for TestE {}
|
impl Copy for TestE {}
|
||||||
impl Copy for MyType {}
|
impl Copy for MyType {}
|
||||||
|
|
||||||
|
impl Copy for &'static mut MyType {}
|
||||||
|
//~^ ERROR E0206
|
||||||
|
|
||||||
impl Copy for (MyType, MyType) {}
|
impl Copy for (MyType, MyType) {}
|
||||||
//~^ ERROR E0206
|
//~^ ERROR E0206
|
||||||
|
//~| ERROR E0117
|
||||||
|
|
||||||
impl Copy for &'static NotSync {}
|
impl Copy for &'static NotSync {}
|
||||||
//~^ ERROR E0206
|
//~^ ERROR E0206
|
||||||
|
|
||||||
impl Copy for [MyType] {}
|
impl Copy for [MyType] {}
|
||||||
//~^ ERROR E0206
|
//~^ ERROR E0206
|
||||||
|
//~| ERROR E0117
|
||||||
|
|
||||||
impl Copy for &'static [NotSync] {}
|
impl Copy for &'static [NotSync] {}
|
||||||
//~^ ERROR E0206
|
//~^ ERROR E0206
|
||||||
|
//~| ERROR E0117
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,17 +24,17 @@ impl !Sync for NotSync {}
|
||||||
unsafe impl Send for TestE {}
|
unsafe impl Send for TestE {}
|
||||||
unsafe impl Send for MyType {}
|
unsafe impl Send for MyType {}
|
||||||
unsafe impl Send for (MyType, MyType) {}
|
unsafe impl Send for (MyType, MyType) {}
|
||||||
//~^ ERROR E0321
|
//~^ ERROR E0117
|
||||||
|
|
||||||
unsafe impl Send for &'static NotSync {}
|
unsafe impl Send for &'static NotSync {}
|
||||||
//~^ ERROR E0321
|
//~^ ERROR E0321
|
||||||
|
|
||||||
unsafe impl Send for [MyType] {}
|
unsafe impl Send for [MyType] {}
|
||||||
//~^ ERROR E0321
|
//~^ ERROR E0117
|
||||||
|
|
||||||
unsafe impl Send for &'static [NotSync] {}
|
unsafe impl Send for &'static [NotSync] {}
|
||||||
//~^ ERROR E0321
|
//~^ ERROR E0117
|
||||||
//~| ERROR conflicting implementations
|
//~| ERROR E0119
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,12 +22,17 @@ struct NotSync;
|
||||||
impl !Sync for NotSync {}
|
impl !Sync for NotSync {}
|
||||||
|
|
||||||
impl Sized for TestE {} //~ ERROR E0322
|
impl Sized for TestE {} //~ ERROR E0322
|
||||||
|
|
||||||
impl Sized for MyType {} //~ 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 &'static NotSync {} //~ ERROR E0322
|
||||||
impl Sized for [MyType] {} //~ ERROR E0322
|
|
||||||
|
impl Sized for [MyType] {} //~ ERROR E0117
|
||||||
//~^ ERROR E0277
|
//~^ ERROR E0277
|
||||||
impl Sized for &'static [NotSync] {} //~ ERROR E0322
|
|
||||||
|
impl Sized for &'static [NotSync] {} //~ ERROR E0117
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
}
|
}
|
||||||
|
|
19
src/test/compile-fail/coherence-overlap-issue-23516.rs
Normal file
19
src/test/compile-fail/coherence-overlap-issue-23516.rs
Normal file
|
@ -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() { }
|
|
@ -8,6 +8,9 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// 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
|
// aux-build:coherence_lib.rs
|
||||||
|
|
||||||
// pretty-expanded FIXME #23616
|
// pretty-expanded FIXME #23616
|
||||||
|
@ -17,6 +20,6 @@ use lib::Remote;
|
||||||
|
|
||||||
struct Local<T>(T);
|
struct Local<T>(T);
|
||||||
|
|
||||||
impl<T> Remote for Vec<Local<T>> { }
|
impl<T> Remote for Vec<Local<T>> { } //~ ERROR E0210
|
||||||
|
|
||||||
fn main() { }
|
fn main() { }
|
|
@ -8,6 +8,9 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// 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
|
// aux-build:coherence_lib.rs
|
||||||
|
|
||||||
// pretty-expanded FIXME #23616
|
// pretty-expanded FIXME #23616
|
||||||
|
@ -17,6 +20,6 @@ use lib::Remote;
|
||||||
|
|
||||||
struct Local;
|
struct Local;
|
||||||
|
|
||||||
impl Remote for Vec<Local> { }
|
impl Remote for Vec<Local> { } //~ ERROR E0117
|
||||||
|
|
||||||
fn main() { }
|
fn main() { }
|
|
@ -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
|
|
@ -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
|
|
@ -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
src/test/compile-fail/coherence_copy_like_err_struct.rs
Normal file
33
src/test/compile-fail/coherence_copy_like_err_struct.rs
Normal file
|
@ -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
src/test/compile-fail/coherence_copy_like_err_tuple.rs
Normal file
32
src/test/compile-fail/coherence_copy_like_err_tuple.rs
Normal file
|
@ -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() { }
|
33
src/test/compile-fail/coherence_local.rs
Normal file
33
src/test/compile-fail/coherence_local.rs
Normal file
|
@ -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.
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
struct MyType { x: i32 }
|
||||||
|
|
||||||
|
// These are all legal because they are all fundamental types:
|
||||||
|
|
||||||
|
impl lib::MyCopy for MyType { }
|
||||||
|
impl<'a> lib::MyCopy for &'a MyType { }
|
||||||
|
impl<'a> lib::MyCopy for &'a Box<MyType> { }
|
||||||
|
impl lib::MyCopy for Box<MyType> { }
|
||||||
|
impl lib::MyCopy for lib::MyFundamentalStruct<MyType> { }
|
||||||
|
impl lib::MyCopy for lib::MyFundamentalStruct<Box<MyType>> { }
|
||||||
|
|
||||||
|
#[rustc_error]
|
||||||
|
fn main() { } //~ ERROR compilation successful
|
29
src/test/compile-fail/coherence_local_err_struct.rs
Normal file
29
src/test/compile-fail/coherence_local_err_struct.rs
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
struct MyType { x: i32 }
|
||||||
|
|
||||||
|
// These are all legal because they are all fundamental types:
|
||||||
|
|
||||||
|
// MyStruct is not fundamental.
|
||||||
|
impl lib::MyCopy for lib::MyStruct<MyType> { } //~ ERROR E0117
|
||||||
|
|
||||||
|
#[rustc_error]
|
||||||
|
fn main() { }
|
29
src/test/compile-fail/coherence_local_err_tuple.rs
Normal file
29
src/test/compile-fail/coherence_local_err_tuple.rs
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
struct MyType { x: i32 }
|
||||||
|
|
||||||
|
// These are all legal because they are all fundamental types:
|
||||||
|
|
||||||
|
// Tuples are not fundamental, so this is not a local impl.
|
||||||
|
impl lib::MyCopy for (MyType,) { } //~ ERROR E0117
|
||||||
|
|
||||||
|
#[rustc_error]
|
||||||
|
fn main() { }
|
27
src/test/compile-fail/coherence_local_ref.rs
Normal file
27
src/test/compile-fail/coherence_local_ref.rs
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
struct MyType { x: i32 }
|
||||||
|
|
||||||
|
// naturally, legal
|
||||||
|
impl lib::MyCopy for MyType { }
|
||||||
|
|
||||||
|
#[rustc_error]
|
||||||
|
fn main() { } //~ ERROR compilation successful
|
|
@ -20,15 +20,15 @@ extern crate typeck_default_trait_impl_cross_crate_coherence_lib as lib;
|
||||||
use lib::DefaultedTrait;
|
use lib::DefaultedTrait;
|
||||||
|
|
||||||
struct A;
|
struct A;
|
||||||
impl DefaultedTrait for (A,) { } //~ ERROR E0321
|
impl DefaultedTrait for (A,) { } //~ ERROR E0117
|
||||||
|
|
||||||
struct B;
|
struct B;
|
||||||
impl !DefaultedTrait for (B,) { } //~ ERROR E0321
|
impl !DefaultedTrait for (B,) { } //~ ERROR E0117
|
||||||
|
|
||||||
struct C;
|
struct C;
|
||||||
struct D<T>(T);
|
struct D<T>(T);
|
||||||
impl DefaultedTrait for Box<C> { } //~ ERROR E0321
|
impl DefaultedTrait for Box<C> { } //~ ERROR E0321
|
||||||
impl DefaultedTrait for lib::Something<C> { } //~ ERROR E0321
|
impl DefaultedTrait for lib::Something<C> { } //~ ERROR E0117
|
||||||
impl DefaultedTrait for D<C> { } // OK
|
impl DefaultedTrait for D<C> { } // OK
|
||||||
|
|
||||||
fn main() { }
|
fn main() { }
|
||||||
|
|
29
src/test/run-pass/coherence_copy_like.rs
Normal file
29
src/test/run-pass/coherence_copy_like.rs
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
// 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 { }
|
||||||
|
impl MyTrait for MyType { }
|
||||||
|
impl<'a> MyTrait for &'a MyType { }
|
||||||
|
impl MyTrait for Box<MyType> { }
|
||||||
|
impl<'a> MyTrait for &'a Box<MyType> { }
|
||||||
|
|
||||||
|
fn main() { }
|
|
@ -8,13 +8,16 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
// Test that we pick which version of `Foo` to run based on whether
|
// Test that when we write `x.foo()`, we do nothave to know the
|
||||||
// the type we (ultimately) inferred for `x` is copyable or not.
|
// complete type of `x` in order to type-check the method call. In
|
||||||
//
|
// this case, we know that `x: Vec<_1>`, but we don't know what type
|
||||||
// In this case, the two versions are both impls of same trait, and
|
// `_1` is (because the call to `push` comes later). To pick between
|
||||||
// hence we we can resolve method even without knowing yet which
|
// the impls, we would have to know `_1`, since we have to know
|
||||||
// version will run (note that the `push` occurs after the call to
|
// whether `_1: MyCopy` or `_1 == Box<i32>`. However (and this is the
|
||||||
// `foo()`).
|
// point of the test), we don't have to pick between the two impls --
|
||||||
|
// it is enough to know that `foo` comes from the `Foo` trait. We can
|
||||||
|
// translate the call as `Foo::foo(&x)` and let the specific impl get
|
||||||
|
// chosen later.
|
||||||
|
|
||||||
// pretty-expanded FIXME #23616
|
// pretty-expanded FIXME #23616
|
||||||
|
|
||||||
|
@ -25,25 +28,29 @@ trait Foo {
|
||||||
fn foo(&self) -> isize;
|
fn foo(&self) -> isize;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T:Copy> Foo for Vec<T> {
|
trait MyCopy { fn foo(&self) { } }
|
||||||
|
impl MyCopy for i32 { }
|
||||||
|
|
||||||
|
impl<T:MyCopy> Foo for Vec<T> {
|
||||||
fn foo(&self) -> isize {1}
|
fn foo(&self) -> isize {1}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Foo for Vec<Box<T>> {
|
impl Foo for Vec<Box<i32>> {
|
||||||
fn foo(&self) -> isize {2}
|
fn foo(&self) -> isize {2}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call_foo_copy() -> isize {
|
fn call_foo_copy() -> isize {
|
||||||
let mut x = Vec::new();
|
let mut x = Vec::new();
|
||||||
let y = x.foo();
|
let y = x.foo();
|
||||||
x.push(0_usize);
|
x.push(0_i32);
|
||||||
y
|
y
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call_foo_other() -> isize {
|
fn call_foo_other() -> isize {
|
||||||
let mut x: Vec<Box<_>> = Vec::new();
|
let mut x: Vec<_> = Vec::new();
|
||||||
let y = x.foo();
|
let y = x.foo();
|
||||||
x.push(box 0);
|
let z: Box<i32> = box 0;
|
||||||
|
x.push(z);
|
||||||
y
|
y
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,16 +17,24 @@
|
||||||
#![allow(unknown_features)]
|
#![allow(unknown_features)]
|
||||||
#![feature(box_syntax)]
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
|
use std::marker::MarkerTrait;
|
||||||
|
|
||||||
trait Get {
|
trait Get {
|
||||||
fn get(&self) -> Self;
|
fn get(&self) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T:Copy> Get for T {
|
trait MyCopy : MarkerTrait { fn copy(&self) -> Self; }
|
||||||
fn get(&self) -> T { *self }
|
impl MyCopy for u16 { fn copy(&self) -> Self { *self } }
|
||||||
|
impl MyCopy for u32 { fn copy(&self) -> Self { *self } }
|
||||||
|
impl MyCopy for i32 { fn copy(&self) -> Self { *self } }
|
||||||
|
impl<T:Copy> MyCopy for Option<T> { fn copy(&self) -> Self { *self } }
|
||||||
|
|
||||||
|
impl<T:MyCopy> Get for T {
|
||||||
|
fn get(&self) -> T { self.copy() }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T:Get> Get for Box<T> {
|
impl Get for Box<i32> {
|
||||||
fn get(&self) -> Box<T> { box get_it(&**self) }
|
fn get(&self) -> Box<i32> { box get_it(&**self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_it<T:Get>(t: &T) -> T {
|
fn get_it<T:Get>(t: &T) -> T {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue