Skip to content

Commit f916aa9

Browse files
committed
Add test for multiple ref-self
1 parent dc04a4e commit f916aa9

File tree

3 files changed

+73
-7
lines changed

3 files changed

+73
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// check-pass
2+
3+
#![feature(arbitrary_self_types)]
4+
#![allow(non_snake_case)]
5+
6+
use std::marker::PhantomData;
7+
use std::ops::Deref;
8+
use std::pin::Pin;
9+
10+
struct Struct { }
11+
12+
struct Wrap<T, P>(T, PhantomData<P>);
13+
14+
impl<T, P> Deref for Wrap<T, P> {
15+
type Target = T;
16+
fn deref(&self) -> &T { &self.0 }
17+
}
18+
19+
impl Struct {
20+
// Test using multiple `&Self`:
21+
22+
fn wrap_ref_Self_ref_Self(self: Wrap<&Self, &Self>, f: &u8) -> &u8 {
23+
f
24+
}
25+
26+
fn box_wrap_ref_Self_ref_Self(self: Box<Wrap<&Self, &Self>>, f: &u32) -> &u32 {
27+
f
28+
}
29+
30+
fn pin_wrap_ref_Self_ref_Self(self: Pin<Wrap<&Self, &Self>>, f: &u32) -> &u32 {
31+
f
32+
}
33+
34+
fn box_box_wrap_ref_Self_ref_Self(self: Box<Box<Wrap<&Self, &Self>>>, f: &u32) -> &u32 {
35+
f
36+
}
37+
38+
fn box_pin_wrap_ref_Self_ref_Self(self: Box<Pin<Wrap<&Self, &Self>>>, f: &u32) -> &u32 {
39+
f
40+
}
41+
}
42+
43+
fn main() { }

src/test/ui/self/elision/ref-self.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
#![feature(arbitrary_self_types)]
22
#![allow(non_snake_case)]
33

4+
use std::marker::PhantomData;
5+
use std::ops::Deref;
46
use std::pin::Pin;
57

68
struct Struct { }
79

10+
struct Wrap<T, P>(T, PhantomData<P>);
11+
12+
impl<T, P> Deref for Wrap<T, P> {
13+
type Target = T;
14+
fn deref(&self) -> &T { &self.0 }
15+
}
16+
817
impl Struct {
918
// Test using `&self` sugar:
1019

@@ -33,6 +42,10 @@ impl Struct {
3342
fn box_pin_ref_Self(self: Box<Pin<&Self>>, f: &u32) -> &u32 {
3443
f //~ ERROR lifetime mismatch
3544
}
45+
46+
fn wrap_ref_Self_Self(self: Wrap<&Self, Self>, f: &u8) -> &u8 {
47+
f //~ ERROR lifetime mismatch
48+
}
3649
}
3750

3851
fn main() { }

src/test/ui/self/elision/ref-self.stderr

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0623]: lifetime mismatch
2-
--> $DIR/ref-self.rs:14:9
2+
--> $DIR/ref-self.rs:21:9
33
|
44
LL | fn ref_self(&self, f: &u32) -> &u32 {
55
| ---- ----
@@ -9,7 +9,7 @@ LL | f
99
| ^ ...but data from `f` is returned here
1010

1111
error[E0623]: lifetime mismatch
12-
--> $DIR/ref-self.rs:20:9
12+
--> $DIR/ref-self.rs:27:9
1313
|
1414
LL | fn ref_Self(self: &Self, f: &u32) -> &u32 {
1515
| ---- ----
@@ -19,7 +19,7 @@ LL | f
1919
| ^ ...but data from `f` is returned here
2020

2121
error[E0623]: lifetime mismatch
22-
--> $DIR/ref-self.rs:24:9
22+
--> $DIR/ref-self.rs:31:9
2323
|
2424
LL | fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 {
2525
| ---- ----
@@ -29,7 +29,7 @@ LL | f
2929
| ^ ...but data from `f` is returned here
3030

3131
error[E0623]: lifetime mismatch
32-
--> $DIR/ref-self.rs:28:9
32+
--> $DIR/ref-self.rs:35:9
3333
|
3434
LL | fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 {
3535
| ---- ----
@@ -39,7 +39,7 @@ LL | f
3939
| ^ ...but data from `f` is returned here
4040

4141
error[E0623]: lifetime mismatch
42-
--> $DIR/ref-self.rs:32:9
42+
--> $DIR/ref-self.rs:39:9
4343
|
4444
LL | fn box_box_ref_Self(self: Box<Box<&Self>>, f: &u32) -> &u32 {
4545
| ---- ----
@@ -49,7 +49,7 @@ LL | f
4949
| ^ ...but data from `f` is returned here
5050

5151
error[E0623]: lifetime mismatch
52-
--> $DIR/ref-self.rs:36:9
52+
--> $DIR/ref-self.rs:43:9
5353
|
5454
LL | fn box_pin_ref_Self(self: Box<Pin<&Self>>, f: &u32) -> &u32 {
5555
| ---- ----
@@ -58,5 +58,15 @@ LL | fn box_pin_ref_Self(self: Box<Pin<&Self>>, f: &u32) -> &u32 {
5858
LL | f
5959
| ^ ...but data from `f` is returned here
6060

61-
error: aborting due to 6 previous errors
61+
error[E0623]: lifetime mismatch
62+
--> $DIR/ref-self.rs:47:9
63+
|
64+
LL | fn wrap_ref_Self_Self(self: Wrap<&Self, Self>, f: &u8) -> &u8 {
65+
| --- ---
66+
| |
67+
| this parameter and the return type are declared with different lifetimes...
68+
LL | f
69+
| ^ ...but data from `f` is returned here
70+
71+
error: aborting due to 7 previous errors
6272

0 commit comments

Comments
 (0)