Skip to content

Commit bdc8b93

Browse files
nikomatsakistaiki-e
authored andcommitted
add a bevy of new test cases
1 parent a2b4ec2 commit bdc8b93

21 files changed

+831
-0
lines changed

src/test/ui/self/elision/README.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
Test cases intended to to document behavior and tryto exhaustively
2+
explore the combinations.
3+
4+
## Confidence
5+
6+
These tests are not yet considered 100% normative, in that some
7+
aspects of the current behavior are not desirable. This is expressed
8+
in the "confidence" field in the following table. Values:
9+
10+
| Confidence | Interpretation |
11+
| --- | --- |
12+
| 100% | this will remain recommended behavior |
13+
| 75% | unclear whether we will continue to accept this |
14+
| 50% | this will likely be deprecated but remain valid |
15+
| 25% | this could change in the future |
16+
| 0% | this is definitely bogus and will likely change in the future in *some* way |
17+
18+
## Tests
19+
20+
| Test file | `Self` type | Pattern | Current elision behavior | Confidence |
21+
| --- | --- | --- | --- | --- |
22+
| `self.rs` | `Struct` | `Self` | ignore `self` parameter | 100% |
23+
| `struct.rs` | `Struct` | `Struct` | ignore `self` parameter | 100% |
24+
| `alias.rs` | `Struct` | `Alias` | ignore `self` parameter | 100% |
25+
| `ref-self.rs` | `Struct` | `&Self` | take lifetime from `&Self` | 100% |
26+
| `ref-mut-self.rs` | `Struct` | `&mut Self` | take lifetime from `&Self` | 100% |
27+
| `ref-struct.rs` | `Struct` | `&Struct` | take lifetime from `&Self` | 50% |
28+
| `ref-mut-struct.rs` | `Struct` | `&Struct` | take lifetime from `&Self` | 50% |
29+
| `ref-alias.rs` | `Struct` | `&Alias` | ignore `Alias` | 0% |
30+
| `ref-mut-alias.rs` | `Struct` | `&Alias` | ignore `Alias` | 0% |
31+
| `lt-self.rs` | `Struct<'a>` | `Self` | ignore `Self` (and hence `'a`) | 25% |
32+
| `lt-struct.rs` | `Struct<'a>` | `Self` | ignore `Self` (and hence `'a`) | 0% |
33+
| `lt-alias.rs` | `Alias<'a>` | `Self` | ignore `Self` (and hence `'a`) | 0% |
34+
| `lt-ref-self.rs` | `Struct<'a>` | `&Self` | take lifetime from `&Self` | 75% |
35+
36+
In each case, we test the following patterns:
37+
38+
- `self: XXX`
39+
- `self: Box<XXX>`
40+
- `self: Pin<XXX>`
41+
- `self: Box<Box<XXX>>`
42+
- `self: Box<Pin<XXX>>`
43+
44+
In the non-reference cases, `Pin` causes errors so we substitute `Rc`.
45+

src/test/ui/self/elision/alias.rs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#![feature(arbitrary_self_types)]
2+
#![allow(non_snake_case)]
3+
4+
use std::rc::Rc;
5+
6+
struct Struct { }
7+
8+
type Alias = Struct;
9+
10+
impl Struct {
11+
// Test using an alias for `Struct`:
12+
13+
fn alias(self: Alias, f: &u32) -> &u32 {
14+
f
15+
}
16+
17+
fn box_Alias(self: Box<Alias>, f: &u32) -> &u32 {
18+
f
19+
}
20+
21+
fn rc_Alias(self: Rc<Alias>, f: &u32) -> &u32 {
22+
f
23+
}
24+
25+
fn box_box_Alias(self: Box<Box<Alias>>, f: &u32) -> &u32 {
26+
f
27+
}
28+
29+
fn box_rc_Alias(self: Box<Rc<Alias>>, f: &u32) -> &u32 {
30+
f
31+
}
32+
}

src/test/ui/self/elision/alias.stderr

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
error[E0601]: `main` function not found in crate `alias`
2+
|
3+
= note: consider adding a `main` function to `$DIR/alias.rs`
4+
5+
error: aborting due to previous error
6+
7+
For more information about this error, try `rustc --explain E0601`.

