Skip to content

Commit 87f63ca

Browse files
committed
Add tests for associated types and inconsistent bounds
1 parent ba35e80 commit 87f63ca

4 files changed

+166
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2018 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(trivial_bounds)]
12+
#![allow(unused)]
13+
14+
struct B;
15+
16+
trait A {
17+
type X;
18+
fn get_x() -> Self::X;
19+
}
20+
21+
impl A for B {
22+
type X = u8;
23+
fn get_x() -> u8 { 0 }
24+
}
25+
26+
fn global_bound_is_hidden() -> u8
27+
where
28+
B: A<X = i32>
29+
{
30+
B::get_x() //~ ERROR
31+
}
32+
33+
fn main () {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/trivial-bounds-inconsistent-projection-error.rs:30:5
3+
|
4+
LL | fn global_bound_is_hidden() -> u8
5+
| -- expected `u8` because of return type
6+
...
7+
LL | B::get_x() //~ ERROR
8+
| ^^^^^^^^^^ expected u8, found i32
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0308`.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright 2018 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+
// run-pass
12+
// Check that global bounds result in the expected choice of associated type
13+
14+
#![feature(trivial_bounds)]
15+
#![allow(unused)]
16+
17+
struct B;
18+
19+
trait A {
20+
type X;
21+
fn get_x() -> Self::X;
22+
}
23+
24+
impl A for B {
25+
type X = u8;
26+
fn get_x() -> u8 { 0 }
27+
}
28+
29+
fn underspecified_bound() -> u8
30+
where
31+
B: A
32+
{
33+
B::get_x()
34+
}
35+
36+
fn inconsistent_bound() -> i32
37+
where
38+
B: A<X = i32>
39+
{
40+
B::get_x()
41+
}
42+
43+
fn redundant_bound() -> u8
44+
where
45+
B: A<X = u8>
46+
{
47+
B::get_x()
48+
}
49+
50+
fn inconsistent_dup_bound() -> i32
51+
where
52+
B: A<X = i32> + A
53+
{
54+
B::get_x()
55+
}
56+
57+
fn redundant_dup_bound() -> u8
58+
where
59+
B: A<X = u8> + A
60+
{
61+
B::get_x()
62+
}
63+
64+
fn main () {}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
warning: Trait bound B: A does not depend on any type or lifetime parameters
2+
--> $DIR/trivial-bounds-inconsistent-projection.rs:29:1
3+
|
4+
LL | / fn underspecified_bound() -> u8
5+
LL | | where
6+
LL | | B: A
7+
LL | | {
8+
LL | | B::get_x()
9+
LL | | }
10+
| |_^
11+
|
12+
= note: #[warn(trivial_bounds)] on by default
13+
14+
warning: Trait bound B: A does not depend on any type or lifetime parameters
15+
--> $DIR/trivial-bounds-inconsistent-projection.rs:36:1
16+
|
17+
LL | / fn inconsistent_bound() -> i32
18+
LL | | where
19+
LL | | B: A<X = i32>
20+
LL | | {
21+
LL | | B::get_x()
22+
LL | | }
23+
| |_^
24+
25+
warning: Trait bound B: A does not depend on any type or lifetime parameters
26+
--> $DIR/trivial-bounds-inconsistent-projection.rs:43:1
27+
|
28+
LL | / fn redundant_bound() -> u8
29+
LL | | where
30+
LL | | B: A<X = u8>
31+
LL | | {
32+
LL | | B::get_x()
33+
LL | | }
34+
| |_^
35+
36+
warning: Trait bound B: A does not depend on any type or lifetime parameters
37+
--> $DIR/trivial-bounds-inconsistent-projection.rs:50:1
38+
|
39+
LL | / fn inconsistent_dup_bound() -> i32
40+
LL | | where
41+
LL | | B: A<X = i32> + A
42+
LL | | {
43+
LL | | B::get_x()
44+
LL | | }
45+
| |_^
46+
47+
warning: Trait bound B: A does not depend on any type or lifetime parameters
48+
--> $DIR/trivial-bounds-inconsistent-projection.rs:57:1
49+
|
50+
LL | / fn redundant_dup_bound() -> u8
51+
LL | | where
52+
LL | | B: A<X = u8> + A
53+
LL | | {
54+
LL | | B::get_x()
55+
LL | | }
56+
| |_^
57+

0 commit comments

Comments
 (0)