Skip to content

Commit b149315

Browse files
authored
Rollup merge of #105944 - JohnTitor:issue-80816, r=compiler-errors
Add regression test for #80816 Closes #80816 r? `@compiler-errors` Signed-off-by: Yuki Okushi <[email protected]>
2 parents d6fbe79 + 17d7d71 commit b149315

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

src/test/ui/inference/issue-80816.rs

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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() {}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error[E0283]: type annotations needed
2+
--> $DIR/issue-80816.rs:49:38
3+
|
4+
LL | let guard: Guard<Arc<usize>> = s.load();
5+
| ^^^^
6+
|
7+
note: multiple `impl`s satisfying `ArcSwapAny<Arc<usize>>: Access<_>` found
8+
--> $DIR/issue-80816.rs:35:1
9+
|
10+
LL | impl<T> Access<T> for ArcSwapAny<T> {
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
...
13+
LL | impl<T> Access<T> for ArcSwapAny<Arc<T>> {
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15+
note: required for `Arc<ArcSwapAny<Arc<usize>>>` to implement `Access<_>`
16+
--> $DIR/issue-80816.rs:31:45
17+
|
18+
LL | impl<T, A: Access<T>, P: Deref<Target = A>> Access<T> for P {
19+
| ^^^^^^^^^ ^
20+
help: try using a fully qualified path to specify the expected types
21+
|
22+
LL | let guard: Guard<Arc<usize>> = <Arc<ArcSwapAny<Arc<usize>>> as Access<T>>::load(&s);
23+
| ++++++++++++++++++++++++++++++++++++++++++++++++++ ~
24+
25+
error: aborting due to previous error
26+
27+
For more information about this error, try `rustc --explain E0283`.

0 commit comments

Comments
 (0)