Skip to content

Commit 665f852

Browse files
committed
update tests slightly
1 parent ac38627 commit 665f852

4 files changed

+76
-8
lines changed

src/test/compile-fail/feature-gate-overlapping_marker_traits.rs

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

11+
use std::fmt::{Debug, Display};
12+
1113
trait MyMarker {}
1214

13-
impl<T> MyMarker for T {}
14-
impl<T> MyMarker for Vec<T> {}
15+
impl<T: Display> MyMarker for T {}
16+
impl<T: Debug> MyMarker for T {}
1517
//~^ ERROR E0119
1618

1719
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2017 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 for RFC 1268: we allow overlapping impls of marker traits,
12+
// that is, traits without items. In this case, a type `T` is
13+
// `MyMarker` if it is either `Debug` or `Display`. This test just
14+
// checks that we don't consider **all** types to be `MyMarker`. See
15+
// also the companion test in
16+
// `run-pass/overlap-permitted-for-marker-traits.rs`.
17+
18+
#![feature(overlapping_marker_traits)]
19+
#![feature(optin_builtin_traits)]
20+
21+
use std::fmt::{Debug, Display};
22+
23+
trait Marker {}
24+
25+
impl<T: Debug> Marker for T {}
26+
impl<T: Display> Marker for T {}
27+
28+
fn is_marker<T: Marker>() { }
29+
30+
struct NotDebugOrDisplay;
31+
32+
fn main() {
33+
// Debug && Display:
34+
is_marker::<i32>();
35+
36+
// Debug && !Display:
37+
is_marker::<Vec<i32>>();
38+
39+
// !Debug && !Display
40+
is_marker::<NotDebugOrDisplay>(); //~ ERROR
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2017 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+
#![feature(overlapping_marker_traits)]
12+
#![feature(optin_builtin_traits)]
13+
14+
// Overlapping negative impls for `MyStruct` are permitted:
15+
struct MyStruct;
16+
impl !Send for MyStruct {}
17+
impl !Send for MyStruct {}
18+
19+
fn main() {
20+
}

src/test/run-pass/overlap-permitted-for-marker-traits.rs

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

11+
// Tests for RFC 1268: we allow overlapping impls of marker traits,
12+
// that is, traits without items. In this case, a type `T` is
13+
// `MyMarker` if it is either `Debug` or `Display`.
14+
1115
#![feature(overlapping_marker_traits)]
1216
#![feature(optin_builtin_traits)]
1317

14-
trait MyMarker {}
18+
use std::fmt::{Debug, Display};
1519

16-
impl<T: Copy> MyMarker for T {}
17-
impl<T: Eq> MyMarker for T {}
20+
trait MyMarker {}
1821

19-
struct MyStruct;
20-
impl !Send for MyStruct {}
21-
impl !Send for MyStruct {}
22+
impl<T: Debug> MyMarker for T {}
23+
impl<T: Display> MyMarker for T {}
2224

2325
fn foo<T: MyMarker>(t: T) -> T {
2426
t
2527
}
2628

2729
fn main() {
30+
// Debug && Display:
2831
assert_eq!(1, foo(1));
2932
assert_eq!(2.0, foo(2.0));
33+
34+
// Debug && !Display:
3035
assert_eq!(vec![1], foo(vec![1]));
3136
}

0 commit comments

Comments
 (0)