Skip to content

Commit f4efc5d

Browse files
committed
Add tests for raw_ref_op
1 parent 064bed0 commit f4efc5d

11 files changed

+373
-11
lines changed

src/test/ui-fulldeps/pprust-expr-roundtrip.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,10 @@ fn iter_exprs(depth: usize, f: &mut dyn FnMut(P<Expr>)) {
139139
Some(make_x()), Some(e), RangeLimits::HalfOpen)));
140140
},
141141
15 => {
142-
iter_exprs(depth - 1, &mut |e| g(ExprKind::AddrOf(Mutability::Immutable, e)));
142+
iter_exprs(
143+
depth - 1,
144+
&mut |e| g(ExprKind::AddrOf(BorrowKind::Ref, Mutability::Immutable, e)),
145+
);
143146
},
144147
16 => {
145148
g(ExprKind::Ret(None));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// gate-test-raw_ref_op
2+
3+
macro_rules! is_expr {
4+
($e:expr) => {}
5+
}
6+
7+
is_expr!(&raw const a); //~ ERROR raw address of syntax is experimental
8+
is_expr!(&raw mut a); //~ ERROR raw address of syntax is experimental
9+
10+
#[cfg(FALSE)]
11+
fn cfgd_out() {
12+
let mut a = 0;
13+
&raw const a; //~ ERROR raw address of syntax is experimental
14+
&raw mut a; //~ ERROR raw address of syntax is experimental
15+
}
16+
17+
fn main() {
18+
let mut y = 123;
19+
let x = &raw const y; //~ ERROR raw address of syntax is experimental
20+
let x = &raw mut y; //~ ERROR raw address of syntax is experimental
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
error[E0658]: raw address of syntax is experimental
2+
--> $DIR/feature-raw-ref-op.rs:13:5
3+
|
4+
LL | &raw const a;
5+
| ^^^^^^^^^^
6+
|
7+
= note: for more information, see https://github.com/rust-lang/rust/issues/64490
8+
= help: add `#![feature(raw_ref_op)]` to the crate attributes to enable
9+
10+
error[E0658]: raw address of syntax is experimental
11+
--> $DIR/feature-raw-ref-op.rs:14:5
12+
|
13+
LL | &raw mut a;
14+
| ^^^^^^^^
15+
|
16+
= note: for more information, see https://github.com/rust-lang/rust/issues/64490
17+
= help: add `#![feature(raw_ref_op)]` to the crate attributes to enable
18+
19+
error[E0658]: raw address of syntax is experimental
20+
--> $DIR/feature-raw-ref-op.rs:19:13
21+
|
22+
LL | let x = &raw const y;
23+
| ^^^^^^^^^^
24+
|
25+
= note: for more information, see https://github.com/rust-lang/rust/issues/64490
26+
= help: add `#![feature(raw_ref_op)]` to the crate attributes to enable
27+
28+
error[E0658]: raw address of syntax is experimental
29+
--> $DIR/feature-raw-ref-op.rs:20:13
30+
|
31+
LL | let x = &raw mut y;
32+
| ^^^^^^^^
33+
|
34+
= note: for more information, see https://github.com/rust-lang/rust/issues/64490
35+
= help: add `#![feature(raw_ref_op)]` to the crate attributes to enable
36+
37+
error[E0658]: raw address of syntax is experimental
38+
--> $DIR/feature-raw-ref-op.rs:7:10
39+
|
40+
LL | is_expr!(&raw const a);
41+
| ^^^^^^^^^^
42+
|
43+
= note: for more information, see https://github.com/rust-lang/rust/issues/64490
44+
= help: add `#![feature(raw_ref_op)]` to the crate attributes to enable
45+
46+
error[E0658]: raw address of syntax is experimental
47+
--> $DIR/feature-raw-ref-op.rs:8:10
48+
|
49+
LL | is_expr!(&raw mut a);
50+
| ^^^^^^^^
51+
|
52+
= note: for more information, see https://github.com/rust-lang/rust/issues/64490
53+
= help: add `#![feature(raw_ref_op)]` to the crate attributes to enable
54+
55+
error: aborting due to 6 previous errors
56+
57+
For more information about this error, try `rustc --explain E0658`.

src/test/ui/raw-ref-op/raw-ref-op.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// FIXME(#64490): make this run-pass
2+
3+
#![feature(raw_ref_op)]
4+
5+
fn main() {
6+
let mut x = 123;
7+
let c_p = &raw const x; //~ ERROR not yet implemented
8+
let m_p = &raw mut x; //~ ERROR not yet implemented
9+
let i_r = &x;
10+
assert!(c_p == i_r);
11+
assert!(c_p == m_p);
12+
unsafe { assert!(*c_p == *i_r ); }
13+
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error: raw borrows are not yet implemented
2+
--> $DIR/raw-ref-op.rs:7:15
3+
|
4+
LL | let c_p = &raw const x;
5+
| ^^^^^^^^^^^^
6+
|
7+
= note: for more information, see https://github.com/rust-lang/rust/issues/64490
8+
9+
error: raw borrows are not yet implemented
10+
--> $DIR/raw-ref-op.rs:8:15
11+
|
12+
LL | let m_p = &raw mut x;
13+
| ^^^^^^^^^^
14+
|
15+
= note: for more information, see https://github.com/rust-lang/rust/issues/64490
16+
17+
error: aborting due to 2 previous errors
18+
+15-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
1-
// Ensure that we don't allow taking the address of temporary values
2-
#![feature(raw_ref_op)]
1+
// FIXME(#64490) This should be check-pass
2+
// Check that taking the address of a place that contains a dereference is
3+
// allowed.
4+
#![feature(raw_ref_op, type_ascription)]
35

4-
const PAIR: (i32, i64) = (1, 2);
56
const PAIR_REF: &(i32, i64) = &(1, 2);
67

7-
const ARRAY: [i32; 2] = [1, 2];
88
const ARRAY_REF: &[i32; 2] = &[3, 4];
99
const SLICE_REF: &[i32] = &[5, 6];
1010

1111
fn main() {
1212
// These are all OK, we're not taking the address of the temporary
13-
let deref_ref = &raw const *PAIR_REF; //~ ERROR not yet implemented
14-
let field_deref_ref = &raw const PAIR_REF.0; //~ ERROR not yet implemented
15-
let deref_ref = &raw const *ARRAY_REF; //~ ERROR not yet implemented
16-
let field_deref_ref = &raw const ARRAY_REF[0]; //~ ERROR not yet implemented
17-
let deref_ref = &raw const *SLICE_REF; //~ ERROR not yet implemented
18-
let field_deref_ref = &raw const SLICE_REF[1]; //~ ERROR not yet implemented
13+
let deref_ref = &raw const *PAIR_REF; //~ ERROR not yet implemented
14+
let field_deref_ref = &raw const PAIR_REF.0; //~ ERROR not yet implemented
15+
let deref_ref = &raw const *ARRAY_REF; //~ ERROR not yet implemented
16+
let index_deref_ref = &raw const ARRAY_REF[0]; //~ ERROR not yet implemented
17+
let deref_ref = &raw const *SLICE_REF; //~ ERROR not yet implemented
18+
let index_deref_ref = &raw const SLICE_REF[1]; //~ ERROR not yet implemented
19+
20+
let x = 0;
21+
let ascribe_ref = &raw const (x: i32); //~ ERROR not yet implemented
22+
let ascribe_deref = &raw const (*ARRAY_REF: [i32; 2]); //~ ERROR not yet implemented
23+
let ascribe_index_deref = &raw const (ARRAY_REF[0]: i32); //~ ERROR not yet implemented
1924
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
error: raw borrows are not yet implemented
2+
--> $DIR/raw-ref-temp-deref.rs:13:21
3+
|
4+
LL | let deref_ref = &raw const *PAIR_REF;
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: for more information, see https://github.com/rust-lang/rust/issues/64490
8+
9+
error: raw borrows are not yet implemented
10+
--> $DIR/raw-ref-temp-deref.rs:14:27
11+
|
12+
LL | let field_deref_ref = &raw const PAIR_REF.0;
13+
| ^^^^^^^^^^^^^^^^^^^^^
14+
|
15+
= note: for more information, see https://github.com/rust-lang/rust/issues/64490
16+
17+
error: raw borrows are not yet implemented
18+
--> $DIR/raw-ref-temp-deref.rs:15:21
19+
|
20+
LL | let deref_ref = &raw const *ARRAY_REF;
21+
| ^^^^^^^^^^^^^^^^^^^^^
22+
|
23+
= note: for more information, see https://github.com/rust-lang/rust/issues/64490
24+
25+
error: raw borrows are not yet implemented
26+
--> $DIR/raw-ref-temp-deref.rs:16:27
27+
|
28+
LL | let index_deref_ref = &raw const ARRAY_REF[0];
29+
| ^^^^^^^^^^^^^^^^^^^^^^^
30+
|
31+
= note: for more information, see https://github.com/rust-lang/rust/issues/64490
32+
33+
error: raw borrows are not yet implemented
34+
--> $DIR/raw-ref-temp-deref.rs:17:21
35+
|
36+
LL | let deref_ref = &raw const *SLICE_REF;
37+
| ^^^^^^^^^^^^^^^^^^^^^
38+
|
39+
= note: for more information, see https://github.com/rust-lang/rust/issues/64490
40+
41+
error: raw borrows are not yet implemented
42+
--> $DIR/raw-ref-temp-deref.rs:18:27
43+
|
44+
LL | let index_deref_ref = &raw const SLICE_REF[1];
45+
| ^^^^^^^^^^^^^^^^^^^^^^^
46+
|
47+
= note: for more information, see https://github.com/rust-lang/rust/issues/64490
48+
49+
error: raw borrows are not yet implemented
50+
--> $DIR/raw-ref-temp-deref.rs:21:23
51+
|
52+
LL | let ascribe_ref = &raw const (x: i32);
53+
| ^^^^^^^^^^^^^^^^^^^
54+
|
55+
= note: for more information, see https://github.com/rust-lang/rust/issues/64490
56+
57+
error: raw borrows are not yet implemented
58+
--> $DIR/raw-ref-temp-deref.rs:22:25
59+
|
60+
LL | let ascribe_deref = &raw const (*ARRAY_REF: [i32; 2]);
61+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
62+
|
63+
= note: for more information, see https://github.com/rust-lang/rust/issues/64490
64+
65+
error: raw borrows are not yet implemented
66+
--> $DIR/raw-ref-temp-deref.rs:23:31
67+
|
68+
LL | let ascribe_index_deref = &raw const (ARRAY_REF[0]: i32);
69+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
70+
|
71+
= note: for more information, see https://github.com/rust-lang/rust/issues/64490
72+
73+
error: aborting due to 9 previous errors
74+
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Ensure that we don't allow taking the address of temporary values
2+
#![feature(raw_ref_op, type_ascription)]
3+
4+
const PAIR: (i32, i64) = (1, 2);
5+
6+
const ARRAY: [i32; 2] = [1, 2];
7+
8+
fn main() {
9+
let ref_expr = &raw const 2; //~ ERROR cannot take address
10+
let mut_ref_expr = &raw mut 3; //~ ERROR cannot take address
11+
let ref_const = &raw const 4; //~ ERROR cannot take address
12+
let mut_ref_const = &raw mut 5; //~ ERROR cannot take address
13+
14+
let field_ref_expr = &raw const (1, 2).0; //~ ERROR cannot take address
15+
let mut_field_ref_expr = &raw mut (1, 2).0; //~ ERROR cannot take address
16+
let field_ref = &raw const PAIR.0; //~ ERROR cannot take address
17+
let mut_field_ref = &raw mut PAIR.0; //~ ERROR cannot take address
18+
19+
let index_ref_expr = &raw const [1, 2][0]; //~ ERROR cannot take address
20+
let mut_index_ref_expr = &raw mut [1, 2][0]; //~ ERROR cannot take address
21+
let index_ref = &raw const ARRAY[0]; //~ ERROR cannot take address
22+
let mut_index_ref = &raw mut ARRAY[1]; //~ ERROR cannot take address
23+
24+
let ref_ascribe = &raw const (2: i32); //~ ERROR cannot take address
25+
let mut_ref_ascribe = &raw mut (3: i32); //~ ERROR cannot take address
26+
27+
let ascribe_field_ref = &raw const (PAIR.0: i32); //~ ERROR cannot take address
28+
let ascribe_index_ref = &raw mut (ARRAY[0]: i32); //~ ERROR cannot take address
29+
}
+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
error[E0745]: cannot take address of a temporary
2+
--> $DIR/raw-ref-temp.rs:9:31
3+
|
4+
LL | let ref_expr = &raw const 2;
5+
| ^ temporary value
6+
7+
error[E0745]: cannot take address of a temporary
8+
--> $DIR/raw-ref-temp.rs:10:33
9+
|
10+
LL | let mut_ref_expr = &raw mut 3;
11+
| ^ temporary value
12+
13+
error[E0745]: cannot take address of a temporary
14+
--> $DIR/raw-ref-temp.rs:11:32
15+
|
16+
LL | let ref_const = &raw const 4;
17+
| ^ temporary value
18+
19+
error[E0745]: cannot take address of a temporary
20+
--> $DIR/raw-ref-temp.rs:12:34
21+
|
22+
LL | let mut_ref_const = &raw mut 5;
23+
| ^ temporary value
24+
25+
error[E0745]: cannot take address of a temporary
26+
--> $DIR/raw-ref-temp.rs:14:37
27+
|
28+
LL | let field_ref_expr = &raw const (1, 2).0;
29+
| ^^^^^^^^ temporary value
30+
31+
error[E0745]: cannot take address of a temporary
32+
--> $DIR/raw-ref-temp.rs:15:39
33+
|
34+
LL | let mut_field_ref_expr = &raw mut (1, 2).0;
35+
| ^^^^^^^^ temporary value
36+
37+
error[E0745]: cannot take address of a temporary
38+
--> $DIR/raw-ref-temp.rs:16:32
39+
|
40+
LL | let field_ref = &raw const PAIR.0;
41+
| ^^^^^^ temporary value
42+
43+
error[E0745]: cannot take address of a temporary
44+
--> $DIR/raw-ref-temp.rs:17:34
45+
|
46+
LL | let mut_field_ref = &raw mut PAIR.0;
47+
| ^^^^^^ temporary value
48+
49+
error[E0745]: cannot take address of a temporary
50+
--> $DIR/raw-ref-temp.rs:19:37
51+
|
52+
LL | let index_ref_expr = &raw const [1, 2][0];
53+
| ^^^^^^^^^ temporary value
54+
55+
error[E0745]: cannot take address of a temporary
56+
--> $DIR/raw-ref-temp.rs:20:39
57+
|
58+
LL | let mut_index_ref_expr = &raw mut [1, 2][0];
59+
| ^^^^^^^^^ temporary value
60+
61+
error[E0745]: cannot take address of a temporary
62+
--> $DIR/raw-ref-temp.rs:21:32
63+
|
64+
LL | let index_ref = &raw const ARRAY[0];
65+
| ^^^^^^^^ temporary value
66+
67+
error[E0745]: cannot take address of a temporary
68+
--> $DIR/raw-ref-temp.rs:22:34
69+
|
70+
LL | let mut_index_ref = &raw mut ARRAY[1];
71+
| ^^^^^^^^ temporary value
72+
73+
error[E0745]: cannot take address of a temporary
74+
--> $DIR/raw-ref-temp.rs:24:34
75+
|
76+
LL | let ref_ascribe = &raw const (2: i32);
77+
| ^^^^^^^^ temporary value
78+
79+
error[E0745]: cannot take address of a temporary
80+
--> $DIR/raw-ref-temp.rs:25:36
81+
|
82+
LL | let mut_ref_ascribe = &raw mut (3: i32);
83+
| ^^^^^^^^ temporary value
84+
85+
error[E0745]: cannot take address of a temporary
86+
--> $DIR/raw-ref-temp.rs:27:40
87+
|
88+
LL | let ascribe_field_ref = &raw const (PAIR.0: i32);
89+
| ^^^^^^^^^^^^^ temporary value
90+
91+
error[E0745]: cannot take address of a temporary
92+
--> $DIR/raw-ref-temp.rs:28:38
93+
|
94+
LL | let ascribe_index_ref = &raw mut (ARRAY[0]: i32);
95+
| ^^^^^^^^^^^^^^^ temporary value
96+
97+
error: aborting due to 16 previous errors
98+
99+
For more information about this error, try `rustc --explain E0745`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// FIXME(#64490): make this check-pass
2+
3+
#![feature(raw_ref_op)]
4+
5+
const USES_PTR: () = { let u = (); &raw const u; }; //~ ERROR not yet implemented
6+
static ALSO_USES_PTR: () = { let u = (); &raw const u; }; //~ ERROR not yet implemented
7+
8+
fn main() {
9+
#[cfg(FALSE)]
10+
{
11+
let x: [i32; { let u = 2; let x = &raw const u; 4 }]
12+
= [2; { let v = 3; let y = &raw const v; 4 }];
13+
let mut one = 1;
14+
let two = 2;
15+
if &raw const one == &raw mut one {
16+
match &raw const two {
17+
_ => {}
18+
}
19+
}
20+
let three = 3;
21+
let mut four = 4;
22+
println!("{:p}", &raw const three);
23+
unsafe { &raw mut four; }
24+
}
25+
}

0 commit comments

Comments
 (0)