Skip to content

Commit 0c0275a

Browse files
committed
Add test for higher-ranked fn ptr in duplicated associated types in dyn.
This does not work yet, and will be fixed in a subsequent commit.
1 parent 8bbea5e commit 0c0275a

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Test that alpha-equivalent associated types are treated as the same type
2+
// for the purposes of prohibiting conflicting associated types in dyn.
3+
// This does not work properly yet.
4+
5+
#![feature(trait_alias)]
6+
7+
trait Trait {
8+
type Assoc;
9+
}
10+
trait Alias = Trait<Assoc = for<'a> fn(&'a ())>;
11+
fn via_trait_alias(_: &dyn Alias<Assoc = for<'b> fn(&'b ())>) {}
12+
//~^ ERROR conflicting associated type bindings for `Assoc`
13+
14+
trait Super<T> {
15+
type Assoc;
16+
}
17+
trait Sub: Super<i32, Assoc = for<'a> fn(&'a ())> + Super<i64, Assoc = for<'b> fn(&'b ())> {}
18+
fn via_supertrait(_: &dyn Sub) {}
19+
//~^ ERROR conflicting associated type bindings for `Assoc`
20+
21+
struct Thing;
22+
impl Trait for Thing {
23+
type Assoc = fn(&());
24+
}
25+
impl Super<i32> for Thing {
26+
type Assoc = fn(&());
27+
}
28+
impl Super<i64> for Thing {
29+
type Assoc = fn(&());
30+
}
31+
impl Sub for Thing {}
32+
33+
fn main() {
34+
via_trait_alias(&Thing);
35+
via_supertrait(&Thing);
36+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error: conflicting associated type bindings for `Assoc`
2+
--> $DIR/duplicate-bound-in-dyn-higher-ranked.rs:11:24
3+
|
4+
LL | trait Alias = Trait<Assoc = for<'a> fn(&'a ())>;
5+
| -------------------------- `Assoc` (in `Trait`) is specified to be `for<'a> fn(&'a ())` here
6+
LL | fn via_trait_alias(_: &dyn Alias<Assoc = for<'b> fn(&'b ())>) {}
7+
| ^^^^^^^^^^--------------------------^
8+
| |
9+
| `Assoc` (in `Trait`) is specified to be `for<'b> fn(&'b ())` here
10+
11+
error: conflicting associated type bindings for `Assoc`
12+
--> $DIR/duplicate-bound-in-dyn-higher-ranked.rs:18:23
13+
|
14+
LL | fn via_supertrait(_: &dyn Sub) {}
15+
| ^^^^^^^
16+
|
17+
= note: `Assoc` (in `Super<i64>`) is specified to be `for<'b> fn(&'b ())`
18+
= note: `Assoc` (in `Super<i32>`) is also specified to be `for<'a> fn(&'a ())`
19+
20+
error: aborting due to 2 previous errors
21+

0 commit comments

Comments
 (0)