about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-08-03 23:07:07 +0000
committerbors <bors@rust-lang.org>2021-08-03 23:07:07 +0000
commit2b8de6f21286d6dbd7dd692af7da7dc6937861d3 (patch)
tree7d2884267ffc5c435502cd9290bae1c3e5b55b78 /src/test
parenta6ece56152d8eb11e049e9fcce147b2859e12c92 (diff)
parent7c5588edf5e6b709f6ba6959bc50ffbc89468d3b (diff)
downloadrust-2b8de6f21286d6dbd7dd692af7da7dc6937861d3.tar.gz
rust-2b8de6f21286d6dbd7dd692af7da7dc6937861d3.zip
Auto merge of #87746 - JohnTitor:rollup-zaapqgl, r=JohnTitor
Rollup of 8 pull requests

Successful merges:

 - #81797 (Add `core::stream::from_iter`)
 - #87267 (Remove space after negative sign in Literal to_string)
 - #87663 (Rustdoc accessibility: use an icon for the [-]/[+] controls)
 - #87720 (don't use .into() to convert types to identical types (clippy::useless_conversion))
 - #87723 (Use .contains instead of manual reimplementation.)
 - #87729 (Remove the aarch64 `crypto` target_feature)
 - #87731 (Update cargo)
 - #87734 (Test dropping union fields more)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/proc-macro/auxiliary/api/parse.rs6