src/test/ui/self/elision/lt-alias.rs

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// run-pass
2+
3+
#![feature(arbitrary_self_types)]
4+
#![allow(non_snake_case)]
5+
6+
use std::rc::Rc;
7+
8+
struct Struct<'a> { x: &'a u32 }
9+
10+
type Alias<'a> = Struct<'a>;
11+
12+
impl<'a> Alias<'a> {
13+
fn take_self(self, f: &u32) -> &u32 {
14+
f
15+
}
16+
17+
fn take_Alias(self: Alias<'a>, f: &u32) -> &u32 {
18+
f
19+
}
20+
21+
fn take_Box_Alias(self: Box<Alias<'a>>, f: &u32) -> &u32 {
22+
f
23+
}
24+
25+
fn take_Box_Box_Alias(self: Box<Box<Alias<'a>>>, f: &u32) -> &u32 {
26+
f
27+
}
28+
29+
fn take_Rc_Alias(self: Rc<Alias<'a>>, f: &u32) -> &u32 {
30+
f
31+
}
32+
33+
fn take_Box_Rc_Alias(self: Box<Rc<Alias<'a>>>, f: &u32) -> &u32 {
34+
f
35+
}
36+
}
37+
38+
fn main() { }
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#![feature(arbitrary_self_types)]
2+
#![allow(non_snake_case)]
3+
4+
use std::pin::Pin;
5+
6+
struct Struct<'a> { data: &'a u32 }
7+
8+
impl<'a> Struct<'a> {
9+
// Test using `&self` sugar:
10+
11+
fn ref_self(&self, f: &u32) -> &u32 {
12+
f //~ ERROR lifetime mismatch
13+
}
14+
15+
// Test using `&Self` explicitly:
16+
17+
fn ref_Self(self: &Self, f: &u32) -> &u32 {
18+
f //~ ERROR lifetime mismatch
19+
}
20+
21+
fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 {
22+
f //~ ERROR lifetime mismatch
23+
}
24+
25+
fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 {
26+
f //~ ERROR lifetime mismatch
27+
}
28+
29+
fn box_box_ref_Self(self: Box<Box<&Self>>, f: &u32) -> &u32 {
30+
f //~ ERROR lifetime mismatch
31+
}
32+
33+
fn box_pin_Self(self: Box<Pin<&Self>>, f: &u32) -> &u32 {
34+
f //~ ERROR lifetime mismatch
35+
}
36+
}
37+
38+
fn main() { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
error[E0623]: lifetime mismatch
2+
--> $DIR/lt-ref-self.rs:12:9
3+
|
4+
LL | fn ref_self(&self, f: &u32) -> &u32 {
5+
| ---- ----
6+
| |
7+
| this parameter and the return type are declared with different lifetimes...
8+
LL | f
9+
| ^ ...but data from `f` is returned here
10+
11+
error[E0623]: lifetime mismatch
12+
--> $DIR/lt-ref-self.rs:18:9
13+
|
14+
LL | fn ref_Self(self: &Self, f: &u32) -> &u32 {
15+
| ---- ----
16+
| |
17+
| this parameter and the return type are declared with different lifetimes...
18+
LL | f
19+
| ^ ...but data from `f` is returned here
20+
21+
error[E0623]: lifetime mismatch
22+
--> $DIR/lt-ref-self.rs:22:9
23+
|
24+
LL | fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 {
25+
| ---- ----
26+
| |
27+
| this parameter and the return type are declared with different lifetimes...
28+
LL | f
29+
| ^ ...but data from `f` is returned here
30+
31+
error[E0623]: lifetime mismatch
32+
--> $DIR/lt-ref-self.rs:26:9
33+
|
34+
LL | fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 {
35+
| ---- ----
36+
| |
37+
| this parameter and the return type are declared with different lifetimes...
38+
LL | f
39+
| ^ ...but data from `f` is returned here
40+
41+
error[E0623]: lifetime mismatch
42+
--> $DIR/lt-ref-self.rs:30:9
43+
|
44+
LL | fn box_box_ref_Self(self: Box<Box<&Self>>, f: &u32) -> &u32 {
45+
| ---- ----
46+
| |
47+
| this parameter and the return type are declared with different lifetimes...
48+
LL | f
49+
| ^ ...but data from `f` is returned here
50+
51+
error[E0623]: lifetime mismatch
52+
--> $DIR/lt-ref-self.rs:34:9
53+
|
54+
LL | fn box_pin_Self(self: Box<Pin<&Self>>, f: &u32) -> &u32 {
55+
| ---- ----
56+
| |
57+
| this parameter and the return type are declared with different lifetimes...
58+
LL | f
59+
| ^ ...but data from `f` is returned here
60+
61+
error: aborting due to 6 previous errors
62+

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

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// run-pass
2+
3+
#![feature(arbitrary_self_types)]
4+
#![allow(non_snake_case)]
5+
6+
use std::pin::Pin;
7+
use std::rc::Rc;
8+
9+
struct Struct<'a> {
10+
x: &'a u32
11+
}
12+
13+
impl<'a> Struct<'a> {
14+
fn take_self(self, f: &u32) -> &u32 {
15+
f
16+
}
17+
18+
fn take_Self(self: Self, f: &u32) -> &u32 {
19+
f
20+
}
21+
22+
fn take_Box_Self(self: Box<Self>, f: &u32) -> &u32 {
23+
f
24+
}
25+
26+
fn take_Box_Box_Self(self: Box<Box<Self>>, f: &u32) -> &u32 {
27+
f
28+
}
29+
30+
fn take_Rc_Self(self: Rc<Self>, f: &u32) -> &u32 {
31+
f
32+
}
33+
34+
fn take_Box_Rc_Self(self: Box<Rc<Self>>, f: &u32) -> &u32 {
35+
f
36+
}
37+
38+
// N/A
39+
//fn take_Pin_Self(self: Pin<Self>, f: &u32) -> &u32 {
40+
// f
41+
//}
42+
43+
// N/A
44+
//fn take_Box_Pin_Self(self: Box<Pin<Self>>, f: &u32) -> &u32 {
45+
// f
46+
//}
47+
}
48+
49+
fn main() { }

src/test/ui/self/elision/lt-struct.rs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// run-pass
2+
3+
#![feature(arbitrary_self_types)]
4+
#![allow(non_snake_case)]
5+
6+
use std::rc::Rc;
7+
8+
struct Struct<'a> { x: &'a u32 }
9+
10+
impl<'a> Struct<'a> {
11+
fn take_self(self, f: &u32) -> &u32 {
12+
f
13+
}
14+
15+
fn take_Struct(self: Struct<'a>, f: &u32) -> &u32 {
16+
f
17+
}
18+
19+
fn take_Box_Struct(self: Box<Struct<'a>>, f: &u32) -> &u32 {
20+
f
21+
}
22+
23+
fn take_Box_Box_Struct(self: Box<Box<Struct<'a>>>, f: &u32) -> &u32 {
24+
f
25+
}
26+
27+
fn take_Rc_Struct(self: Rc<Struct<'a>>, f: &u32) -> &u32 {
28+
f
29+
}
30+
31+
fn take_Box_Rc_Struct(self: Box<Rc<Struct<'a>>>, f: &u32) -> &u32 {
32+
f
33+
}
34+
}
35+
36+
fn main() { }

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

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// run-pass
2+
3+
#![feature(arbitrary_self_types)]
4+
#![allow(non_snake_case)]
5+
6+
use std::pin::Pin;
7+
8+
struct Struct { }
9+
10+
type Alias = Struct;
11+
12+
impl Struct {
13+
// Test using an alias for `Struct`:
14+
//
15+
// FIXME. We currently fail to recognize this as the self type, which
16+
// feels like a bug.
17+
18+
fn ref_Alias(self: &Alias, f: &u32) -> &u32 {
19+
f
20+
}
21+
22+
fn box_ref_Alias(self: Box<&Alias>, f: &u32) -> &u32 {
23+
f
24+
}
25+
26+
fn pin_ref_Alias(self: Pin<&Alias>, f: &u32) -> &u32 {
27+
f
28+
}
29+
30+
fn box_box_ref_Alias(self: Box<Box<&Alias>>, f: &u32) -> &u32 {
31+
f
32+
}
33+
34+
fn box_pin_ref_Alias(self: Box<Pin<&Alias>>, f: &u32) -> &u32 {
35+
f
36+
}
37+
}
38+
39+
fn main() { }
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#![feature(arbitrary_self_types)]
2+
#![allow(non_snake_case)]
3+
4+
use std::pin::Pin;
5+
6+
struct Struct { }
7+
8+
type Alias = Struct;
9+
10+
impl Struct {
11+
// Test using an alias for `Struct`:
12+
13+
fn ref_Alias(self: &mut Alias, f: &u32) -> &u32 {
14+
f
15+
}
16+
17+
fn box_ref_Alias(self: Box<&mut Alias>, f: &u32) -> &u32 {
18+
f
19+
}
20+
21+
fn pin_ref_Alias(self: Pin<&mut Alias>, f: &u32) -> &u32 {
22+
f
23+
}
24+
25+
fn box_box_ref_Alias(self: Box<Box<&mut Alias>>, f: &u32) -> &u32 {
26+
f
27+
}
28+
29+
fn box_pin_ref_Alias(self: Box<Pin<&mut Alias>>, f: &u32) -> &u32 {
30+
f
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
error[E0601]: `main` function not found in crate `ref_mut_alias`
2+
|
3+
= note: consider adding a `main` function to `$DIR/ref-mut-alias.rs`
4+
5+
error: aborting due to previous error
6+
7+
For more information about this error, try `rustc --explain E0601`.

0 commit comments

Comments
 (0)