Skip to content

Commit b0af587

Browse files
committed
Update tests for new coherence rules, and add a swatch of new tests
probing the specifics of `Fundamental`. Fixes #23086. Fixes #23516.
1 parent 35c261a commit b0af587

23 files changed

+431
-36
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![crate_type = "rlib"]
12+
#![feature(fundamental)]
13+
14+
use std::marker::MarkerTrait;
15+
16+
pub trait MyCopy : MarkerTrait { }
17+
impl MyCopy for i32 { }
18+
19+
pub struct MyStruct<T>(T);
20+
21+
#[fundamental]
22+
pub struct MyFundamentalStruct<T>(T);

src/test/run-pass/coherence-cow-1.rs src/test/compile-fail/coherence-cow-1.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@
1010

1111
// aux-build:coherence_lib.rs
1212

13-
// Test that it's ok for T to appear first in the self-type, as long
14-
// as it's covered somewhere.
15-
1613
// pretty-expanded FIXME #23616
1714

15+
// Test that the `Pair` type reports an error if it contains type
16+
// parameters, even when they are covered by local types. This test
17+
// was originally intended to test the opposite, but the rules changed
18+
// with RFC 1023 and this became illegal.
19+
1820
extern crate coherence_lib as lib;
1921
use lib::{Remote,Pair};
2022

2123
pub struct Cover<T>(T);
2224

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

2528
fn main() { }

src/test/run-pass/coherence-cow-2.rs src/test/compile-fail/coherence-cow-2.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010

1111
// aux-build:coherence_lib.rs
1212

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

1618
// pretty-expanded FIXME #23616
1719

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

2123
pub struct Cover<T>(T);
2224

23-
impl<T> Remote for Pair<Cover<T>,T> { }
25+
impl<T> Remote for Pair<Cover<T>,T> { } //~ ERROR E0210
2426

2527
fn main() { }

src/test/compile-fail/coherence-cow-no-cover.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010

1111
// aux-build:coherence_lib.rs
1212

13-
// Test that it's not ok for U to appear uncovered
13+
// Test that it's not ok for T to appear uncovered
1414

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

1818
pub struct Cover<T>(T);
1919

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

2323
fn main() { }

src/test/compile-fail/coherence-impls-copy.rs

+7
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,24 @@ impl !Sync for NotSync {}
2323

2424
impl Copy for TestE {}
2525
impl Copy for MyType {}
26+
27+
impl Copy for &'static mut MyType {}
28+
//~^ ERROR E0206
29+
2630
impl Copy for (MyType, MyType) {}
2731
//~^ ERROR E0206
32+
//~| ERROR E0117
2833

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

3237
impl Copy for [MyType] {}
3338
//~^ ERROR E0206
39+
//~| ERROR E0117
3440

3541
impl Copy for &'static [NotSync] {}
3642
//~^ ERROR E0206
43+
//~| ERROR E0117
3744

3845
fn main() {
3946
}

src/test/compile-fail/coherence-impls-send.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ impl !Sync for NotSync {}
2424
unsafe impl Send for TestE {}
2525
unsafe impl Send for MyType {}
2626
unsafe impl Send for (MyType, MyType) {}
27-
//~^ ERROR E0321
27+
//~^ ERROR E0117
2828

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

3232
unsafe impl Send for [MyType] {}
33-
//~^ ERROR E0321
33+
//~^ ERROR E0117
3434

3535
unsafe impl Send for &'static [NotSync] {}
36-
//~^ ERROR E0321
37-
//~| ERROR conflicting implementations
36+
//~^ ERROR E0117
37+
//~| ERROR E0119
3838

3939
fn main() {
4040
}

src/test/compile-fail/coherence-impls-sized.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,17 @@ struct NotSync;
2222
impl !Sync for NotSync {}
2323

2424
impl Sized for TestE {} //~ ERROR E0322
25+
2526
impl Sized for MyType {} //~ ERROR E0322
26-
impl Sized for (MyType, MyType) {} //~ ERROR E0322
27+
28+
impl Sized for (MyType, MyType) {} //~ ERROR E0117
29+
2730
impl Sized for &'static NotSync {} //~ ERROR E0322
28-
impl Sized for [MyType] {} //~ ERROR E0322
31+
32+
impl Sized for [MyType] {} //~ ERROR E0117
2933
//~^ ERROR E0277
30-
impl Sized for &'static [NotSync] {} //~ ERROR E0322
34+
35+
impl Sized for &'static [NotSync] {} //~ ERROR E0117
3136

