about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMatthew Jasper <mjjasper1@gmail.com>2019-11-23 14:22:30 +0000
committerMatthew Jasper <mjjasper1@gmail.com>2019-11-24 18:06:13 +0000
commitf4efc5de8a91c8322f83fe07ced5ab119a457ade (patch)
tree524014760e9f85a12d9b8077359bad47383c93ba /src
parent064bed0f31ab9c8dd201bd763141693d92858d76 (diff)
downloadrust-f4efc5de8a91c8322f83fe07ced5ab119a457ade.tar.gz
rust-f4efc5de8a91c8322f83fe07ced5ab119a457ade.zip
Add tests for raw_ref_op
Diffstat (limited to 'src')
-rw-r--r--src/test/ui-fulldeps/pprust-expr-roundtrip.rs5
-rw-r--r--src/test/ui/raw-ref-op/feature-raw-ref-op.rs21
-rw-r--r--src/test/ui/raw-ref-op/feature-raw-ref-op.stderr57
-rw-r--r--src/test/ui/raw-ref-op/raw-ref-op.rs13
-rw-r--r--src/test/ui/raw-ref-op/raw-ref-op.stderr18
-rw-r--r--src/test/ui/raw-ref-op/raw-ref-temp-deref.rs25
-rw-r--r--src/test/ui/raw-ref-op/raw-ref-temp-deref.stderr74
-rw-r--r--src/test/ui/raw-ref-op/raw-ref-temp.rs29
-rw-r--r--src/test/ui/raw-ref-op/raw-ref-temp.stderr99
-rw-r--r--src/test/ui/raw-ref-op/unusual_locations.rs25
-rw-r--r--src/test/ui/raw-ref-op/unusual_locations.stderr18
11 files changed, 373 insertions, 11 deletions
diff --git a/src/test/ui-fulldeps/pprust-expr-roundtrip.rs b/src/test/ui-fulldeps/pprust-expr-roundtrip.rs
index 290562046e2..f19d13ff5c5 100644
--- a/src/test/ui-fulldeps/pprust-expr-roundtrip.rs
+++ b/src/test/ui-fulldeps/pprust-expr-roundtrip.rs
@@ -139,7 +139,10 @@ fn iter_exprs(depth: usize, f: &mut dyn FnMut(P<Expr>)) {
                             Some(make_x()), Some(e), RangeLimits::HalfOpen)));
             },
             15 => {
-                iter_exprs(depth - 1, &mut |e| g(ExprKind::AddrOf(Mutability::Immutable, e)));
+                iter_exprs(
+                    depth - 1,
+                    &mut |e| g(ExprKind::AddrOf(BorrowKind::Ref, Mutability::Immutable, e)),
+                );
             },
             16 => {
                 g(ExprKind::Ret(None));
diff --git a/src/test/ui/raw-ref-op/feature-raw-ref-op.rs b/src/test/ui/raw-ref-op/feature-raw-ref-op.rs
new file mode 100644
index 00000000000..0a44b1cde40
--- /dev/null
+++ b/src/test/ui/raw-ref-op/feature-raw-ref-op.rs
@@ -0,0 +1,21 @@
+// gate-test-raw_ref_op
+
+macro_rules! is_expr {
+    ($e:expr) => {}
+}
+
+is_expr!(&raw const a);         //~ ERROR raw address of syntax is experimental
+is_expr!(&raw mut a);           //~ ERROR raw address of syntax is experimental
+
+#[cfg(FALSE)]
+fn cfgd_out() {
+    let mut a = 0;
+    &raw const a;               //~ ERROR raw address of syntax is experimental
+    &raw mut a;                 //~ ERROR raw address of syntax is experimental
+}
+
+fn main() {
+    let mut y = 123;
+    let x = &raw const y;       //~ ERROR raw address of syntax is experimental
+    let x = &raw mut y;         //~ ERROR raw address of syntax is experimental
+}
diff --git a/src/test/ui/raw-ref-op/feature-raw-ref-op.stderr b/src/test/ui/raw-ref-op/feature-raw-ref-op.stderr
new file mode 100644
index 00000000000..cbd413aec7b
--- /dev/null
+++ b/src/test/ui/raw-ref-op/feature-raw-ref-op.stderr
@@ -0,0 +1,57 @@
+error[E0658]: raw address of syntax is experimental
+  --> $DIR/feature-raw-ref-op.rs:13:5
+   |
+LL |     &raw const a;
+   |     ^^^^^^^^^^
+   |
+   = note: for more information, see https://github.com/rust-lang/rust/issues/64490
+   = help: add `#![feature(raw_ref_op)]` to the crate attributes to enable
+
+error[E0658]: raw address of syntax is experimental
+  --> $DIR/feature-raw-ref-op.rs:14:5
+   |
+LL |     &raw mut a;
+   |     ^^^^^^^^
+   |
+   = note: for more information, see https://github.com/rust-lang/rust/issues/64490
+   = help: add `#![feature(raw_ref_op)]` to the crate attributes to enable
+
+error[E0658]: raw address of syntax is experimental
+  --> $DIR/feature-raw-ref-op.rs:19:13
+   |
+LL |     let x = &raw const y;
+   |             ^^^^^^^^^^
+   |
+   = note: for more information, see https://github.com/rust-lang/rust/issues/64490
+   = help: add `#![feature(raw_ref_op)]` to the crate attributes to enable
+
+error[E0658]: raw address of syntax is experimental
+  --> $DIR/feature-raw-ref-op.rs:20:13
+   |
+LL |     let x = &raw mut y;
+   |             ^^^^^^^^
+   |
+   = note: for more information, see https://github.com/rust-lang/rust/issues/64490
+   = help: add `#![feature(raw_ref_op)]` to the crate attributes to enable
+
+error[E0658]: raw address of syntax is experimental
+  --> $DIR/feature-raw-ref-op.rs:7:10
+   |
+LL | is_expr!(&raw const a);
+   |          ^^^^^^^^^^
+   |
+   = note: for more information, see https://github.com/rust-lang/rust/issues/64490
+   = help: add `#![feature(raw_ref_op)]` to the crate attributes to enable
+
+error[E0658]: raw address of syntax is experimental
+  --> $DIR/feature-raw-ref-op.rs:8:10
+   |
+LL | is_expr!(&raw mut a);
+   |          ^^^^^^^^
+   |
+   = note: for more information, see https://github.com/rust-lang/rust/issues/64490
+   = help: add `#![feature(raw_ref_op)]` to the crate attributes to enable
+
+error: aborting due to 6 previous errors
+
+For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/raw-ref-op/raw-ref-op.rs b/src/test/ui/raw-ref-op/raw-ref-op.rs
new file mode 100644
index 00000000000..de847909eb3
--- /dev/null
+++ b/src/test/ui/raw-ref-op/raw-ref-op.rs
@@ -0,0 +1,13 @@
+// FIXME(#64490): make this run-pass
+
+#![feature(raw_ref_op)]
+
+fn main() {
+    let mut x = 123;
+    let c_p = &raw const x;                     //~ ERROR not yet implemented
+    let m_p = &raw mut x;                       //~ ERROR not yet implemented
+    let i_r = &x;
+    assert!(c_p == i_r);
+    assert!(c_p == m_p);
+    unsafe { assert!(*c_p == *i_r ); }
+}
diff --git a/src/test/ui/raw-ref-op/raw-ref-op.stderr b/src/test/ui/raw-ref-op/raw-ref-op.stderr
new file mode 100644
index 00000000000..04c59c95fca
--- /dev/null
+++ b/src/test/ui/raw-ref-op/raw-ref-op.stderr
@@ -0,0 +1,18 @@
+error: raw borrows are not yet implemented
+  --> $DIR/raw-ref-op.rs:7:15
+   |
+LL |     let c_p = &raw const x;
+   |               ^^^^^^^^^^^^
+   |
+   = note: for more information, see https://github.com/rust-lang/rust/issues/64490
+
+error: raw borrows are not yet implemented
+  --> $DIR/raw-ref-op.rs:8:15
+   |
+LL |     let m_p = &raw mut x;
+   |               ^^^^^^^^^^
+   |
+   = note: for more information, see https://github.com/rust-lang/rust/issues/64490
+
+error: aborting due to 2 previous errors
+
diff --git a/src/test/ui/raw-ref-op/raw-ref-temp-deref.rs b/src/test/ui/raw-ref-op/raw-ref-temp-deref.rs
index 22de148e4c2..d251586de55 100644
--- a/src/test/ui/raw-ref-op/raw-ref-temp-deref.rs
+++ b/src/test/ui/raw-ref-op/raw-ref-temp-deref.rs
@@ -1,19 +1,24 @@
-// Ensure that we don't allow taking the address of temporary values
-#![feature(raw_ref_op)]
+// FIXME(#64490) This should be check-pass
+// Check that taking the address of a place that contains a dereference is
+// allowed.
+#![feature(raw_ref_op, type_ascription)]
 
-const PAIR: (i32, i64) = (1, 2);
 const PAIR_REF: &(i32, i64) = &(1, 2);
 
-const ARRAY: [i32; 2] = [1, 2];
 const ARRAY_REF: &[i32; 2] = &[3, 4];
 const SLICE_REF: &[i32] = &[5, 6];
 
 fn main() {
     // These are all OK, we're not taking the address of the temporary
-    let deref_ref = &raw const *PAIR_REF;               //~ ERROR not yet implemented
-    let field_deref_ref = &raw const PAIR_REF.0;        //~ ERROR not yet implemented
-    let deref_ref = &raw const *ARRAY_REF;              //~ ERROR not yet implemented
-    let field_deref_ref = &raw const ARRAY_REF[0];      //~ ERROR not yet implemented
-    let deref_ref = &raw const *SLICE_REF;              //~ ERROR not yet implemented
-    let field_deref_ref = &raw const SLICE_REF[1];      //~ ERROR not yet implemented
+    let deref_ref = &raw const *PAIR_REF;                       //~ ERROR not yet implemented
+    let field_deref_ref = &raw const PAIR_REF.0;                //~ ERROR not yet implemented
+    let deref_ref = &raw const *ARRAY_REF;                      //~ ERROR not yet implemented
+    let index_deref_ref = &raw const ARRAY_REF[0];              //~ ERROR not yet implemented
+    let deref_ref = &raw const *SLICE_REF;                      //~ ERROR not yet implemented
+    let index_deref_ref = &raw const SLICE_REF[1];              //~ ERROR not yet implemented
+
+    let x = 0;
+    let ascribe_ref = &raw const (x: i32);                      //~ ERROR not yet implemented
+    let ascribe_deref = &raw const (*ARRAY_REF: [i32; 2]);      //~ ERROR not yet implemented
+    let ascribe_index_deref = &raw const (ARRAY_REF[0]: i32);   //~ ERROR not yet implemented
 }
diff --git a/src/test/ui/raw-ref-op/raw-ref-temp-deref.stderr b/src/test/ui/raw-ref-op/raw-ref-temp-deref.stderr
new file mode 100644
index 00000000000..b0bfc74903b
--- /dev/null
+++ b/src/test/ui/raw-ref-op/raw-ref-temp-deref.stderr
@@ -0,0 +1,74 @@
+error: raw borrows are not yet implemented
+  --> $DIR/raw-ref-temp-deref.rs:13:21
+   |
+LL |     let deref_ref = &raw const *PAIR_REF;
+   |                     ^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: for more information, see https://github.com/rust-lang/rust/issues/64490
+
+error: raw borrows are not yet implemented
+  --> $DIR/raw-ref-temp-deref.rs:14:27
+   |
+LL |     let field_deref_ref = &raw const PAIR_REF.0;
+   |                           ^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: for more information, see https://github.com/rust-lang/rust/issues/64490
+
+error: raw borrows are not yet implemented
+  --> $DIR/raw-ref-temp-deref.rs:15:21
+   |
+LL |     let deref_ref = &raw const *ARRAY_REF;
+   |                     ^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: for more information, see https://github.com/rust-lang/rust/issues/64490
+
+error: raw borrows are not yet implemented
+  --> $DIR/raw-ref-temp-deref.rs:16:27
+   |
+LL |     let index_deref_ref = &raw const ARRAY_REF[0];
+   |                           ^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: for more information, see https://github.com/rust-lang/rust/issues/64490
+
+error: raw borrows are not yet implemented
+  --> $DIR/raw-ref-temp-deref.rs:17:21
+   |
+LL |     let deref_ref = &raw const *SLICE_REF;
+   |                     ^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: for more information, see https://github.com/rust-lang/rust/issues/64490
+
+error: raw borrows are not yet implemented
+  --> $DIR/raw-ref-temp-deref.rs:18:27
+   |
+LL |     let index_deref_ref = &raw const SLICE_REF[1];
+   |                           ^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: for more information, see https://github.com/rust-lang/rust/issues/64490
+
+error: raw borrows are not yet implemented
+  --> $DIR/raw-ref-temp-deref.rs:21:23
+   |
+LL |     let ascribe_ref = &raw const (x: i32);
+   |                       ^^^^^^^^^^^^^^^^^^^
+   |
+   = note: for more information, see https://github.com/rust-lang/rust/issues/64490
+
+error: raw borrows are not yet implemented
+  --> $DIR/raw-ref-temp-deref.rs:22:25
+   |
+LL |     let ascribe_deref = &raw const (*ARRAY_REF: [i32; 2]);
+   |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: for more information, see https://github.com/rust-lang/rust/issues/64490
+
+error: raw borrows are not yet implemented
+  --> $DIR/raw-ref-temp-deref.rs:23:31
+   |
+LL |     let ascribe_index_deref = &raw const (ARRAY_REF[0]: i32);
+   |                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: for more information, see https://github.com/rust-lang/rust/issues/64490
+
+error: aborting due to 9 previous errors
+
diff --git a/src/test/ui/raw-ref-op/raw-ref-temp.rs b/src/test/ui/raw-ref-op/raw-ref-temp.rs
new file mode 100644
index 00000000000..ac2445f049c
--- /dev/null
+++ b/src/test/ui/raw-ref-op/raw-ref-temp.rs
@@ -0,0 +1,29 @@
+// Ensure that we don't allow taking the address of temporary values
+#![feature(raw_ref_op, type_ascription)]
+
+const PAIR: (i32, i64) = (1, 2);
+
+const ARRAY: [i32; 2] = [1, 2];
+
+fn main() {
+    let ref_expr = &raw const 2;                        //~ ERROR cannot take address
+    let mut_ref_expr = &raw mut 3;                      //~ ERROR cannot take address
+    let ref_const = &raw const 4;                       //~ ERROR cannot take address
+    let mut_ref_const = &raw mut 5;                     //~ ERROR cannot take address
+
+    let field_ref_expr = &raw const (1, 2).0;           //~ ERROR cannot take address
+    let mut_field_ref_expr = &raw mut (1, 2).0;         //~ ERROR cannot take address
+    let field_ref = &raw const PAIR.0;                  //~ ERROR cannot take address
+    let mut_field_ref = &raw mut PAIR.0;                //~ ERROR cannot take address
+
+    let index_ref_expr = &raw const [1, 2][0];          //~ ERROR cannot take address
+    let mut_index_ref_expr = &raw mut [1, 2][0];        //~ ERROR cannot take address
+    let index_ref = &raw const ARRAY[0];                //~ ERROR cannot take address
+    let mut_index_ref = &raw mut ARRAY[1];              //~ ERROR cannot take address
+
+    let ref_ascribe = &raw const (2: i32);              //~ ERROR cannot take address
+    let mut_ref_ascribe = &raw mut (3: i32);            //~ ERROR cannot take address
+
+    let ascribe_field_ref = &raw const (PAIR.0: i32);   //~ ERROR cannot take address
+    let ascribe_index_ref = &raw mut (ARRAY[0]: i32);   //~ ERROR cannot take address
+}
diff --git a/src/test/ui/raw-ref-op/raw-ref-temp.stderr b/src/test/ui/raw-ref-op/raw-ref-temp.stderr
new file mode 100644
index 00000000000..de070733735
--- /dev/null
+++ b/src/test/ui/raw-ref-op/raw-ref-temp.stderr
@@ -0,0 +1,99 @@
+error[E0745]: cannot take address of a temporary
+  --> $DIR/raw-ref-temp.rs:9:31
+   |
+LL |     let ref_expr = &raw const 2;
+   |                               ^ temporary value
+
+error[E0745]: cannot take address of a temporary
+  --> $DIR/raw-ref-temp.rs:10:33
+   |
+LL |     let mut_ref_expr = &raw mut 3;
+   |                                 ^ temporary value
+
+error[E0745]: cannot take address of a temporary
+  --> $DIR/raw-ref-temp.rs:11:32
+   |
+LL |     let ref_const = &raw const 4;
+   |                                ^ temporary value
+
+error[E0745]: cannot take address of a temporary
+  --> $DIR/raw-ref-temp.rs:12:34
+   |
+LL |     let mut_ref_const = &raw mut 5;
+   |                                  ^ temporary value
+
+error[E0745]: cannot take address of a temporary
+  --> $DIR/raw-ref-temp.rs:14:37
+   |
+LL |     let field_ref_expr = &raw const (1, 2).0;
+   |                                     ^^^^^^^^ temporary value
+
+error[E0745]: cannot take address of a temporary
+  --> $DIR/raw-ref-temp.rs:15:39
+   |
+LL |     let mut_field_ref_expr = &raw mut (1, 2).0;
+   |                                       ^^^^^^^^ temporary value
+
+error[E0745]: cannot take address of a temporary
+  --> $DIR/raw-ref-temp.rs:16:32
+   |
+LL |     let field_ref = &raw const PAIR.0;
+   |                                ^^^^^^ temporary value
+
+error[E0745]: cannot take address of a temporary
+  --> $DIR/raw-ref-temp.rs:17:34
+   |
+LL |     let mut_field_ref = &raw mut PAIR.0;
+   |                                  ^^^^^^ temporary value
+
+error[E0745]: cannot take address of a temporary
+  --> $DIR/raw-ref-temp.rs:19:37
+   |
+LL |     let index_ref_expr = &raw const [1, 2][0];
+   |                                     ^^^^^^^^^ temporary value
+
+error[E0745]: cannot take address of a temporary
+  --> $DIR/raw-ref-temp.rs:20:39
+   |
+LL |     let mut_index_ref_expr = &raw mut [1, 2][0];
+   |                                       ^^^^^^^^^ temporary value
+
+error[E0745]: cannot take address of a temporary
+  --> $DIR/raw-ref-temp.rs:21:32
+   |
+LL |     let index_ref = &raw const ARRAY[0];
+   |                                ^^^^^^^^ temporary value
+
+error[E0745]: cannot take address of a temporary
+  --> $DIR/raw-ref-temp.rs:22:34
+   |
+LL |     let mut_index_ref = &raw mut ARRAY[1];
+   |                                  ^^^^^^^^ temporary value
+
+error[E0745]: cannot take address of a temporary
+  --> $DIR/raw-ref-temp.rs:24:34
+   |
+LL |     let ref_ascribe = &raw const (2: i32);
+   |                                  ^^^^^^^^ temporary value
+
+error[E0745]: cannot take address of a temporary
+  --> $DIR/raw-ref-temp.rs:25:36
+   |
+LL |     let mut_ref_ascribe = &raw mut (3: i32);
+   |                                    ^^^^^^^^ temporary value
+
+error[E0745]: cannot take address of a temporary
+  --> $DIR/raw-ref-temp.rs:27:40
+   |
+LL |     let ascribe_field_ref = &raw const (PAIR.0: i32);
+   |                                        ^^^^^^^^^^^^^ temporary value
+
+error[E0745]: cannot take address of a temporary
+  --> $DIR/raw-ref-temp.rs:28:38
+   |
+LL |     let ascribe_index_ref = &raw mut (ARRAY[0]: i32);
+   |                                      ^^^^^^^^^^^^^^^ temporary value
+
+error: aborting due to 16 previous errors
+
+For more information about this error, try `rustc --explain E0745`.
diff --git a/src/test/ui/raw-ref-op/unusual_locations.rs b/src/test/ui/raw-ref-op/unusual_locations.rs
new file mode 100644
index 00000000000..f0a6bcce2ac
--- /dev/null
+++ b/src/test/ui/raw-ref-op/unusual_locations.rs
@@ -0,0 +1,25 @@
+// FIXME(#64490): make this check-pass
+
+#![feature(raw_ref_op)]
+
+const USES_PTR: () = { let u = (); &raw const u; };         //~ ERROR not yet implemented
+static ALSO_USES_PTR: () = { let u = (); &raw const u; };   //~ ERROR not yet implemented
+
+fn main() {
+    #[cfg(FALSE)]
+    {
+        let x: [i32; { let u = 2; let x = &raw const u; 4 }]
+            = [2; { let v = 3; let y = &raw const v; 4 }];
+        let mut one = 1;
+        let two = 2;
+        if &raw const one == &raw mut one {
+            match &raw const two {
+                _ => {}
+            }
+        }
+        let three = 3;
+        let mut four = 4;
+        println!("{:p}", &raw const three);
+        unsafe { &raw mut four; }
+    }
+}
diff --git a/src/test/ui/raw-ref-op/unusual_locations.stderr b/src/test/ui/raw-ref-op/unusual_locations.stderr
new file mode 100644
index 00000000000..3fae5db3d51
--- /dev/null
+++ b/src/test/ui/raw-ref-op/unusual_locations.stderr
@@ -0,0 +1,18 @@
+error: raw borrows are not yet implemented
+  --> $DIR/unusual_locations.rs:5:36
+   |
+LL | const USES_PTR: () = { let u = (); &raw const u; };
+   |                                    ^^^^^^^^^^^^
+   |
+   = note: for more information, see https://github.com/rust-lang/rust/issues/64490
+
+error: raw borrows are not yet implemented
+  --> $DIR/unusual_locations.rs:6:42
+   |
+LL | static ALSO_USES_PTR: () = { let u = (); &raw const u; };
+   |                                          ^^^^^^^^^^^^
+   |
+   = note: for more information, see https://github.com/rust-lang/rust/issues/64490
+
+error: aborting due to 2 previous errors
+