]> git.lizzy.rs Git - rust.git/blob - tests/ui/inference/issue-80816.rs
Rollup merge of #106321 - compiler-errors:delayed-bug-backtrace, r=Nilstrieb
[rust.git] / tests / ui / inference / issue-80816.rs
1 #![allow(unreachable_code)]
2
3 use std::marker::PhantomData;
4 use std::ops::Deref;
5 use std::sync::Arc;
6
7 pub struct Guard<T> {
8     _phantom: PhantomData<T>,
9 }
10 impl<T> Deref for Guard<T> {
11     type Target = T;
12     fn deref(&self) -> &T {
13         unimplemented!()
14     }
15 }
16
17 pub struct DirectDeref<T>(T);
18 impl<T> Deref for DirectDeref<Arc<T>> {
19     type Target = T;
20     fn deref(&self) -> &T {
21         unimplemented!()
22     }
23 }
24
25 pub trait Access<T> {
26     type Guard: Deref<Target = T>;
27     fn load(&self) -> Self::Guard {
28         unimplemented!()
29     }
30 }
31 impl<T, A: Access<T>, P: Deref<Target = A>> Access<T> for P {
32     //~^ NOTE: required for `Arc<ArcSwapAny<Arc<usize>>>` to implement `Access<_>`
33     type Guard = A::Guard;
34 }
35 impl<T> Access<T> for ArcSwapAny<T> {
36     //~^ NOTE: multiple `impl`s satisfying `ArcSwapAny<Arc<usize>>: Access<_>` found
37     type Guard = Guard<T>;
38 }
39 impl<T> Access<T> for ArcSwapAny<Arc<T>> {
40     type Guard = DirectDeref<Arc<T>>;
41 }
42
43 pub struct ArcSwapAny<T> {
44     _phantom_arc: PhantomData<T>,
45 }
46
47 pub fn foo() {
48     let s: Arc<ArcSwapAny<Arc<usize>>> = unimplemented!();
49     let guard: Guard<Arc<usize>> = s.load();
50     //~^ ERROR: type annotations needed
51     //~| HELP: try using a fully qualified path to specify the expected types
52 }
53
54 fn main() {}