Skip to content

Commit a186b79

Browse files
committed
Add test for known issue with higher-ranked fn ptr in duplicated associated types in dyn.
This issue previously only affected trait aliases. This PR causes the same issue to also affect supertraits.
1 parent 8bbea5e commit a186b79

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Alpha-equivalent associated types are currently treated as different types
2+
// for the purposes of prohibiting conflicting associated types in dyn.
3+
// This is undesirable, but we don't have a good way of fixing this.
4+
// See also https://github.com/rust-lang/rust/issues/146548
5+
6+
#![feature(trait_alias)]
7+
8+
trait Trait {
9+
type Assoc;
10+
}
11+
trait Alias = Trait<Assoc = for<'a> fn(&'a ())>;
12+
fn via_trait_alias(_: &dyn Alias<Assoc = for<'b> fn(&'b ())>) {}
13+
//~^ ERROR conflicting associated type bindings for `Assoc`
14+
15+
trait Super<T> {
16+
type Assoc;
17+
}
18+
trait Sub: Super<i32, Assoc = for<'a> fn(&'a ())> + Super<i64, Assoc = for<'b> fn(&'b ())> {}
19+
fn via_supertrait(_: &dyn Sub) {}
20+
//~^ ERROR conflicting associated type bindings for `Assoc`
21+
22+
struct Thing;
23+
impl Trait for Thing {
24+
type Assoc = fn(&());
25+
}
26+
impl Super<i32> for Thing {
27+
type Assoc = fn(&());
28+
}
29+
impl Super<i64> for Thing {
30+
type Assoc = fn(&());
31+
}
32+
impl Sub for Thing {}
33+
34+
fn main() {
35+
via_trait_alias(&Thing);
36+
via_supertrait(&Thing);
37+
}
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:12: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:19: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)