-rw-r--r--src/test/ui/union/union-drop.rs3
-rw-r--r--src/test/ui/union/union-drop.thirunsafeck.stderr22
-rw-r--r--src/test/ui/unsafe/union-assignop.mirunsafeck.stderr59
-rw-r--r--src/test/ui/unsafe/union-assignop.rs30
-rw-r--r--src/test/ui/unsafe/union-assignop.thirunsafeck.stderr59
6 files changed, 154 insertions, 25 deletions
diff --git a/src/test/ui/proc-macro/auxiliary/api/parse.rs b/src/test/ui/proc-macro/auxiliary/api/parse.rs
index a304c5e81a4..93551ebaf82 100644
--- a/src/test/ui/proc-macro/auxiliary/api/parse.rs
+++ b/src/test/ui/proc-macro/auxiliary/api/parse.rs
@@ -6,8 +6,8 @@ pub fn test() {
 }
 
 fn test_display_literal() {
-    assert_eq!(Literal::isize_unsuffixed(-10).to_string(), "- 10");
-    assert_eq!(Literal::isize_suffixed(-10).to_string(), "- 10isize");
+    assert_eq!(Literal::isize_unsuffixed(-10).to_string(), "-10");
+    assert_eq!(Literal::isize_suffixed(-10).to_string(), "-10isize");
 }
 
 fn test_parse_literal() {
@@ -18,7 +18,7 @@ fn test_parse_literal() {
     assert_eq!("b\"\"".parse::<Literal>().unwrap().to_string(), "b\"\"");
     assert_eq!("r##\"\"##".parse::<Literal>().unwrap().to_string(), "r##\"\"##");
     assert_eq!("10ulong".parse::<Literal>().unwrap().to_string(), "10ulong");
-    assert_eq!("-10ulong".parse::<Literal>().unwrap().to_string(), "- 10ulong");
+    assert_eq!("-10ulong".parse::<Literal>().unwrap().to_string(), "-10ulong");
 
     assert!("true".parse::<Literal>().is_err());
     assert!(".8".parse::<Literal>().is_err());
diff --git a/src/test/ui/union/union-drop.rs b/src/test/ui/union/union-drop.rs
index 9edf5827511..c3d7d41ca35 100644
--- a/src/test/ui/union/union-drop.rs
+++ b/src/test/ui/union/union-drop.rs
@@ -1,4 +1,7 @@
 // run-pass
+// revisions: mirunsafeck thirunsafeck
+// [thirunsafeck]compile-flags: -Z thir-unsafeck
+
 #![allow(dead_code)]
 #![allow(unused_variables)]
 
diff --git a/src/test/ui/union/union-drop.thirunsafeck.stderr b/src/test/ui/union/union-drop.thirunsafeck.stderr
deleted file mode 100644
index 9766ae4e435..00000000000
--- a/src/test/ui/union/union-drop.thirunsafeck.stderr
+++ /dev/null
@@ -1,22 +0,0 @@
-warning: unnecessary `unsafe` block
-  --> $DIR/union-drop.rs:27:9
-   |
-LL |         unsafe { CHECK += 1; }
-   |         ^^^^^^ unnecessary `unsafe` block
-   |
-   = note: `#[warn(unused_unsafe)]` on by default
-
-warning: unnecessary `unsafe` block
-  --> $DIR/union-drop.rs:33:9
-   |
-LL |         unsafe { CHECK += 1; }
-   |         ^^^^^^ unnecessary `unsafe` block
-
-warning: unnecessary `unsafe` block
-  --> $DIR/union-drop.rs:40:5
-   |
-LL |     unsafe {
-   |     ^^^^^^ unnecessary `unsafe` block
-
-warning: 3 warnings emitted
-
diff --git a/src/test/ui/unsafe/union-assignop.mirunsafeck.stderr b/src/test/ui/unsafe/union-assignop.mirunsafeck.stderr
new file mode 100644
index 00000000000..cd338ac9e3a
--- /dev/null
+++ b/src/test/ui/unsafe/union-assignop.mirunsafeck.stderr
@@ -0,0 +1,59 @@
+error[E0133]: access to union field is unsafe and requires unsafe function or block
+  --> $DIR/union-assignop.rs:20:5
+   |
+LL |     foo.a += 5;
+   |     ^^^^^^^^^^ access to union field
+   |
+   = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior
+
+error[E0133]: access to union field is unsafe and requires unsafe function or block
+  --> $DIR/union-assignop.rs:21:5
+   |
+LL |     foo.b += Dropping;
+   |     ^^^^^ access to union field
+   |
+   = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior
+
+error[E0133]: assignment to union field that might need dropping is unsafe and requires unsafe function or block
+  --> $DIR/union-assignop.rs:22:5
+   |
+LL |     foo.b = Dropping;
+   |     ^^^^^^^^^^^^^^^^ assignment to union field that might need dropping
+   |
+   = note: the previous content of the field will be dropped, which causes undefined behavior if the field was not properly initialized
+
+error[E0133]: access to union field is unsafe and requires unsafe function or block
+  --> $DIR/union-assignop.rs:23:5
+   |
+LL |     foo.a;
+   |     ^^^^^ access to union field
+   |
+   = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior
+
+error[E0133]: access to union field is unsafe and requires unsafe function or block
+  --> $DIR/union-assignop.rs:25:5
+   |
+LL |     foo.b;
+   |     ^^^^^ access to union field
+   |
+   = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior
+
+error[E0133]: access to union field is unsafe and requires unsafe function or block
+  --> $DIR/union-assignop.rs:27:13
+   |
+LL |     foo.b = foo.b;
+   |             ^^^^^ access to union field
+   |
+   = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior
+
+error[E0133]: assignment to union field that might need dropping is unsafe and requires unsafe function or block
+  --> $DIR/union-assignop.rs:27:5
+   |
+LL |     foo.b = foo.b;
+   |     ^^^^^^^^^^^^^ assignment to union field that might need dropping
+   |
+   = note: the previous content of the field will be dropped, which causes undefined behavior if the field was not properly initialized
+
+error: aborting due to 7 previous errors
+
+For more information about this error, try `rustc --explain E0133`.
diff --git a/src/test/ui/unsafe/union-assignop.rs b/src/test/ui/unsafe/union-assignop.rs
new file mode 100644
index 00000000000..c4be20aa567
--- /dev/null
+++ b/src/test/ui/unsafe/union-assignop.rs
@@ -0,0 +1,30 @@
+// revisions: mirunsafeck thirunsafeck
+// [thirunsafeck]compile-flags: -Z thir-unsafeck
+
+#![feature(untagged_unions)]
+
+use std::ops::AddAssign;
+
+struct Dropping;
+impl AddAssign for Dropping {
+    fn add_assign(&mut self, _: Self) {}
+}
+
+union Foo {
+    a: u8, // non-dropping
+    b: Dropping, // treated as dropping
+}
+
+fn main() {
+    let mut foo = Foo { a: 42 };
+    foo.a += 5; //~ ERROR access to union field is unsafe
+    foo.b += Dropping; //~ ERROR access to union field is unsafe
+    foo.b = Dropping; //~ ERROR assignment to union field that might need dropping is unsafe
+    foo.a; //~ ERROR access to union field is unsafe
+    let foo = Foo { a: 42 };
+    foo.b; //~ ERROR access to union field is unsafe
+    let mut foo = Foo { a: 42 };
+    foo.b = foo.b;
+    //~^ ERROR access to union field is unsafe
+    //~| ERROR assignment to union field that might need dropping
+}
diff --git a/src/test/ui/unsafe/union-assignop.thirunsafeck.stderr b/src/test/ui/unsafe/union-assignop.thirunsafeck.stderr
new file mode 100644
index 00000000000..71de421a255
--- /dev/null
+++ b/src/test/ui/unsafe/union-assignop.thirunsafeck.stderr
@@ -0,0 +1,59 @@
+error[E0133]: access to union field is unsafe and requires unsafe function or block
+  --> $DIR/union-assignop.rs:20:5
+   |
+LL |     foo.a += 5;
+   |     ^^^^^ access to union field
+   |
+   = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior
+
+error[E0133]: access to union field is unsafe and requires unsafe function or block
+  --> $DIR/union-assignop.rs:21:5
+   |
+LL |     foo.b += Dropping;
+   |     ^^^^^ access to union field
+   |
+   = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior
+
+error[E0133]: assignment to union field that might need dropping is unsafe and requires unsafe function or block
+  --> $DIR/union-assignop.rs:22:5
+   |
+LL |     foo.b = Dropping;
+   |     ^^^^^^^^^^^^^^^^ assignment to union field that might need dropping
+   |
+   = note: the previous content of the field will be dropped, which causes undefined behavior if the field was not properly initialized
+
+error[E0133]: access to union field is unsafe and requires unsafe function or block
+  --> $DIR/union-assignop.rs:23:5
+   |
+LL |     foo.a;
+   |     ^^^^^ access to union field
+   |
+   = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior
+
+error[E0133]: access to union field is unsafe and requires unsafe function or block
+  --> $DIR/union-assignop.rs:25:5
+   |
+LL |     foo.b;
+   |     ^^^^^ access to union field
+   |
+   = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior
+
+error[E0133]: assignment to union field that might need dropping is unsafe and requires unsafe function or block
+  --> $DIR/union-assignop.rs:27:5
+   |
+LL |     foo.b = foo.b;
+   |     ^^^^^^^^^^^^^ assignment to union field that might need dropping
+   |
+   = note: the previous content of the field will be dropped, which causes undefined behavior if the field was not properly initialized
+
+error[E0133]: access to union field is unsafe and requires unsafe function or block
+  --> $DIR/union-assignop.rs:27:13
+   |
+LL |     foo.b = foo.b;
+   |             ^^^^^ access to union field
+   |
+   = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior
+
+error: aborting due to 7 previous errors
+
+For more information about this error, try `rustc --explain E0133`.