File: associated-type.rs

package info (click to toggle)
rustc 1.88.0%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 934,168 kB
  • sloc: xml: 158,127; python: 36,062; javascript: 19,855; sh: 19,700; cpp: 18,947; ansic: 12,993; asm: 4,792; makefile: 690; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (47 lines) | stat: -rw-r--r-- 980 bytes parent folder | download | duplicates (17)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//@ revisions: old next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver

// A (partial) regression test for #105787

// Using the higher ranked projection hack to prevent us from replacing the projection
// with an inference variable.
trait ToUnit<'a> {
    type Unit;
}

struct LocalTy;
impl<'a> ToUnit<'a> for *const LocalTy {
    type Unit = ();
}

impl<'a, T: Copy + ?Sized> ToUnit<'a> for *const T {
    type Unit = ();
}

trait Overlap<T> {
    type Assoc;
}

type Assoc<'a, T> = <*const T as ToUnit<'a>>::Unit;

impl<T> Overlap<T> for T {
    type Assoc = usize;
}

impl<T> Overlap<for<'a> fn(&'a (), Assoc<'a, T>)> for T
//~^ ERROR conflicting implementations of trait
where
    for<'a> *const T: ToUnit<'a>,
{
    type Assoc = Box<usize>;
}

fn foo<T: Overlap<U>, U>(x: T::Assoc) -> T::Assoc {
    x
}

fn main() {
    foo::<for<'a> fn(&'a (), ()), for<'a> fn(&'a (), ())>(3usize);
    //[next]~^ ERROR: cannot normalize
}