3237
fn main() {
3338
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Tests that we consider `Box<U>: !Sugar` to be ambiguous, even
12+
// though we see no impl of `Sugar` for `Box`. Therefore, an overlap
13+
// error is reported for the following pair of impls (#23516).
14+
15+
pub trait Sugar { fn dummy(&self) { } }
16+
pub trait Sweet { fn dummy(&self) { } }
17+
impl<T:Sugar> Sweet for T { } //~ ERROR E0119
18+
impl<U:Sugar> Sweet for Box<U> { }
19+
fn main() { }

src/test/run-pass/coherence-local-2.rs src/test/compile-fail/coherence-vec-local-2.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// Test that a local, generic type appearing within a
12+
// *non-fundamental* remote type like `Vec` is not considered local.
13+
1114
// aux-build:coherence_lib.rs
1215

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

1821
struct Local<T>(T);
1922

20-
impl<T> Remote for Vec<Local<T>> { }
23+
impl<T> Remote for Vec<Local<T>> { } //~ ERROR E0210
2124

2225
fn main() { }

src/test/run-pass/coherence-local-1.rs src/test/compile-fail/coherence-vec-local.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// Test that a local type (with no type parameters) appearing within a
12+
// *non-fundamental* remote type like `Vec` is not considered local.
13+
1114
// aux-build:coherence_lib.rs
1215

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

1821
struct Local;
1922

20-
impl Remote for Vec<Local> { }
23+
impl Remote for Vec<Local> { } //~ ERROR E0117
2124

2225
fn main() { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that we are able to introduce a negative constraint that
12+
// `MyType: !MyTrait` along with other "fundamental" wrappers.
13+
14+
// aux-build:coherence_copy_like_lib.rs
15+
16+
#![feature(rustc_attrs)]
17+
#![allow(dead_code)]
18+
19+
extern crate coherence_copy_like_lib as lib;
20+
21+
use std::marker::MarkerTrait;
22+
23+
struct MyType { x: i32 }
24+
25+
trait MyTrait : MarkerTrait { }
26+
impl<T: lib::MyCopy> MyTrait for T { }
27+
28+
// `MyFundamentalStruct` is declared fundamental, so we can test that
29+
//
30+
// MyFundamentalStruct<MyTrait>: !MyTrait
31+
//
32+
// Huzzah.
33+
impl MyTrait for lib::MyFundamentalStruct<MyType> { }
34+
35+
#[rustc_error]
36+
fn main() { } //~ ERROR compilation successful
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that we are able to introduce a negative constraint that
12+
// `MyType: !MyTrait` along with other "fundamental" wrappers.
13+
14+
// aux-build:coherence_copy_like_lib.rs
15+
16+
#![feature(rustc_attrs)]
17+
#![allow(dead_code)]
18+
19+
extern crate coherence_copy_like_lib as lib;
20+
21+
use std::marker::MarkerTrait;
22+
23+
struct MyType { x: i32 }
24+
25+
trait MyTrait : MarkerTrait { }
26+
impl<T: lib::MyCopy> MyTrait for T { }
27+
28+
// `MyFundamentalStruct` is declared fundamental, so we can test that
29+
//
30+
// MyFundamentalStruct<&MyTrait>: !MyTrait
31+
//
32+
// Huzzah.
33+
impl<'a> MyTrait for lib::MyFundamentalStruct<&'a MyType> { }
34+
35+
#[rustc_error]
36+
fn main() { } //~ ERROR compilation successful
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that we are able to introduce a negative constraint that
12+
// `MyType: !MyTrait` along with other "fundamental" wrappers.
13+
14+
// aux-build:coherence_copy_like_lib.rs
15+
16+
#![feature(rustc_attrs)]
17+
18+
extern crate coherence_copy_like_lib as lib;
19+
20+
use std::marker::MarkerTrait;
21+
22+
struct MyType { x: i32 }
23+
24+
trait MyTrait : MarkerTrait { }
25+
26+
impl<T: lib::MyCopy> MyTrait for T { } //~ ERROR E0119
27+
28+
// Tuples are not fundamental.
29+
impl MyTrait for lib::MyFundamentalStruct<(MyType,)> { }
30+
31+
#[rustc_error]
32+
fn main() { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// aux-build:coherence_copy_like_lib.rs
12+
13+
// Test that we are able to introduce a negative constraint that
14+
// `MyType: !MyTrait` along with other "fundamental" wrappers.
15+
16+
extern crate coherence_copy_like_lib as lib;
17+
18+
use std::marker::MarkerTrait;
19+
20+
struct MyType { x: i32 }
21+
22+
trait MyTrait : MarkerTrait { }
23+
impl<T: lib::MyCopy> MyTrait for T { } //~ ERROR E0119
24+
25+
// `MyStruct` is not declared fundamental, therefore this would
26+
// require that
27+
//
28+
// MyStruct<MyType>: !MyTrait
29+
//
30+
// which we cannot approve.
31+
impl MyTrait for lib::MyStruct<MyType> { }
32+
33+
fn main() { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that we are able to introduce a negative constraint that
12+
// `MyType: !MyTrait` along with other "fundamental" wrappers.
13+
14+
// aux-build:coherence_copy_like_lib.rs
15+
16+
extern crate coherence_copy_like_lib as lib;
17+
18+
use std::marker::MarkerTrait;
19+
20+
struct MyType { x: i32 }
21+
22+
trait MyTrait : MarkerTrait { }
23+
impl<T: lib::MyCopy> MyTrait for T { } //~ ERROR E0119
24+
25+
// Tuples are not fundamental, therefore this would require that
26+
//
27+
// (MyType,): !MyTrait
28+
//
29+
// which we cannot approve.
30+
impl MyTrait for (MyType,) { }
31+
32+
fn main() { }

0 commit comments

Comments
 (0)