mirror of https://github.com/rust-lang/rust.git
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
|
@ -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
|
||||
|
||||
// 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() { }
|
|
@ -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
|
||||
|
||||
|
@ -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() { }
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
// 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};
|
||||
|
@ -18,6 +18,6 @@ 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() { }
|
||||
|
|
|
@ -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() {
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
}
|
||||
|
|
|
@ -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
|
||||
// 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
|
||||
|
@ -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() { }
|
|
@ -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
|
||||
|
@ -17,6 +20,6 @@ use lib::Remote;
|
|||
|
||||
struct Local;
|
||||
|
||||
impl Remote for Vec<Local> { }
|
||||
impl Remote for Vec<Local> { } //~ ERROR E0117
|
||||
|
||||
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() { }
|
|
@ -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() { }
|
|
@ -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() { }
|
|
@ -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
|
|
@ -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() { }
|
|
@ -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() { }
|
|
@ -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;
|
||||
|
||||
struct A;
|
||||
impl DefaultedTrait for (A,) { } //~ ERROR E0321
|
||||
impl DefaultedTrait for (A,) { } //~ ERROR E0117
|
||||
|
||||
struct B;
|
||||
impl !DefaultedTrait for (B,) { } //~ ERROR E0321
|
||||
impl !DefaultedTrait for (B,) { } //~ ERROR E0117
|
||||
|
||||
struct C;
|
||||
struct D<T>(T);
|
||||
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
|
||||
|
||||
fn main() { }
|
||||
|
|
|
@ -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
|
||||
// except according to those terms.
|
||||
|
||||
// Test that we pick which version of `Foo` to run based on whether
|
||||
// the type we (ultimately) inferred for `x` is copyable or not.
|
||||
//
|
||||
// In this case, the two versions are both impls of same trait, and
|
||||
// hence we we can resolve method even without knowing yet which
|
||||
// version will run (note that the `push` occurs after the call to
|
||||
// `foo()`).
|
||||
// Test that when we write `x.foo()`, we do nothave to know the
|
||||
// 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
|
||||
// `_1` is (because the call to `push` comes later). To pick between
|
||||
// the impls, we would have to know `_1`, since we have to know
|
||||
// whether `_1: MyCopy` or `_1 == Box<i32>`. However (and this is the
|
||||
// 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
|
||||
|
||||
|
@ -25,25 +28,29 @@ trait Foo {
|
|||
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}
|
||||
}
|
||||
|
||||
impl<T> Foo for Vec<Box<T>> {
|
||||
impl Foo for Vec<Box<i32>> {
|
||||
fn foo(&self) -> isize {2}
|
||||
}
|
||||
|
||||
fn call_foo_copy() -> isize {
|
||||
let mut x = Vec::new();
|
||||
let y = x.foo();
|
||||
x.push(0_usize);
|
||||
x.push(0_i32);
|
||||
y
|
||||
}
|
||||
|
||||
fn call_foo_other() -> isize {
|
||||
let mut x: Vec<Box<_>> = Vec::new();
|
||||
let mut x: Vec<_> = Vec::new();
|
||||
let y = x.foo();
|
||||
x.push(box 0);
|
||||
let z: Box<i32> = box 0;
|
||||
x.push(z);
|
||||
y
|
||||
}
|
||||
|
||||
|
|
|
@ -17,16 +17,24 @@
|
|||
#![allow(unknown_features)]
|
||||
#![feature(box_syntax)]
|
||||
|
||||
use std::marker::MarkerTrait;
|
||||
|
||||
trait Get {
|
||||
fn get(&self) -> Self;
|
||||
}
|
||||
|
||||
impl<T:Copy> Get for T {
|
||||
fn get(&self) -> T { *self }
|
||||
trait MyCopy : MarkerTrait { fn copy(&self) -> 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> {
|
||||
fn get(&self) -> Box<T> { box get_it(&**self) }
|
||||
impl Get for Box<i32> {
|
||||
fn get(&self) -> Box<i32> { box get_it(&**self) }
|
||||
}
|
||||
|
||||
fn get_it<T:Get>(t: &T) -> T {
|
||||
|
|
Loading…
Reference in New Issue