summaryrefslogtreecommitdiffstats
path: root/tests/ui/raw-ref-op
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/raw-ref-op
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/raw-ref-op')
-rw-r--r--tests/ui/raw-ref-op/feature-raw-ref-op.rs21
-rw-r--r--tests/ui/raw-ref-op/feature-raw-ref-op.stderr57
-rw-r--r--tests/ui/raw-ref-op/raw-ref-op.rs13
-rw-r--r--tests/ui/raw-ref-op/raw-ref-temp-deref.rs24
-rw-r--r--tests/ui/raw-ref-op/raw-ref-temp.rs31
-rw-r--r--tests/ui/raw-ref-op/raw-ref-temp.stderr99
-rw-r--r--tests/ui/raw-ref-op/unusual_locations.rs22
7 files changed, 267 insertions, 0 deletions
diff --git a/tests/ui/raw-ref-op/feature-raw-ref-op.rs b/tests/ui/raw-ref-op/feature-raw-ref-op.rs
new file mode 100644
index 000000000..0a44b1cde
--- /dev/null
+++ b/tests/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/tests/ui/raw-ref-op/feature-raw-ref-op.stderr b/tests/ui/raw-ref-op/feature-raw-ref-op.stderr
new file mode 100644
index 000000000..1e5fd84ff
--- /dev/null
+++ b/tests/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: see issue #64490 <https://github.com/rust-lang/rust/issues/64490> for more information
+ = 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: see issue #64490 <https://github.com/rust-lang/rust/issues/64490> for more information
+ = 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: see issue #64490 <https://github.com/rust-lang/rust/issues/64490> for more information
+ = 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: see issue #64490 <https://github.com/rust-lang/rust/issues/64490> for more information
+ = 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: see issue #64490 <https://github.com/rust-lang/rust/issues/64490> for more information
+ = 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: see issue #64490 <https://github.com/rust-lang/rust/issues/64490> for more information
+ = 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/tests/ui/raw-ref-op/raw-ref-op.rs b/tests/ui/raw-ref-op/raw-ref-op.rs
new file mode 100644
index 000000000..0c6e23a00
--- /dev/null
+++ b/tests/ui/raw-ref-op/raw-ref-op.rs
@@ -0,0 +1,13 @@
+// run-pass
+
+#![feature(raw_ref_op)]
+
+fn main() {
+ let mut x = 123;
+ let c_p = &raw const x;
+ let m_p = &raw mut x;
+ let i_r = &x;
+ assert!(c_p == i_r);
+ assert!(c_p == m_p);
+ unsafe { assert!(*c_p == *i_r ); }
+}
diff --git a/tests/ui/raw-ref-op/raw-ref-temp-deref.rs b/tests/ui/raw-ref-op/raw-ref-temp-deref.rs
new file mode 100644
index 000000000..2e075a1b9
--- /dev/null
+++ b/tests/ui/raw-ref-op/raw-ref-temp-deref.rs
@@ -0,0 +1,24 @@
+// check-pass
+// Check that taking the address of a place that contains a dereference is
+// allowed.
+#![feature(raw_ref_op, type_ascription)]
+
+const PAIR_REF: &(i32, i64) = &(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;
+ let field_deref_ref = &raw const PAIR_REF.0;
+ let deref_ref = &raw const *ARRAY_REF;
+ let index_deref_ref = &raw const ARRAY_REF[0];
+ let deref_ref = &raw const *SLICE_REF;
+ let index_deref_ref = &raw const SLICE_REF[1];
+
+ let x = 0;
+ let ascribe_ref = &raw const type_ascribe!(x, i32);
+ let ascribe_deref = &raw const type_ascribe!(*ARRAY_REF, [i32; 2]);
+ let ascribe_index_deref = &raw const type_ascribe!(ARRAY_REF[0], i32);
+}
diff --git a/tests/ui/raw-ref-op/raw-ref-temp.rs b/tests/ui/raw-ref-op/raw-ref-temp.rs
new file mode 100644
index 000000000..10e47cb34
--- /dev/null
+++ b/tests/ui/raw-ref-op/raw-ref-temp.rs
@@ -0,0 +1,31 @@
+// Ensure that we don't allow taking the address of temporary values
+#![feature(raw_ref_op, type_ascription)]
+
+const FOUR: u64 = 4;
+
+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 FOUR; //~ ERROR cannot take address
+ let mut_ref_const = &raw mut FOUR; //~ 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 type_ascribe!(2, i32); //~ ERROR cannot take address
+ let mut_ref_ascribe = &raw mut type_ascribe!(3, i32); //~ ERROR cannot take address
+
+ let ascribe_field_ref = &raw const type_ascribe!(PAIR.0, i32); //~ ERROR cannot take address
+ let ascribe_index_ref = &raw mut type_ascribe!(ARRAY[0], i32); //~ ERROR cannot take address
+}
diff --git a/tests/ui/raw-ref-op/raw-ref-temp.stderr b/tests/ui/raw-ref-op/raw-ref-temp.stderr
new file mode 100644
index 000000000..b96661625
--- /dev/null
+++ b/tests/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:11:31
+ |
+LL | let ref_expr = &raw const 2;
+ | ^ temporary value
+
+error[E0745]: cannot take address of a temporary
+ --> $DIR/raw-ref-temp.rs:12:33
+ |
+LL | let mut_ref_expr = &raw mut 3;
+ | ^ temporary value
+
+error[E0745]: cannot take address of a temporary
+ --> $DIR/raw-ref-temp.rs:13:32
+ |
+LL | let ref_const = &raw const FOUR;
+ | ^^^^ temporary value
+
+error[E0745]: cannot take address of a temporary
+ --> $DIR/raw-ref-temp.rs:14:34
+ |
+LL | let mut_ref_const = &raw mut FOUR;
+ | ^^^^ temporary value
+
+error[E0745]: cannot take address of a temporary
+ --> $DIR/raw-ref-temp.rs:16: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:17: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:18:32
+ |
+LL | let field_ref = &raw const PAIR.0;
+ | ^^^^^^ temporary value
+
+error[E0745]: cannot take address of a temporary
+ --> $DIR/raw-ref-temp.rs:19: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:21: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:22: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:23:32
+ |
+LL | let index_ref = &raw const ARRAY[0];
+ | ^^^^^^^^ temporary value
+
+error[E0745]: cannot take address of a temporary
+ --> $DIR/raw-ref-temp.rs:24: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:26:34
+ |
+LL | let ref_ascribe = &raw const type_ascribe!(2, i32);
+ | ^^^^^^^^^^^^^^^^^^^^^ temporary value
+
+error[E0745]: cannot take address of a temporary
+ --> $DIR/raw-ref-temp.rs:27:36
+ |
+LL | let mut_ref_ascribe = &raw mut type_ascribe!(3, i32);
+ | ^^^^^^^^^^^^^^^^^^^^^ temporary value
+
+error[E0745]: cannot take address of a temporary
+ --> $DIR/raw-ref-temp.rs:29:40
+ |
+LL | let ascribe_field_ref = &raw const type_ascribe!(PAIR.0, i32);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ temporary value
+
+error[E0745]: cannot take address of a temporary
+ --> $DIR/raw-ref-temp.rs:30:38
+ |
+LL | let ascribe_index_ref = &raw mut type_ascribe!(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/tests/ui/raw-ref-op/unusual_locations.rs b/tests/ui/raw-ref-op/unusual_locations.rs
new file mode 100644
index 000000000..6bf37408a
--- /dev/null
+++ b/tests/ui/raw-ref-op/unusual_locations.rs
@@ -0,0 +1,22 @@
+// check-pass
+
+#![feature(raw_ref_op)]
+
+const USES_PTR: () = { let u = (); &raw const u; };
+static ALSO_USES_PTR: () = { let u = (); &raw const u; };
+
+fn main() {
+ 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; }
+}