| author | bors <bors@rust-lang.org> 2026-03-27 09:03:50 UTC |
| committer | bors <bors@rust-lang.org> 2026-03-27 09:03:50 UTC |
| log | fda6d37bb88ee12fd50fa54d15859f1f91b74f55 |
| tree | 7ffcc610a269cbfcfc1b2639bad5043515b36a96 |
| parent | e3691a5bd58e92999bcbffedf640ecd61e02c29e |
| parent | a16a4c3f86d09c8333717e1b6efc0729048b05ad |
Rollup of 6 pull requests
Successful merges:
- rust-lang/rust#152457 (Pass -pg to linker when using -Zinstrument-mcount)
- rust-lang/rust#154031 (Remove divergence check from check_expr_array)
- rust-lang/rust#154418 (move many tests out of `ui/unsafe`)
- rust-lang/rust#154441 (bootstrap: force a CI LLVM stamp bump)
- rust-lang/rust#153675 (simd_add/sub/mul/neg: document overflow behavior)
- rust-lang/rust#154430 (Create GPU target notification group)85 files changed, 753 insertions(+), 699 deletions(-)
compiler/rustc_codegen_ssa/src/back/link.rs+4| ... | ... | @@ -2767,6 +2767,10 @@ fn add_order_independent_options( |
| 2767 | 2767 | cmd.pgo_gen(); |
| 2768 | 2768 | } |
| 2769 | 2769 | |
| 2770 | if sess.opts.unstable_opts.instrument_mcount { | |
| 2771 | cmd.enable_profiling(); | |
| 2772 | } | |
| 2773 | ||
| 2770 | 2774 | if sess.opts.cg.control_flow_guard != CFGuard::Disabled { |
| 2771 | 2775 | cmd.control_flow_guard(); |
| 2772 | 2776 | } |
compiler/rustc_codegen_ssa/src/back/linker.rs+14| ... | ... | @@ -352,6 +352,7 @@ pub(crate) trait Linker { |
| 352 | 352 | fn add_no_exec(&mut self) {} |
| 353 | 353 | fn add_as_needed(&mut self) {} |
| 354 | 354 | fn reset_per_library_state(&mut self) {} |
| 355 | fn enable_profiling(&mut self) {} | |
| 355 | 356 | } |
| 356 | 357 | |
| 357 | 358 | impl dyn Linker + '_ { |
| ... | ... | @@ -732,6 +733,19 @@ impl<'a> Linker for GccLinker<'a> { |
| 732 | 733 | self.link_or_cc_args(&["-u", "__llvm_profile_runtime"]); |
| 733 | 734 | } |
| 734 | 735 | |
| 736 | fn enable_profiling(&mut self) { | |
| 737 | // This flag is also used when linking to choose target specific | |
| 738 | // libraries needed to enable profiling. | |
| 739 | self.cc_arg("-pg"); | |
| 740 | // On windows-gnu targets, libgmon also needs to be linked, and this | |
| 741 | // requires readding libraries to satisfy its dependencies. | |
| 742 | if self.sess.target.is_like_windows { | |
| 743 | self.cc_arg("-lgmon"); | |
| 744 | self.cc_arg("-lkernel32"); | |
| 745 | self.cc_arg("-lmsvcrt"); | |
| 746 | } | |
| 747 | } | |
| 748 | ||
| 735 | 749 | fn control_flow_guard(&mut self) {} |
| 736 | 750 | |
| 737 | 751 | fn ehcont_guard(&mut self) {} |
compiler/rustc_hir_typeck/src/expr.rs-8| ... | ... | @@ -1660,14 +1660,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 1660 | 1660 | expr: &'tcx hir::Expr<'tcx>, |
| 1661 | 1661 | ) -> Ty<'tcx> { |
| 1662 | 1662 | let element_ty = if !args.is_empty() { |
| 1663 | // This shouldn't happen unless there's another error | |
| 1664 | // (e.g., never patterns in inappropriate contexts). | |
| 1665 | if self.diverges.get() != Diverges::Maybe { | |
| 1666 | self.dcx() | |
| 1667 | .struct_span_err(expr.span, "unexpected divergence state in checking array") | |
| 1668 | .delay_as_bug(); | |
| 1669 | } | |
| 1670 | ||
| 1671 | 1663 | let coerce_to = expected |
| 1672 | 1664 | .to_option(self) |
| 1673 | 1665 | .and_then(|uty| { |
compiler/rustc_target/src/spec/base/windows_gnu.rs+1| ... | ... | @@ -106,6 +106,7 @@ pub(crate) fn opts() -> TargetOptions { |
| 106 | 106 | // FIXME(davidtwco): Support Split DWARF on Windows GNU - may require LLVM changes to |
| 107 | 107 | // output DWO, despite using DWARF, doesn't use ELF.. |
| 108 | 108 | supported_split_debuginfo: Cow::Borrowed(&[SplitDebuginfo::Off]), |
| 109 | mcount: "_mcount".into(), | |
| 109 | 110 | ..Default::default() |
| 110 | 111 | } |
| 111 | 112 | } |
compiler/rustc_target/src/spec/base/windows_gnullvm.rs+1| ... | ... | @@ -53,6 +53,7 @@ pub(crate) fn opts() -> TargetOptions { |
| 53 | 53 | // FIXME(davidtwco): Support Split DWARF on Windows GNU - may require LLVM changes to |
| 54 | 54 | // output DWO, despite using DWARF, doesn't use ELF.. |
| 55 | 55 | supported_split_debuginfo: Cow::Borrowed(&[SplitDebuginfo::Off]), |
| 56 | mcount: "_mcount".into(), | |
| 56 | 57 | ..Default::default() |
| 57 | 58 | } |
| 58 | 59 | } |
library/core/src/intrinsics/simd.rs+4-2| ... | ... | @@ -62,6 +62,7 @@ pub const unsafe fn simd_splat<T, U>(value: U) -> T; |
| 62 | 62 | /// Adds two simd vectors elementwise. |
| 63 | 63 | /// |
| 64 | 64 | /// `T` must be a vector of integers or floats. |
| 65 | /// For integers, wrapping arithmetic is used. | |
| 65 | 66 | #[rustc_intrinsic] |
| 66 | 67 | #[rustc_nounwind] |
| 67 | 68 | pub const unsafe fn simd_add<T>(x: T, y: T) -> T; |
| ... | ... | @@ -69,6 +70,7 @@ pub const unsafe fn simd_add<T>(x: T, y: T) -> T; |
| 69 | 70 | /// Subtracts `rhs` from `lhs` elementwise. |
| 70 | 71 | /// |
| 71 | 72 | /// `T` must be a vector of integers or floats. |
| 73 | /// For integers, wrapping arithmetic is used. | |
| 72 | 74 | #[rustc_intrinsic] |
| 73 | 75 | #[rustc_nounwind] |
| 74 | 76 | pub const unsafe fn simd_sub<T>(lhs: T, rhs: T) -> T; |
| ... | ... | @@ -76,6 +78,7 @@ pub const unsafe fn simd_sub<T>(lhs: T, rhs: T) -> T; |
| 76 | 78 | /// Multiplies two simd vectors elementwise. |
| 77 | 79 | /// |
| 78 | 80 | /// `T` must be a vector of integers or floats. |
| 81 | /// For integers, wrapping arithmetic is used. | |
| 79 | 82 | #[rustc_intrinsic] |
| 80 | 83 | #[rustc_nounwind] |
| 81 | 84 | pub const unsafe fn simd_mul<T>(x: T, y: T) -> T; |
| ... | ... | @@ -233,8 +236,7 @@ pub const unsafe fn simd_as<T, U>(x: T) -> U; |
| 233 | 236 | /// Negates a vector elementwise. |
| 234 | 237 | /// |
| 235 | 238 | /// `T` must be a vector of integers or floats. |
| 236 | /// | |
| 237 | /// Rust panics for `-<int>::Min` due to overflow, but it is not UB with this intrinsic. | |
| 239 | /// For integers, wrapping arithmetic is used. | |
| 238 | 240 | #[rustc_intrinsic] |
| 239 | 241 | #[rustc_nounwind] |
| 240 | 242 | pub const unsafe fn simd_neg<T>(x: T) -> T; |
src/bootstrap/download-ci-llvm-stamp+1-1| ... | ... | @@ -1,4 +1,4 @@ |
| 1 | 1 | Change this file to make users of the `download-ci-llvm` configuration download |
| 2 | 2 | a new version of LLVM from CI, even if the LLVM submodule hasn’t changed. |
| 3 | 3 | |
| 4 | Last change is for: https://github.com/rust-lang/rust/pull/153179 | |
| 4 | Last change is for: https://github.com/rust-lang/rust/pull/151063 |
tests/run-make/instrument-mcount-link-pg/main.rs created+3| ... | ... | @@ -0,0 +1,3 @@ |
| 1 | fn main() { | |
| 2 | println!("Hello World!"); | |
| 3 | } |
tests/run-make/instrument-mcount-link-pg/rmake.rs created+19| ... | ... | @@ -0,0 +1,19 @@ |
| 1 | // When building a binary instrumented with mcount, verify the | |
| 2 | // binary is linked with the correct crt to enable profiling. | |
| 3 | // | |
| 4 | //@ only-gnu | |
| 5 | //@ ignore-cross-compile | |
| 6 | ||
| 7 | use run_make_support::{path, run, rustc}; | |
| 8 | ||
| 9 | fn main() { | |
| 10 | // Compile instrumentation enabled binary, and verify -pg is passed | |
| 11 | let link_args = | |
| 12 | rustc().input("main.rs").arg("-Zinstrument-mcount").print("link-args").run().stdout_utf8(); | |
| 13 | assert!(link_args.contains("\"-pg\"")); | |
| 14 | ||
| 15 | // Run it, and verify gmon.out is created | |
| 16 | assert!(!path("gmon.out").exists()); | |
| 17 | run("main"); | |
| 18 | assert!(path("gmon.out").exists()); | |
| 19 | } |
tests/ui/reachable/never-pattern-closure-param-array.rs created+13| ... | ... | @@ -0,0 +1,13 @@ |
| 1 | //@ check-pass | |
| 2 | //@ edition: 2024 | |
| 3 | ||
| 4 | #![feature(never_patterns)] | |
| 5 | #![allow(incomplete_features)] | |
| 6 | #![allow(unreachable_code)] | |
| 7 | ||
| 8 | fn main() { | |
| 9 | let _ = Some({ | |
| 10 | return; | |
| 11 | }) | |
| 12 | .map(|!| [1]); | |
| 13 | } |
tests/ui/union/access_union_field.rs created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | #![allow(unused_variables)] | |
| 2 | ||
| 3 | union Foo { | |
| 4 | bar: i8, | |
| 5 | baz: u8, | |
| 6 | } | |
| 7 | ||
| 8 | fn main() { | |
| 9 | let foo = Foo { bar: 5 }; | |
| 10 | let a = foo.bar; //~ ERROR access to union field is unsafe and requires unsafe function or block | |
| 11 | let b = foo.baz; //~ ERROR access to union field is unsafe and requires unsafe function or block | |
| 12 | } |
tests/ui/union/access_union_field.stderr created+19| ... | ... | @@ -0,0 +1,19 @@ |
| 1 | error[E0133]: access to union field is unsafe and requires unsafe function or block | |
| 2 | --> $DIR/access_union_field.rs:10:13 | |
| 3 | | | |
| 4 | LL | let a = foo.bar; | |
| 5 | | ^^^^^^^ access to union field | |
| 6 | | | |
| 7 | = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | |
| 8 | ||
| 9 | error[E0133]: access to union field is unsafe and requires unsafe function or block | |
| 10 | --> $DIR/access_union_field.rs:11:13 | |
| 11 | | | |
| 12 | LL | let b = foo.baz; | |
| 13 | | ^^^^^^^ access to union field | |
| 14 | | | |
| 15 | = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | |
| 16 | ||
| 17 | error: aborting due to 2 previous errors | |
| 18 | ||
| 19 | For more information about this error, try `rustc --explain E0133`. |
tests/ui/union/union-assignop.rs created+26| ... | ... | @@ -0,0 +1,26 @@ |
| 1 | use std::ops::AddAssign; | |
| 2 | use std::mem::ManuallyDrop; | |
| 3 | ||
| 4 | struct NonCopy; | |
| 5 | impl AddAssign for NonCopy { | |
| 6 | fn add_assign(&mut self, _: Self) {} | |
| 7 | } | |
| 8 | ||
| 9 | union Foo { | |
| 10 | a: u8, // non-dropping | |
| 11 | b: ManuallyDrop<NonCopy>, | |
| 12 | } | |
| 13 | ||
| 14 | fn main() { | |
| 15 | let mut foo = Foo { a: 42 }; | |
| 16 | foo.a += 5; //~ ERROR access to union field is unsafe | |
| 17 | *foo.b += NonCopy; //~ ERROR access to union field is unsafe | |
| 18 | *foo.b = NonCopy; //~ ERROR access to union field is unsafe | |
| 19 | foo.b = ManuallyDrop::new(NonCopy); | |
| 20 | foo.a; //~ ERROR access to union field is unsafe | |
| 21 | let foo = Foo { a: 42 }; | |
| 22 | foo.b; //~ ERROR access to union field is unsafe | |
| 23 | let mut foo = Foo { a: 42 }; | |
| 24 | foo.b = foo.b; | |
| 25 | //~^ ERROR access to union field is unsafe | |
| 26 | } |
tests/ui/union/union-assignop.stderr created+51| ... | ... | @@ -0,0 +1,51 @@ |
| 1 | error[E0133]: access to union field is unsafe and requires unsafe function or block | |
| 2 | --> $DIR/union-assignop.rs:16:5 | |
| 3 | | | |
| 4 | LL | foo.a += 5; | |
| 5 | | ^^^^^ access to union field | |
| 6 | | | |
| 7 | = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | |
| 8 | ||
| 9 | error[E0133]: access to union field is unsafe and requires unsafe function or block | |
| 10 | --> $DIR/union-assignop.rs:17:6 | |
| 11 | | | |
| 12 | LL | *foo.b += NonCopy; | |
| 13 | | ^^^^^ access to union field | |
| 14 | | | |
| 15 | = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | |
| 16 | ||
| 17 | error[E0133]: access to union field is unsafe and requires unsafe function or block | |
| 18 | --> $DIR/union-assignop.rs:18:6 | |
| 19 | | | |
| 20 | LL | *foo.b = NonCopy; | |
| 21 | | ^^^^^ access to union field | |
| 22 | | | |
| 23 | = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | |
| 24 | ||
| 25 | error[E0133]: access to union field is unsafe and requires unsafe function or block | |
| 26 | --> $DIR/union-assignop.rs:20:5 | |
| 27 | | | |
| 28 | LL | foo.a; | |
| 29 | | ^^^^^ access to union field | |
| 30 | | | |
| 31 | = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | |
| 32 | ||
| 33 | error[E0133]: access to union field is unsafe and requires unsafe function or block | |
| 34 | --> $DIR/union-assignop.rs:22:5 | |
| 35 | | | |
| 36 | LL | foo.b; | |
| 37 | | ^^^^^ access to union field | |
| 38 | | | |
| 39 | = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | |
| 40 | ||
| 41 | error[E0133]: access to union field is unsafe and requires unsafe function or block | |
| 42 | --> $DIR/union-assignop.rs:24:13 | |
| 43 | | | |
| 44 | LL | foo.b = foo.b; | |
| 45 | | ^^^^^ access to union field | |
| 46 | | | |
| 47 | = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | |
| 48 | ||
| 49 | error: aborting due to 6 previous errors | |
| 50 | ||
| 51 | For more information about this error, try `rustc --explain E0133`. |
tests/ui/union/union-modification.rs created+34| ... | ... | @@ -0,0 +1,34 @@ |
| 1 | //@ run-pass | |
| 2 | union Foo { | |
| 3 | bar: i8, | |
| 4 | _blah: isize, | |
| 5 | _zst: (), | |
| 6 | } | |
| 7 | ||
| 8 | struct FooHolder { | |
| 9 | inner_foo: Foo | |
| 10 | } | |
| 11 | ||
| 12 | fn do_nothing(_x: &mut Foo) {} | |
| 13 | ||
| 14 | pub fn main() { | |
| 15 | let mut foo = Foo { bar: 5 }; | |
| 16 | do_nothing(&mut foo); | |
| 17 | foo.bar = 6; | |
| 18 | unsafe { foo.bar += 1; } | |
| 19 | assert_eq!(unsafe { foo.bar }, 7); | |
| 20 | unsafe { | |
| 21 | let Foo { bar: inner } = foo; | |
| 22 | assert_eq!(inner, 7); | |
| 23 | } | |
| 24 | ||
| 25 | let foo = Foo { bar: 5 }; | |
| 26 | let foo = if let 3 = if let true = true { 3 } else { 4 } { foo } else { foo }; | |
| 27 | ||
| 28 | let (_foo2, _random) = (foo, 42); | |
| 29 | ||
| 30 | let mut foo_holder = FooHolder { inner_foo: Foo { bar: 5 } }; | |
| 31 | foo_holder.inner_foo.bar = 4; | |
| 32 | assert_eq!(unsafe { foo_holder.inner_foo.bar }, 4); | |
| 33 | drop(foo_holder); | |
| 34 | } |
tests/ui/union/union-pat-in-param.rs created+19| ... | ... | @@ -0,0 +1,19 @@ |
| 1 | union U { | |
| 2 | a: &'static i32, | |
| 3 | b: usize, | |
| 4 | } | |
| 5 | ||
| 6 | fn fun(U { a }: U) { | |
| 7 | //~^ ERROR access to union field is unsafe | |
| 8 | dbg!(*a); | |
| 9 | } | |
| 10 | ||
| 11 | fn main() { | |
| 12 | fun(U { b: 0 }); | |
| 13 | ||
| 14 | let closure = |U { a }| { | |
| 15 | //~^ ERROR access to union field is unsafe | |
| 16 | dbg!(*a); | |
| 17 | }; | |
| 18 | closure(U { b: 0 }); | |
| 19 | } |
tests/ui/union/union-pat-in-param.stderr created+19| ... | ... | @@ -0,0 +1,19 @@ |
| 1 | error[E0133]: access to union field is unsafe and requires unsafe function or block | |
| 2 | --> $DIR/union-pat-in-param.rs:6:12 | |
| 3 | | | |
| 4 | LL | fn fun(U { a }: U) { | |
| 5 | | ^ access to union field | |
| 6 | | | |
| 7 | = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | |
| 8 | ||
| 9 | error[E0133]: access to union field is unsafe and requires unsafe function or block | |
| 10 | --> $DIR/union-pat-in-param.rs:14:24 | |
| 11 | | | |
| 12 | LL | let closure = |U { a }| { | |
| 13 | | ^ access to union field | |
| 14 | | | |
| 15 | = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | |
| 16 | ||
| 17 | error: aborting due to 2 previous errors | |
| 18 | ||
| 19 | For more information about this error, try `rustc --explain E0133`. |
tests/ui/union/union.rs created+49| ... | ... | @@ -0,0 +1,49 @@ |
| 1 | union Foo { | |
| 2 | bar: i8, | |
| 3 | zst: (), | |
| 4 | pizza: Pizza, | |
| 5 | } | |
| 6 | ||
| 7 | #[derive(Clone, Copy)] | |
| 8 | struct Pizza { | |
| 9 | topping: Option<PizzaTopping> | |
| 10 | } | |
| 11 | ||
| 12 | #[allow(dead_code)] | |
| 13 | #[derive(Clone, Copy)] | |
| 14 | enum PizzaTopping { | |
| 15 | Cheese, | |
| 16 | Pineapple, | |
| 17 | } | |
| 18 | ||
| 19 | fn do_nothing(_x: &mut Foo) {} | |
| 20 | ||
| 21 | pub fn main() { | |
| 22 | let mut foo = Foo { bar: 5 }; | |
| 23 | do_nothing(&mut foo); | |
| 24 | ||
| 25 | // This is UB, so this test isn't run | |
| 26 | match foo { | |
| 27 | Foo { bar: _a } => {}, //~ ERROR access to union field is unsafe | |
| 28 | } | |
| 29 | match foo { | |
| 30 | Foo { | |
| 31 | pizza: Pizza { //~ ERROR access to union field is unsafe | |
| 32 | topping: Some(PizzaTopping::Cheese) | Some(PizzaTopping::Pineapple) | None | |
| 33 | } | |
| 34 | } => {}, | |
| 35 | } | |
| 36 | ||
| 37 | match foo { | |
| 38 | Foo { zst: () } => {} //~ ERROR access to union field is unsafe | |
| 39 | } | |
| 40 | match foo { | |
| 41 | Foo { pizza: Pizza { .. } } => {} //~ ERROR access to union field is unsafe | |
| 42 | } | |
| 43 | ||
| 44 | // binding to wildcard is okay | |
| 45 | match foo { | |
| 46 | Foo { bar: _ } => {}, | |
| 47 | } | |
| 48 | let Foo { bar: _ } = foo; | |
| 49 | } |
tests/ui/union/union.stderr created+38| ... | ... | @@ -0,0 +1,38 @@ |
| 1 | error[E0133]: access to union field is unsafe and requires unsafe function or block | |
| 2 | --> $DIR/union.rs:27:20 | |
| 3 | | | |
| 4 | LL | Foo { bar: _a } => {}, | |
| 5 | | ^^ access to union field | |
| 6 | | | |
| 7 | = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | |
| 8 | ||
| 9 | error[E0133]: access to union field is unsafe and requires unsafe function or block | |
| 10 | --> $DIR/union.rs:31:20 | |
| 11 | | | |
| 12 | LL | pizza: Pizza { | |
| 13 | | ____________________^ | |
| 14 | LL | | topping: Some(PizzaTopping::Cheese) | Some(PizzaTopping::Pineapple) | None | |
| 15 | LL | | } | |
| 16 | | |_____________^ access to union field | |
| 17 | | | |
| 18 | = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | |
| 19 | ||
| 20 | error[E0133]: access to union field is unsafe and requires unsafe function or block | |
| 21 | --> $DIR/union.rs:38:20 | |
| 22 | | | |
| 23 | LL | Foo { zst: () } => {} | |
| 24 | | ^^ access to union field | |
| 25 | | | |
| 26 | = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | |
| 27 | ||
| 28 | error[E0133]: access to union field is unsafe and requires unsafe function or block | |
| 29 | --> $DIR/union.rs:41:22 | |
| 30 | | | |
| 31 | LL | Foo { pizza: Pizza { .. } } => {} | |
| 32 | | ^^^^^^^^^^^^ access to union field | |
| 33 | | | |
| 34 | = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | |
| 35 | ||
| 36 | error: aborting due to 4 previous errors | |
| 37 | ||
| 38 | For more information about this error, try `rustc --explain E0133`. |
tests/ui/union/union_access_through_block.rs created+15| ... | ... | @@ -0,0 +1,15 @@ |
| 1 | //@ check-pass | |
| 2 | #[derive(Copy, Clone)] | |
| 3 | pub struct Foo { a: bool } | |
| 4 | ||
| 5 | pub union Bar { | |
| 6 | a: Foo, | |
| 7 | b: u32, | |
| 8 | } | |
| 9 | pub fn baz(mut bar: Bar) { | |
| 10 | unsafe { | |
| 11 | { bar.a }.a = true; | |
| 12 | } | |
| 13 | } | |
| 14 | ||
| 15 | fn main() {} |
tests/ui/union/union_destructure.rs created+50| ... | ... | @@ -0,0 +1,50 @@ |
| 1 | //@ run-pass | |
| 2 | #![allow(unreachable_patterns)] | |
| 3 | ||
| 4 | #[derive(Copy, Clone)] | |
| 5 | #[allow(dead_code)] | |
| 6 | struct Pie { | |
| 7 | slices: u8, | |
| 8 | size: u8, | |
| 9 | } | |
| 10 | ||
| 11 | union Foo { | |
| 12 | #[allow(dead_code)] | |
| 13 | bar: i8, | |
| 14 | baz: Pie, | |
| 15 | } | |
| 16 | ||
| 17 | fn main() { | |
| 18 | let u = Foo { bar: 5 }; | |
| 19 | let (Some(Foo { bar: _ }) | None) = Some(u); | |
| 20 | let u = Foo { bar: 6 }; | |
| 21 | let (Some(Foo { bar: _ }) | Some(Foo { bar: _ }) | None) = Some(u); | |
| 22 | unsafe { | |
| 23 | let u = Foo { bar: 7 }; | |
| 24 | let (Foo { bar } | Foo { bar }) = u; | |
| 25 | assert_eq!(bar, 7) | |
| 26 | } | |
| 27 | let u = Foo { bar: 8 }; | |
| 28 | match Some(u) { | |
| 29 | Some(Foo { bar: _ }) => 3, | |
| 30 | None => 4, | |
| 31 | }; | |
| 32 | ||
| 33 | let u = Foo { bar: 9 }; | |
| 34 | unsafe { | |
| 35 | match u { | |
| 36 | Foo { baz: Pie { .. } } => {} | |
| 37 | }; | |
| 38 | } | |
| 39 | let u = Foo { bar: 10 }; | |
| 40 | unsafe { | |
| 41 | match u { | |
| 42 | Foo { baz: Pie { slices: _, size: _ } } => {} | |
| 43 | }; | |
| 44 | } | |
| 45 | ||
| 46 | let u = Foo { bar: 11 }; | |
| 47 | match u { | |
| 48 | Foo { baz: _ } => {} | |
| 49 | }; | |
| 50 | } |
tests/ui/union/union_wild_or_wild.rs created+9| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | //@ check-pass | |
| 2 | union X { a: i8 } | |
| 3 | ||
| 4 | fn main() { | |
| 5 | let x = X { a: 5 }; | |
| 6 | match x { | |
| 7 | X { a: _ | _ } => {}, | |
| 8 | } | |
| 9 | } |
tests/ui/unsafe-binders/move-out-of-non-copy.rs created+15| ... | ... | @@ -0,0 +1,15 @@ |
| 1 | //@ compile-flags: -Zvalidate-mir | |
| 2 | ||
| 3 | // Regression test for <https://github.com/rust-lang/rust/issues/141394>. | |
| 4 | ||
| 5 | #![feature(unsafe_binders)] | |
| 6 | #![allow(incomplete_features)] | |
| 7 | ||
| 8 | use std::unsafe_binder::unwrap_binder; | |
| 9 | ||
| 10 | fn id<T>(x: unsafe<> T) -> T { | |
| 11 | //~^ ERROR the trait bound `T: Copy` is not satisfied | |
| 12 | unsafe { unwrap_binder!(x) } | |
| 13 | } | |
| 14 | ||
| 15 | fn main() {} |
tests/ui/unsafe-binders/move-out-of-non-copy.stderr created+14| ... | ... | @@ -0,0 +1,14 @@ |
| 1 | error[E0277]: the trait bound `T: Copy` is not satisfied | |
| 2 | --> $DIR/move-out-of-non-copy.rs:10:13 | |
| 3 | | | |
| 4 | LL | fn id<T>(x: unsafe<> T) -> T { | |
| 5 | | ^^^^^^^^^^ the trait `Copy` is not implemented for `T` | |
| 6 | | | |
| 7 | help: consider restricting type parameter `T` with trait `Copy` | |
| 8 | | | |
| 9 | LL | fn id<T: std::marker::Copy>(x: unsafe<> T) -> T { | |
| 10 | | +++++++++++++++++++ | |
| 11 | ||
| 12 | error: aborting due to 1 previous error | |
| 13 | ||
| 14 | For more information about this error, try `rustc --explain E0277`. |
tests/ui/unsafe/access_union_field.rs deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | #![allow(unused_variables)] | |
| 2 | ||
| 3 | union Foo { | |
| 4 | bar: i8, | |
| 5 | baz: u8, | |
| 6 | } | |
| 7 | ||
| 8 | fn main() { | |
| 9 | let foo = Foo { bar: 5 }; | |
| 10 | let a = foo.bar; //~ ERROR access to union field is unsafe and requires unsafe function or block | |
| 11 | let b = foo.baz; //~ ERROR access to union field is unsafe and requires unsafe function or block | |
| 12 | } |
tests/ui/unsafe/access_union_field.stderr deleted-19| ... | ... | @@ -1,19 +0,0 @@ |
| 1 | error[E0133]: access to union field is unsafe and requires unsafe function or block | |
| 2 | --> $DIR/access_union_field.rs:10:13 | |
| 3 | | | |
| 4 | LL | let a = foo.bar; | |
| 5 | | ^^^^^^^ access to union field | |
| 6 | | | |
| 7 | = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | |
| 8 | ||
| 9 | error[E0133]: access to union field is unsafe and requires unsafe function or block | |
| 10 | --> $DIR/access_union_field.rs:11:13 | |
| 11 | | | |
| 12 | LL | let b = foo.baz; | |
| 13 | | ^^^^^^^ access to union field | |
| 14 | | | |
| 15 | = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | |
| 16 | ||
| 17 | error: aborting due to 2 previous errors | |
| 18 | ||
| 19 | For more information about this error, try `rustc --explain E0133`. |
tests/ui/unsafe/initializing-ranged-via-ctor.rs deleted-11| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | #![feature(rustc_attrs)] | |
| 2 | #![allow(internal_features)] | |
| 3 | ||
| 4 | #[derive(Debug)] | |
| 5 | #[rustc_layout_scalar_valid_range_start(2)] | |
| 6 | struct NonZeroAndOneU8(u8); | |
| 7 | ||
| 8 | fn main() { | |
| 9 | println!("{:?}", Some(1).map(NonZeroAndOneU8).unwrap()); | |
| 10 | //~^ ERROR found `unsafe fn(u8) -> NonZeroAndOneU8 {NonZeroAndOneU8}` | |
| 11 | } |
tests/ui/unsafe/initializing-ranged-via-ctor.stderr deleted-16| ... | ... | @@ -1,16 +0,0 @@ |
| 1 | error[E0277]: expected a `FnOnce({integer})` closure, found `unsafe fn(u8) -> NonZeroAndOneU8 {NonZeroAndOneU8}` | |
| 2 | --> $DIR/initializing-ranged-via-ctor.rs:9:34 | |
| 3 | | | |
| 4 | LL | println!("{:?}", Some(1).map(NonZeroAndOneU8).unwrap()); | |
| 5 | | --- ^^^^^^^^^^^^^^^ call the function in a closure: `|| unsafe { /* code */ }` | |
| 6 | | | | |
| 7 | | required by a bound introduced by this call | |
| 8 | | | |
| 9 | = help: the trait `FnOnce({integer})` is not implemented for fn item `unsafe fn(u8) -> NonZeroAndOneU8 {NonZeroAndOneU8}` | |
| 10 | = note: unsafe function cannot be called generically without an unsafe block | |
| 11 | note: required by a bound in `Option::<T>::map` | |
| 12 | --> $SRC_DIR/core/src/option.rs:LL:COL | |
| 13 | ||
| 14 | error: aborting due to 1 previous error | |
| 15 | ||
| 16 | For more information about this error, try `rustc --explain E0277`. |
tests/ui/unsafe/move-out-of-non-copy.rs deleted-15| ... | ... | @@ -1,15 +0,0 @@ |
| 1 | //@ compile-flags: -Zvalidate-mir | |
| 2 | ||
| 3 | // Regression test for <https://github.com/rust-lang/rust/issues/141394>. | |
| 4 | ||
| 5 | #![feature(unsafe_binders)] | |
| 6 | #![allow(incomplete_features)] | |
| 7 | ||
| 8 | use std::unsafe_binder::unwrap_binder; | |
| 9 | ||
| 10 | fn id<T>(x: unsafe<> T) -> T { | |
| 11 | //~^ ERROR the trait bound `T: Copy` is not satisfied | |
| 12 | unsafe { unwrap_binder!(x) } | |
| 13 | } | |
| 14 | ||
| 15 | fn main() {} |
tests/ui/unsafe/move-out-of-non-copy.stderr deleted-14| ... | ... | @@ -1,14 +0,0 @@ |
| 1 | error[E0277]: the trait bound `T: Copy` is not satisfied | |
| 2 | --> $DIR/move-out-of-non-copy.rs:10:13 | |
| 3 | | | |
| 4 | LL | fn id<T>(x: unsafe<> T) -> T { | |
| 5 | | ^^^^^^^^^^ the trait `Copy` is not implemented for `T` | |
| 6 | | | |
| 7 | help: consider restricting type parameter `T` with trait `Copy` | |
| 8 | | | |
| 9 | LL | fn id<T: std::marker::Copy>(x: unsafe<> T) -> T { | |
| 10 | | +++++++++++++++++++ | |
| 11 | ||
| 12 | error: aborting due to 1 previous error | |
| 13 | ||
| 14 | For more information about this error, try `rustc --explain E0277`. |
tests/ui/unsafe/ranged-ctor-as-fn-ptr.rs deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | #![feature(rustc_attrs)] | |
| 2 | ||
| 3 | #[derive(Debug)] | |
| 4 | #[rustc_layout_scalar_valid_range_start(2)] | |
| 5 | struct NonZeroAndOneU8(u8); | |
| 6 | ||
| 7 | fn main() { | |
| 8 | let x: fn(u8) -> NonZeroAndOneU8 = NonZeroAndOneU8; | |
| 9 | //~^ ERROR mismatched types | |
| 10 | } |
tests/ui/unsafe/ranged-ctor-as-fn-ptr.stderr deleted-15| ... | ... | @@ -1,15 +0,0 @@ |
| 1 | error[E0308]: mismatched types | |
| 2 | --> $DIR/ranged-ctor-as-fn-ptr.rs:8:40 | |
| 3 | | | |
| 4 | LL | let x: fn(u8) -> NonZeroAndOneU8 = NonZeroAndOneU8; | |
| 5 | | ------------------------- ^^^^^^^^^^^^^^^ expected safe fn, found unsafe fn | |
| 6 | | | | |
| 7 | | expected due to this | |
| 8 | | | |
| 9 | = note: expected fn pointer `fn(_) -> NonZeroAndOneU8` | |
| 10 | found struct constructor `unsafe fn(_) -> NonZeroAndOneU8 {NonZeroAndOneU8}` | |
| 11 | = note: unsafe functions cannot be coerced into safe function pointers | |
| 12 | ||
| 13 | error: aborting due to 1 previous error | |
| 14 | ||
| 15 | For more information about this error, try `rustc --explain E0308`. |
tests/ui/unsafe/ranged_ints.rs deleted-8| ... | ... | @@ -1,8 +0,0 @@ |
| 1 | #![feature(rustc_attrs)] | |
| 2 | ||
| 3 | #[rustc_layout_scalar_valid_range_start(1)] | |
| 4 | #[repr(transparent)] | |
| 5 | pub(crate) struct NonZero<T>(pub(crate) T); | |
| 6 | fn main() { | |
| 7 | let _x = NonZero(0); //~ ERROR initializing type with `rustc_layout_scalar_valid_range` attr | |
| 8 | } |
tests/ui/unsafe/ranged_ints.stderr deleted-11| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | error[E0133]: initializing type with `rustc_layout_scalar_valid_range` attr is unsafe and requires unsafe function or block | |
| 2 | --> $DIR/ranged_ints.rs:7:14 | |
| 3 | | | |
| 4 | LL | let _x = NonZero(0); | |
| 5 | | ^^^^^^^^^^ initializing type with `rustc_layout_scalar_valid_range` attr | |
| 6 | | | |
| 7 | = note: initializing a layout restricted type's field with a value outside the valid range is undefined behavior | |
| 8 | ||
| 9 | error: aborting due to 1 previous error | |
| 10 | ||
| 11 | For more information about this error, try `rustc --explain E0133`. |
tests/ui/unsafe/ranged_ints2.rs deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | #![feature(rustc_attrs)] | |
| 2 | ||
| 3 | #[rustc_layout_scalar_valid_range_start(1)] | |
| 4 | #[repr(transparent)] | |
| 5 | pub(crate) struct NonZero<T>(pub(crate) T); | |
| 6 | fn main() { | |
| 7 | let mut x = unsafe { NonZero(1) }; | |
| 8 | let y = &mut x.0; //~ ERROR mutation of layout constrained field is unsafe | |
| 9 | if let Some(NonZero(ref mut y)) = Some(x) {} //~ ERROR mutation of layout constrained field is unsafe | |
| 10 | } |
tests/ui/unsafe/ranged_ints2.stderr deleted-19| ... | ... | @@ -1,19 +0,0 @@ |
| 1 | error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block | |
| 2 | --> $DIR/ranged_ints2.rs:8:13 | |
| 3 | | | |
| 4 | LL | let y = &mut x.0; | |
| 5 | | ^^^^^^^^ mutation of layout constrained field | |
| 6 | | | |
| 7 | = note: mutating layout constrained fields cannot statically be checked for valid values | |
| 8 | ||
| 9 | error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block | |
| 10 | --> $DIR/ranged_ints2.rs:9:25 | |
| 11 | | | |
| 12 | LL | if let Some(NonZero(ref mut y)) = Some(x) {} | |
| 13 | | ^^^^^^^^^ mutation of layout constrained field | |
| 14 | | | |
| 15 | = note: mutating layout constrained fields cannot statically be checked for valid values | |
| 16 | ||
| 17 | error: aborting due to 2 previous errors | |
| 18 | ||
| 19 | For more information about this error, try `rustc --explain E0133`. |
tests/ui/unsafe/ranged_ints2_const.rs deleted-26| ... | ... | @@ -1,26 +0,0 @@ |
| 1 | #![feature(rustc_attrs)] | |
| 2 | ||
| 3 | #[rustc_layout_scalar_valid_range_start(1)] | |
| 4 | #[repr(transparent)] | |
| 5 | pub(crate) struct NonZero<T>(pub(crate) T); | |
| 6 | fn main() { | |
| 7 | } | |
| 8 | ||
| 9 | const fn foo() -> NonZero<u32> { | |
| 10 | let mut x = unsafe { NonZero(1) }; | |
| 11 | let y = &mut x.0; | |
| 12 | //~^ ERROR mutation of layout constrained field is unsafe | |
| 13 | unsafe { NonZero(1) } | |
| 14 | } | |
| 15 | ||
| 16 | const fn bar() -> NonZero<u32> { | |
| 17 | let mut x = unsafe { NonZero(1) }; | |
| 18 | let y = unsafe { &mut x.0 }; | |
| 19 | unsafe { NonZero(1) } | |
| 20 | } | |
| 21 | ||
| 22 | const fn boo() -> NonZero<u32> { | |
| 23 | let mut x = unsafe { NonZero(1) }; | |
| 24 | unsafe { let y = &mut x.0; } | |
| 25 | unsafe { NonZero(1) } | |
| 26 | } |
tests/ui/unsafe/ranged_ints2_const.stderr deleted-11| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block | |
| 2 | --> $DIR/ranged_ints2_const.rs:11:13 | |
| 3 | | | |
| 4 | LL | let y = &mut x.0; | |
| 5 | | ^^^^^^^^ mutation of layout constrained field | |
| 6 | | | |
| 7 | = note: mutating layout constrained fields cannot statically be checked for valid values | |
| 8 | ||
| 9 | error: aborting due to 1 previous error | |
| 10 | ||
| 11 | For more information about this error, try `rustc --explain E0133`. |
tests/ui/unsafe/ranged_ints3.rs deleted-11| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | #![feature(rustc_attrs)] | |
| 2 | ||
| 3 | use std::cell::Cell; | |
| 4 | ||
| 5 | #[rustc_layout_scalar_valid_range_start(1)] | |
| 6 | #[repr(transparent)] | |
| 7 | pub(crate) struct NonZero<T>(pub(crate) T); | |
| 8 | fn main() { | |
| 9 | let mut x = unsafe { NonZero(Cell::new(1)) }; | |
| 10 | let y = &x.0; //~ ERROR borrow of layout constrained field with interior mutability | |
| 11 | } |
tests/ui/unsafe/ranged_ints3.stderr deleted-11| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | error[E0133]: borrow of layout constrained field with interior mutability is unsafe and requires unsafe function or block | |
| 2 | --> $DIR/ranged_ints3.rs:10:13 | |
| 3 | | | |
| 4 | LL | let y = &x.0; | |
| 5 | | ^^^^ borrow of layout constrained field with interior mutability | |
| 6 | | | |
| 7 | = note: references to fields of layout constrained fields lose the constraints. Coupled with interior mutability, the field can be changed to invalid values | |
| 8 | ||
| 9 | error: aborting due to 1 previous error | |
| 10 | ||
| 11 | For more information about this error, try `rustc --explain E0133`. |
tests/ui/unsafe/ranged_ints3_const.rs deleted-21| ... | ... | @@ -1,21 +0,0 @@ |
| 1 | #![feature(rustc_attrs)] | |
| 2 | ||
| 3 | use std::cell::Cell; | |
| 4 | ||
| 5 | #[rustc_layout_scalar_valid_range_start(1)] | |
| 6 | #[repr(transparent)] | |
| 7 | pub(crate) struct NonZero<T>(pub(crate) T); | |
| 8 | fn main() {} | |
| 9 | ||
| 10 | const fn foo() -> NonZero<Cell<u32>> { | |
| 11 | let mut x = unsafe { NonZero(Cell::new(1)) }; | |
| 12 | let y = &x.0; | |
| 13 | //~^ ERROR borrow of layout constrained field with interior mutability | |
| 14 | unsafe { NonZero(Cell::new(1)) } | |
| 15 | } | |
| 16 | ||
| 17 | const fn bar() -> NonZero<Cell<u32>> { | |
| 18 | let mut x = unsafe { NonZero(Cell::new(1)) }; | |
| 19 | let y = unsafe { &x.0 }; | |
| 20 | unsafe { NonZero(Cell::new(1)) } | |
| 21 | } |
tests/ui/unsafe/ranged_ints3_const.stderr deleted-11| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | error[E0133]: borrow of layout constrained field with interior mutability is unsafe and requires unsafe function or block | |
| 2 | --> $DIR/ranged_ints3_const.rs:12:13 | |
| 3 | | | |
| 4 | LL | let y = &x.0; | |
| 5 | | ^^^^ borrow of layout constrained field with interior mutability | |
| 6 | | | |
| 7 | = note: references to fields of layout constrained fields lose the constraints. Coupled with interior mutability, the field can be changed to invalid values | |
| 8 | ||
| 9 | error: aborting due to 1 previous error | |
| 10 | ||
| 11 | For more information about this error, try `rustc --explain E0133`. |
tests/ui/unsafe/ranged_ints3_match.rs deleted-19| ... | ... | @@ -1,19 +0,0 @@ |
| 1 | #![feature(rustc_attrs)] | |
| 2 | ||
| 3 | use std::cell::Cell; | |
| 4 | ||
| 5 | #[rustc_layout_scalar_valid_range_start(1)] | |
| 6 | #[repr(transparent)] | |
| 7 | pub(crate) struct NonZero<T>(pub(crate) T); | |
| 8 | fn main() { | |
| 9 | let mut x = unsafe { NonZero(Cell::new(1)) }; | |
| 10 | match x { | |
| 11 | NonZero(ref x) => { x } | |
| 12 | //~^ ERROR borrow of layout constrained field with interior mutability | |
| 13 | }; | |
| 14 | ||
| 15 | let mut y = unsafe { NonZero(42) }; | |
| 16 | match y { NonZero(ref y) => { y } }; // OK, type of `y` is freeze | |
| 17 | match y { NonZero(ref mut y) => { y } }; | |
| 18 | //~^ ERROR mutation of layout constrained field | |
| 19 | } |
tests/ui/unsafe/ranged_ints3_match.stderr deleted-19| ... | ... | @@ -1,19 +0,0 @@ |
| 1 | error[E0133]: borrow of layout constrained field with interior mutability is unsafe and requires unsafe function or block | |
| 2 | --> $DIR/ranged_ints3_match.rs:11:17 | |
| 3 | | | |
| 4 | LL | NonZero(ref x) => { x } | |
| 5 | | ^^^^^ borrow of layout constrained field with interior mutability | |
| 6 | | | |
| 7 | = note: references to fields of layout constrained fields lose the constraints. Coupled with interior mutability, the field can be changed to invalid values | |
| 8 | ||
| 9 | error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block | |
| 10 | --> $DIR/ranged_ints3_match.rs:17:23 | |
| 11 | | | |
| 12 | LL | match y { NonZero(ref mut y) => { y } }; | |
| 13 | | ^^^^^^^^^ mutation of layout constrained field | |
| 14 | | | |
| 15 | = note: mutating layout constrained fields cannot statically be checked for valid values | |
| 16 | ||
| 17 | error: aborting due to 2 previous errors | |
| 18 | ||
| 19 | For more information about this error, try `rustc --explain E0133`. |
tests/ui/unsafe/ranged_ints4.rs deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | #![feature(rustc_attrs)] | |
| 2 | ||
| 3 | #[rustc_layout_scalar_valid_range_start(1)] | |
| 4 | #[repr(transparent)] | |
| 5 | pub(crate) struct NonZero<T>(pub(crate) T); | |
| 6 | fn main() { | |
| 7 | let mut x = unsafe { NonZero(1) }; | |
| 8 | x.0 = 0; //~ ERROR mutation of layout constrained field is unsafe | |
| 9 | } |
tests/ui/unsafe/ranged_ints4.stderr deleted-11| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block | |
| 2 | --> $DIR/ranged_ints4.rs:8:5 | |
| 3 | | | |
| 4 | LL | x.0 = 0; | |
| 5 | | ^^^^^^^ mutation of layout constrained field | |
| 6 | | | |
| 7 | = note: mutating layout constrained fields cannot statically be checked for valid values | |
| 8 | ||
| 9 | error: aborting due to 1 previous error | |
| 10 | ||
| 11 | For more information about this error, try `rustc --explain E0133`. |
tests/ui/unsafe/ranged_ints4_const.rs deleted-19| ... | ... | @@ -1,19 +0,0 @@ |
| 1 | #![feature(rustc_attrs)] | |
| 2 | ||
| 3 | #[rustc_layout_scalar_valid_range_start(1)] | |
| 4 | #[repr(transparent)] | |
| 5 | pub(crate) struct NonZero<T>(pub(crate) T); | |
| 6 | fn main() {} | |
| 7 | ||
| 8 | const fn foo() -> NonZero<u32> { | |
| 9 | let mut x = unsafe { NonZero(1) }; | |
| 10 | x.0 = 0; | |
| 11 | //~^ ERROR mutation of layout constrained field is unsafe | |
| 12 | x | |
| 13 | } | |
| 14 | ||
| 15 | const fn bar() -> NonZero<u32> { | |
| 16 | let mut x = unsafe { NonZero(1) }; | |
| 17 | unsafe { x.0 = 0 }; // this is UB | |
| 18 | x | |
| 19 | } |
tests/ui/unsafe/ranged_ints4_const.stderr deleted-11| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block | |
| 2 | --> $DIR/ranged_ints4_const.rs:10:5 | |
| 3 | | | |
| 4 | LL | x.0 = 0; | |
| 5 | | ^^^^^^^ mutation of layout constrained field | |
| 6 | | | |
| 7 | = note: mutating layout constrained fields cannot statically be checked for valid values | |
| 8 | ||
| 9 | error: aborting due to 1 previous error | |
| 10 | ||
| 11 | For more information about this error, try `rustc --explain E0133`. |
tests/ui/unsafe/ranged_ints_const.rs deleted-11| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | #![feature(rustc_attrs)] | |
| 2 | ||
| 3 | #[rustc_layout_scalar_valid_range_start(1)] | |
| 4 | #[repr(transparent)] | |
| 5 | pub(crate) struct NonZero<T>(pub(crate) T); | |
| 6 | fn main() {} | |
| 7 | ||
| 8 | const fn foo() -> NonZero<u32> { NonZero(0) } | |
| 9 | //~^ ERROR initializing type with `rustc_layout_scalar_valid_range` attr is unsafe | |
| 10 | ||
| 11 | const fn bar() -> NonZero<u32> { unsafe { NonZero(0) } } |
tests/ui/unsafe/ranged_ints_const.stderr deleted-11| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | error[E0133]: initializing type with `rustc_layout_scalar_valid_range` attr is unsafe and requires unsafe function or block | |
| 2 | --> $DIR/ranged_ints_const.rs:8:34 | |
| 3 | | | |
| 4 | LL | const fn foo() -> NonZero<u32> { NonZero(0) } | |
| 5 | | ^^^^^^^^^^ initializing type with `rustc_layout_scalar_valid_range` attr | |
| 6 | | | |
| 7 | = note: initializing a layout restricted type's field with a value outside the valid range is undefined behavior | |
| 8 | ||
| 9 | error: aborting due to 1 previous error | |
| 10 | ||
| 11 | For more information about this error, try `rustc --explain E0133`. |
tests/ui/unsafe/ranged_ints_macro.rs deleted-17| ... | ... | @@ -1,17 +0,0 @@ |
| 1 | //@ build-pass | |
| 2 | ||
| 3 | #![feature(rustc_attrs)] | |
| 4 | ||
| 5 | macro_rules! apply { | |
| 6 | ($val:expr) => { | |
| 7 | #[rustc_layout_scalar_valid_range_start($val)] | |
| 8 | #[repr(transparent)] | |
| 9 | pub(crate) struct NonZero<T>(pub(crate) T); | |
| 10 | } | |
| 11 | } | |
| 12 | ||
| 13 | apply!(1); | |
| 14 | ||
| 15 | fn main() { | |
| 16 | let _x = unsafe { NonZero(1) }; | |
| 17 | } |
tests/ui/unsafe/rustc_layout_scalar_valid_range/initializing-ranged-via-ctor.rs created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | #![feature(rustc_attrs)] | |
| 2 | #![allow(internal_features)] | |
| 3 | ||
| 4 | #[derive(Debug)] | |
| 5 | #[rustc_layout_scalar_valid_range_start(2)] | |
| 6 | struct NonZeroAndOneU8(u8); | |
| 7 | ||
| 8 | fn main() { | |
| 9 | println!("{:?}", Some(1).map(NonZeroAndOneU8).unwrap()); | |
| 10 | //~^ ERROR found `unsafe fn(u8) -> NonZeroAndOneU8 {NonZeroAndOneU8}` | |
| 11 | } |
tests/ui/unsafe/rustc_layout_scalar_valid_range/initializing-ranged-via-ctor.stderr created+16| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | error[E0277]: expected a `FnOnce({integer})` closure, found `unsafe fn(u8) -> NonZeroAndOneU8 {NonZeroAndOneU8}` | |
| 2 | --> $DIR/initializing-ranged-via-ctor.rs:9:34 | |
| 3 | | | |
| 4 | LL | println!("{:?}", Some(1).map(NonZeroAndOneU8).unwrap()); | |
| 5 | | --- ^^^^^^^^^^^^^^^ call the function in a closure: `|| unsafe { /* code */ }` | |
| 6 | | | | |
| 7 | | required by a bound introduced by this call | |
| 8 | | | |
| 9 | = help: the trait `FnOnce({integer})` is not implemented for fn item `unsafe fn(u8) -> NonZeroAndOneU8 {NonZeroAndOneU8}` | |
| 10 | = note: unsafe function cannot be called generically without an unsafe block | |
| 11 | note: required by a bound in `Option::<T>::map` | |
| 12 | --> $SRC_DIR/core/src/option.rs:LL:COL | |
| 13 | ||
| 14 | error: aborting due to 1 previous error | |
| 15 | ||
| 16 | For more information about this error, try `rustc --explain E0277`. |
tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged-ctor-as-fn-ptr.rs created+10| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | #![feature(rustc_attrs)] | |
| 2 | ||
| 3 | #[derive(Debug)] | |
| 4 | #[rustc_layout_scalar_valid_range_start(2)] | |
| 5 | struct NonZeroAndOneU8(u8); | |
| 6 | ||
| 7 | fn main() { | |
| 8 | let x: fn(u8) -> NonZeroAndOneU8 = NonZeroAndOneU8; | |
| 9 | //~^ ERROR mismatched types | |
| 10 | } |
tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged-ctor-as-fn-ptr.stderr created+15| ... | ... | @@ -0,0 +1,15 @@ |
| 1 | error[E0308]: mismatched types | |
| 2 | --> $DIR/ranged-ctor-as-fn-ptr.rs:8:40 | |
| 3 | | | |
| 4 | LL | let x: fn(u8) -> NonZeroAndOneU8 = NonZeroAndOneU8; | |
| 5 | | ------------------------- ^^^^^^^^^^^^^^^ expected safe fn, found unsafe fn | |
| 6 | | | | |
| 7 | | expected due to this | |
| 8 | | | |
| 9 | = note: expected fn pointer `fn(_) -> NonZeroAndOneU8` | |
| 10 | found struct constructor `unsafe fn(_) -> NonZeroAndOneU8 {NonZeroAndOneU8}` | |
| 11 | = note: unsafe functions cannot be coerced into safe function pointers | |
| 12 | ||
| 13 | error: aborting due to 1 previous error | |
| 14 | ||
| 15 | For more information about this error, try `rustc --explain E0308`. |
tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints.rs created+8| ... | ... | @@ -0,0 +1,8 @@ |
| 1 | #![feature(rustc_attrs)] | |
| 2 | ||
| 3 | #[rustc_layout_scalar_valid_range_start(1)] | |
| 4 | #[repr(transparent)] | |
| 5 | pub(crate) struct NonZero<T>(pub(crate) T); | |
| 6 | fn main() { | |
| 7 | let _x = NonZero(0); //~ ERROR initializing type with `rustc_layout_scalar_valid_range` attr | |
| 8 | } |
tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints.stderr created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | error[E0133]: initializing type with `rustc_layout_scalar_valid_range` attr is unsafe and requires unsafe function or block | |
| 2 | --> $DIR/ranged_ints.rs:7:14 | |
| 3 | | | |
| 4 | LL | let _x = NonZero(0); | |
| 5 | | ^^^^^^^^^^ initializing type with `rustc_layout_scalar_valid_range` attr | |
| 6 | | | |
| 7 | = note: initializing a layout restricted type's field with a value outside the valid range is undefined behavior | |
| 8 | ||
| 9 | error: aborting due to 1 previous error | |
| 10 | ||
| 11 | For more information about this error, try `rustc --explain E0133`. |
tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints2.rs created+10| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | #![feature(rustc_attrs)] | |
| 2 | ||
| 3 | #[rustc_layout_scalar_valid_range_start(1)] | |
| 4 | #[repr(transparent)] | |
| 5 | pub(crate) struct NonZero<T>(pub(crate) T); | |
| 6 | fn main() { | |
| 7 | let mut x = unsafe { NonZero(1) }; | |
| 8 | let y = &mut x.0; //~ ERROR mutation of layout constrained field is unsafe | |
| 9 | if let Some(NonZero(ref mut y)) = Some(x) {} //~ ERROR mutation of layout constrained field is unsafe | |
| 10 | } |
tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints2.stderr created+19| ... | ... | @@ -0,0 +1,19 @@ |
| 1 | error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block | |
| 2 | --> $DIR/ranged_ints2.rs:8:13 | |
| 3 | | | |
| 4 | LL | let y = &mut x.0; | |
| 5 | | ^^^^^^^^ mutation of layout constrained field | |
| 6 | | | |
| 7 | = note: mutating layout constrained fields cannot statically be checked for valid values | |
| 8 | ||
| 9 | error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block | |
| 10 | --> $DIR/ranged_ints2.rs:9:25 | |
| 11 | | | |
| 12 | LL | if let Some(NonZero(ref mut y)) = Some(x) {} | |
| 13 | | ^^^^^^^^^ mutation of layout constrained field | |
| 14 | | | |
| 15 | = note: mutating layout constrained fields cannot statically be checked for valid values | |
| 16 | ||
| 17 | error: aborting due to 2 previous errors | |
| 18 | ||
| 19 | For more information about this error, try `rustc --explain E0133`. |
tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints2_const.rs created+26| ... | ... | @@ -0,0 +1,26 @@ |
| 1 | #![feature(rustc_attrs)] | |
| 2 | ||
| 3 | #[rustc_layout_scalar_valid_range_start(1)] | |
| 4 | #[repr(transparent)] | |
| 5 | pub(crate) struct NonZero<T>(pub(crate) T); | |
| 6 | fn main() { | |
| 7 | } | |
| 8 | ||
| 9 | const fn foo() -> NonZero<u32> { | |
| 10 | let mut x = unsafe { NonZero(1) }; | |
| 11 | let y = &mut x.0; | |
| 12 | //~^ ERROR mutation of layout constrained field is unsafe | |
| 13 | unsafe { NonZero(1) } | |
| 14 | } | |
| 15 | ||
| 16 | const fn bar() -> NonZero<u32> { | |
| 17 | let mut x = unsafe { NonZero(1) }; | |
| 18 | let y = unsafe { &mut x.0 }; | |
| 19 | unsafe { NonZero(1) } | |
| 20 | } | |
| 21 | ||
| 22 | const fn boo() -> NonZero<u32> { | |
| 23 | let mut x = unsafe { NonZero(1) }; | |
| 24 | unsafe { let y = &mut x.0; } | |
| 25 | unsafe { NonZero(1) } | |
| 26 | } |
tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints2_const.stderr created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block | |
| 2 | --> $DIR/ranged_ints2_const.rs:11:13 | |
| 3 | | | |
| 4 | LL | let y = &mut x.0; | |
| 5 | | ^^^^^^^^ mutation of layout constrained field | |
| 6 | | | |
| 7 | = note: mutating layout constrained fields cannot statically be checked for valid values | |
| 8 | ||
| 9 | error: aborting due to 1 previous error | |
| 10 | ||
| 11 | For more information about this error, try `rustc --explain E0133`. |
tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3.rs created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | #![feature(rustc_attrs)] | |
| 2 | ||
| 3 | use std::cell::Cell; | |
| 4 | ||
| 5 | #[rustc_layout_scalar_valid_range_start(1)] | |
| 6 | #[repr(transparent)] | |
| 7 | pub(crate) struct NonZero<T>(pub(crate) T); | |
| 8 | fn main() { | |
| 9 | let mut x = unsafe { NonZero(Cell::new(1)) }; | |
| 10 | let y = &x.0; //~ ERROR borrow of layout constrained field with interior mutability | |
| 11 | } |
tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3.stderr created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | error[E0133]: borrow of layout constrained field with interior mutability is unsafe and requires unsafe function or block | |
| 2 | --> $DIR/ranged_ints3.rs:10:13 | |
| 3 | | | |
| 4 | LL | let y = &x.0; | |
| 5 | | ^^^^ borrow of layout constrained field with interior mutability | |
| 6 | | | |
| 7 | = note: references to fields of layout constrained fields lose the constraints. Coupled with interior mutability, the field can be changed to invalid values | |
| 8 | ||
| 9 | error: aborting due to 1 previous error | |
| 10 | ||
| 11 | For more information about this error, try `rustc --explain E0133`. |
tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3_const.rs created+21| ... | ... | @@ -0,0 +1,21 @@ |
| 1 | #![feature(rustc_attrs)] | |
| 2 | ||
| 3 | use std::cell::Cell; | |
| 4 | ||
| 5 | #[rustc_layout_scalar_valid_range_start(1)] | |
| 6 | #[repr(transparent)] | |
| 7 | pub(crate) struct NonZero<T>(pub(crate) T); | |
| 8 | fn main() {} | |
| 9 | ||
| 10 | const fn foo() -> NonZero<Cell<u32>> { | |
| 11 | let mut x = unsafe { NonZero(Cell::new(1)) }; | |
| 12 | let y = &x.0; | |
| 13 | //~^ ERROR borrow of layout constrained field with interior mutability | |
| 14 | unsafe { NonZero(Cell::new(1)) } | |
| 15 | } | |
| 16 | ||
| 17 | const fn bar() -> NonZero<Cell<u32>> { | |
| 18 | let mut x = unsafe { NonZero(Cell::new(1)) }; | |
| 19 | let y = unsafe { &x.0 }; | |
| 20 | unsafe { NonZero(Cell::new(1)) } | |
| 21 | } |
tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3_const.stderr created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | error[E0133]: borrow of layout constrained field with interior mutability is unsafe and requires unsafe function or block | |
| 2 | --> $DIR/ranged_ints3_const.rs:12:13 | |
| 3 | | | |
| 4 | LL | let y = &x.0; | |
| 5 | | ^^^^ borrow of layout constrained field with interior mutability | |
| 6 | | | |
| 7 | = note: references to fields of layout constrained fields lose the constraints. Coupled with interior mutability, the field can be changed to invalid values | |
| 8 | ||
| 9 | error: aborting due to 1 previous error | |
| 10 | ||
| 11 | For more information about this error, try `rustc --explain E0133`. |
tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3_match.rs created+19| ... | ... | @@ -0,0 +1,19 @@ |
| 1 | #![feature(rustc_attrs)] | |
| 2 | ||
| 3 | use std::cell::Cell; | |
| 4 | ||
| 5 | #[rustc_layout_scalar_valid_range_start(1)] | |
| 6 | #[repr(transparent)] | |
| 7 | pub(crate) struct NonZero<T>(pub(crate) T); | |
| 8 | fn main() { | |
| 9 | let mut x = unsafe { NonZero(Cell::new(1)) }; | |
| 10 | match x { | |
| 11 | NonZero(ref x) => { x } | |
| 12 | //~^ ERROR borrow of layout constrained field with interior mutability | |
| 13 | }; | |
| 14 | ||
| 15 | let mut y = unsafe { NonZero(42) }; | |
| 16 | match y { NonZero(ref y) => { y } }; // OK, type of `y` is freeze | |
| 17 | match y { NonZero(ref mut y) => { y } }; | |
| 18 | //~^ ERROR mutation of layout constrained field | |
| 19 | } |
tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3_match.stderr created+19| ... | ... | @@ -0,0 +1,19 @@ |
| 1 | error[E0133]: borrow of layout constrained field with interior mutability is unsafe and requires unsafe function or block | |
| 2 | --> $DIR/ranged_ints3_match.rs:11:17 | |
| 3 | | | |
| 4 | LL | NonZero(ref x) => { x } | |
| 5 | | ^^^^^ borrow of layout constrained field with interior mutability | |
| 6 | | | |
| 7 | = note: references to fields of layout constrained fields lose the constraints. Coupled with interior mutability, the field can be changed to invalid values | |
| 8 | ||
| 9 | error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block | |
| 10 | --> $DIR/ranged_ints3_match.rs:17:23 | |
| 11 | | | |
| 12 | LL | match y { NonZero(ref mut y) => { y } }; | |
| 13 | | ^^^^^^^^^ mutation of layout constrained field | |
| 14 | | | |
| 15 | = note: mutating layout constrained fields cannot statically be checked for valid values | |
| 16 | ||
| 17 | error: aborting due to 2 previous errors | |
| 18 | ||
| 19 | For more information about this error, try `rustc --explain E0133`. |
tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints4.rs created+9| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | #![feature(rustc_attrs)] | |
| 2 | ||
| 3 | #[rustc_layout_scalar_valid_range_start(1)] | |
| 4 | #[repr(transparent)] | |
| 5 | pub(crate) struct NonZero<T>(pub(crate) T); | |
| 6 | fn main() { | |
| 7 | let mut x = unsafe { NonZero(1) }; | |
| 8 | x.0 = 0; //~ ERROR mutation of layout constrained field is unsafe | |
| 9 | } |
tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints4.stderr created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block | |
| 2 | --> $DIR/ranged_ints4.rs:8:5 | |
| 3 | | | |
| 4 | LL | x.0 = 0; | |
| 5 | | ^^^^^^^ mutation of layout constrained field | |
| 6 | | | |
| 7 | = note: mutating layout constrained fields cannot statically be checked for valid values | |
| 8 | ||
| 9 | error: aborting due to 1 previous error | |
| 10 | ||
| 11 | For more information about this error, try `rustc --explain E0133`. |
tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints4_const.rs created+19| ... | ... | @@ -0,0 +1,19 @@ |
| 1 | #![feature(rustc_attrs)] | |
| 2 | ||
| 3 | #[rustc_layout_scalar_valid_range_start(1)] | |
| 4 | #[repr(transparent)] | |
| 5 | pub(crate) struct NonZero<T>(pub(crate) T); | |
| 6 | fn main() {} | |
| 7 | ||
| 8 | const fn foo() -> NonZero<u32> { | |
| 9 | let mut x = unsafe { NonZero(1) }; | |
| 10 | x.0 = 0; | |
| 11 | //~^ ERROR mutation of layout constrained field is unsafe | |
| 12 | x | |
| 13 | } | |
| 14 | ||
| 15 | const fn bar() -> NonZero<u32> { | |
| 16 | let mut x = unsafe { NonZero(1) }; | |
| 17 | unsafe { x.0 = 0 }; // this is UB | |
| 18 | x | |
| 19 | } |
tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints4_const.stderr created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block | |
| 2 | --> $DIR/ranged_ints4_const.rs:10:5 | |
| 3 | | | |
| 4 | LL | x.0 = 0; | |
| 5 | | ^^^^^^^ mutation of layout constrained field | |
| 6 | | | |
| 7 | = note: mutating layout constrained fields cannot statically be checked for valid values | |
| 8 | ||
| 9 | error: aborting due to 1 previous error | |
| 10 | ||
| 11 | For more information about this error, try `rustc --explain E0133`. |
tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints_const.rs created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | #![feature(rustc_attrs)] | |
| 2 | ||
| 3 | #[rustc_layout_scalar_valid_range_start(1)] | |
| 4 | #[repr(transparent)] | |
| 5 | pub(crate) struct NonZero<T>(pub(crate) T); | |
| 6 | fn main() {} | |
| 7 | ||
| 8 | const fn foo() -> NonZero<u32> { NonZero(0) } | |
| 9 | //~^ ERROR initializing type with `rustc_layout_scalar_valid_range` attr is unsafe | |
| 10 | ||
| 11 | const fn bar() -> NonZero<u32> { unsafe { NonZero(0) } } |
tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints_const.stderr created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | error[E0133]: initializing type with `rustc_layout_scalar_valid_range` attr is unsafe and requires unsafe function or block | |
| 2 | --> $DIR/ranged_ints_const.rs:8:34 | |
| 3 | | | |
| 4 | LL | const fn foo() -> NonZero<u32> { NonZero(0) } | |
| 5 | | ^^^^^^^^^^ initializing type with `rustc_layout_scalar_valid_range` attr | |
| 6 | | | |
| 7 | = note: initializing a layout restricted type's field with a value outside the valid range is undefined behavior | |
| 8 | ||
| 9 | error: aborting due to 1 previous error | |
| 10 | ||
| 11 | For more information about this error, try `rustc --explain E0133`. |
tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints_macro.rs created+17| ... | ... | @@ -0,0 +1,17 @@ |
| 1 | //@ build-pass | |
| 2 | ||
| 3 | #![feature(rustc_attrs)] | |
| 4 | ||
| 5 | macro_rules! apply { | |
| 6 | ($val:expr) => { | |
| 7 | #[rustc_layout_scalar_valid_range_start($val)] | |
| 8 | #[repr(transparent)] | |
| 9 | pub(crate) struct NonZero<T>(pub(crate) T); | |
| 10 | } | |
| 11 | } | |
| 12 | ||
| 13 | apply!(1); | |
| 14 | ||
| 15 | fn main() { | |
| 16 | let _x = unsafe { NonZero(1) }; | |
| 17 | } |
tests/ui/unsafe/union-assignop.rs deleted-26| ... | ... | @@ -1,26 +0,0 @@ |
| 1 | use std::ops::AddAssign; | |
| 2 | use std::mem::ManuallyDrop; | |
| 3 | ||
| 4 | struct NonCopy; | |
| 5 | impl AddAssign for NonCopy { | |
| 6 | fn add_assign(&mut self, _: Self) {} | |
| 7 | } | |
| 8 | ||
| 9 | union Foo { | |
| 10 | a: u8, // non-dropping | |
| 11 | b: ManuallyDrop<NonCopy>, | |
| 12 | } | |
| 13 | ||
| 14 | fn main() { | |
| 15 | let mut foo = Foo { a: 42 }; | |
| 16 | foo.a += 5; //~ ERROR access to union field is unsafe | |
| 17 | *foo.b += NonCopy; //~ ERROR access to union field is unsafe | |
| 18 | *foo.b = NonCopy; //~ ERROR access to union field is unsafe | |
| 19 | foo.b = ManuallyDrop::new(NonCopy); | |
| 20 | foo.a; //~ ERROR access to union field is unsafe | |
| 21 | let foo = Foo { a: 42 }; | |
| 22 | foo.b; //~ ERROR access to union field is unsafe | |
| 23 | let mut foo = Foo { a: 42 }; | |
| 24 | foo.b = foo.b; | |
| 25 | //~^ ERROR access to union field is unsafe | |
| 26 | } |
tests/ui/unsafe/union-assignop.stderr deleted-51| ... | ... | @@ -1,51 +0,0 @@ |
| 1 | error[E0133]: access to union field is unsafe and requires unsafe function or block | |
| 2 | --> $DIR/union-assignop.rs:16:5 | |
| 3 | | | |
| 4 | LL | foo.a += 5; | |
| 5 | | ^^^^^ access to union field | |
| 6 | | | |
| 7 | = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | |
| 8 | ||
| 9 | error[E0133]: access to union field is unsafe and requires unsafe function or block | |
| 10 | --> $DIR/union-assignop.rs:17:6 | |
| 11 | | | |
| 12 | LL | *foo.b += NonCopy; | |
| 13 | | ^^^^^ access to union field | |
| 14 | | | |
| 15 | = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | |
| 16 | ||
| 17 | error[E0133]: access to union field is unsafe and requires unsafe function or block | |
| 18 | --> $DIR/union-assignop.rs:18:6 | |
| 19 | | | |
| 20 | LL | *foo.b = NonCopy; | |
| 21 | | ^^^^^ access to union field | |
| 22 | | | |
| 23 | = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | |
| 24 | ||
| 25 | error[E0133]: access to union field is unsafe and requires unsafe function or block | |
| 26 | --> $DIR/union-assignop.rs:20:5 | |
| 27 | | | |
| 28 | LL | foo.a; | |
| 29 | | ^^^^^ access to union field | |
| 30 | | | |
| 31 | = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | |
| 32 | ||
| 33 | error[E0133]: access to union field is unsafe and requires unsafe function or block | |
| 34 | --> $DIR/union-assignop.rs:22:5 | |
| 35 | | | |
| 36 | LL | foo.b; | |
| 37 | | ^^^^^ access to union field | |
| 38 | | | |
| 39 | = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | |
| 40 | ||
| 41 | error[E0133]: access to union field is unsafe and requires unsafe function or block | |
| 42 | --> $DIR/union-assignop.rs:24:13 | |
| 43 | | | |
| 44 | LL | foo.b = foo.b; | |
| 45 | | ^^^^^ access to union field | |
| 46 | | | |
| 47 | = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | |
| 48 | ||
| 49 | error: aborting due to 6 previous errors | |
| 50 | ||
| 51 | For more information about this error, try `rustc --explain E0133`. |
tests/ui/unsafe/union-modification.rs deleted-34| ... | ... | @@ -1,34 +0,0 @@ |
| 1 | //@ run-pass | |
| 2 | union Foo { | |
| 3 | bar: i8, | |
| 4 | _blah: isize, | |
| 5 | _zst: (), | |
| 6 | } | |
| 7 | ||
| 8 | struct FooHolder { | |
| 9 | inner_foo: Foo | |
| 10 | } | |
| 11 | ||
| 12 | fn do_nothing(_x: &mut Foo) {} | |
| 13 | ||
| 14 | pub fn main() { | |
| 15 | let mut foo = Foo { bar: 5 }; | |
| 16 | do_nothing(&mut foo); | |
| 17 | foo.bar = 6; | |
| 18 | unsafe { foo.bar += 1; } | |
| 19 | assert_eq!(unsafe { foo.bar }, 7); | |
| 20 | unsafe { | |
| 21 | let Foo { bar: inner } = foo; | |
| 22 | assert_eq!(inner, 7); | |
| 23 | } | |
| 24 | ||
| 25 | let foo = Foo { bar: 5 }; | |
| 26 | let foo = if let 3 = if let true = true { 3 } else { 4 } { foo } else { foo }; | |
| 27 | ||
| 28 | let (_foo2, _random) = (foo, 42); | |
| 29 | ||
| 30 | let mut foo_holder = FooHolder { inner_foo: Foo { bar: 5 } }; | |
| 31 | foo_holder.inner_foo.bar = 4; | |
| 32 | assert_eq!(unsafe { foo_holder.inner_foo.bar }, 4); | |
| 33 | drop(foo_holder); | |
| 34 | } |
tests/ui/unsafe/union-pat-in-param.rs deleted-19| ... | ... | @@ -1,19 +0,0 @@ |
| 1 | union U { | |
| 2 | a: &'static i32, | |
| 3 | b: usize, | |
| 4 | } | |
| 5 | ||
| 6 | fn fun(U { a }: U) { | |
| 7 | //~^ ERROR access to union field is unsafe | |
| 8 | dbg!(*a); | |
| 9 | } | |
| 10 | ||
| 11 | fn main() { | |
| 12 | fun(U { b: 0 }); | |
| 13 | ||
| 14 | let closure = |U { a }| { | |
| 15 | //~^ ERROR access to union field is unsafe | |
| 16 | dbg!(*a); | |
| 17 | }; | |
| 18 | closure(U { b: 0 }); | |
| 19 | } |
tests/ui/unsafe/union-pat-in-param.stderr deleted-19| ... | ... | @@ -1,19 +0,0 @@ |
| 1 | error[E0133]: access to union field is unsafe and requires unsafe function or block | |
| 2 | --> $DIR/union-pat-in-param.rs:6:12 | |
| 3 | | | |
| 4 | LL | fn fun(U { a }: U) { | |
| 5 | | ^ access to union field | |
| 6 | | | |
| 7 | = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | |
| 8 | ||
| 9 | error[E0133]: access to union field is unsafe and requires unsafe function or block | |
| 10 | --> $DIR/union-pat-in-param.rs:14:24 | |
| 11 | | | |
| 12 | LL | let closure = |U { a }| { | |
| 13 | | ^ access to union field | |
| 14 | | | |
| 15 | = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | |
| 16 | ||
| 17 | error: aborting due to 2 previous errors | |
| 18 | ||
| 19 | For more information about this error, try `rustc --explain E0133`. |
tests/ui/unsafe/union.rs deleted-49| ... | ... | @@ -1,49 +0,0 @@ |
| 1 | union Foo { | |
| 2 | bar: i8, | |
| 3 | zst: (), | |
| 4 | pizza: Pizza, | |
| 5 | } | |
| 6 | ||
| 7 | #[derive(Clone, Copy)] | |
| 8 | struct Pizza { | |
| 9 | topping: Option<PizzaTopping> | |
| 10 | } | |
| 11 | ||
| 12 | #[allow(dead_code)] | |
| 13 | #[derive(Clone, Copy)] | |
| 14 | enum PizzaTopping { | |
| 15 | Cheese, | |
| 16 | Pineapple, | |
| 17 | } | |
| 18 | ||
| 19 | fn do_nothing(_x: &mut Foo) {} | |
| 20 | ||
| 21 | pub fn main() { | |
| 22 | let mut foo = Foo { bar: 5 }; | |
| 23 | do_nothing(&mut foo); | |
| 24 | ||
| 25 | // This is UB, so this test isn't run | |
| 26 | match foo { | |
| 27 | Foo { bar: _a } => {}, //~ ERROR access to union field is unsafe | |
| 28 | } | |
| 29 | match foo { | |
| 30 | Foo { | |
| 31 | pizza: Pizza { //~ ERROR access to union field is unsafe | |
| 32 | topping: Some(PizzaTopping::Cheese) | Some(PizzaTopping::Pineapple) | None | |
| 33 | } | |
| 34 | } => {}, | |
| 35 | } | |
| 36 | ||
| 37 | match foo { | |
| 38 | Foo { zst: () } => {} //~ ERROR access to union field is unsafe | |
| 39 | } | |
| 40 | match foo { | |
| 41 | Foo { pizza: Pizza { .. } } => {} //~ ERROR access to union field is unsafe | |
| 42 | } | |
| 43 | ||
| 44 | // binding to wildcard is okay | |
| 45 | match foo { | |
| 46 | Foo { bar: _ } => {}, | |
| 47 | } | |
| 48 | let Foo { bar: _ } = foo; | |
| 49 | } |
tests/ui/unsafe/union.stderr deleted-38| ... | ... | @@ -1,38 +0,0 @@ |
| 1 | error[E0133]: access to union field is unsafe and requires unsafe function or block | |
| 2 | --> $DIR/union.rs:27:20 | |
| 3 | | | |
| 4 | LL | Foo { bar: _a } => {}, | |
| 5 | | ^^ access to union field | |
| 6 | | | |
| 7 | = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | |
| 8 | ||
| 9 | error[E0133]: access to union field is unsafe and requires unsafe function or block | |
| 10 | --> $DIR/union.rs:31:20 | |
| 11 | | | |
| 12 | LL | pizza: Pizza { | |
| 13 | | ____________________^ | |
| 14 | LL | | topping: Some(PizzaTopping::Cheese) | Some(PizzaTopping::Pineapple) | None | |
| 15 | LL | | } | |
| 16 | | |_____________^ access to union field | |
| 17 | | | |
| 18 | = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | |
| 19 | ||
| 20 | error[E0133]: access to union field is unsafe and requires unsafe function or block | |
| 21 | --> $DIR/union.rs:38:20 | |
| 22 | | | |
| 23 | LL | Foo { zst: () } => {} | |
| 24 | | ^^ access to union field | |
| 25 | | | |
| 26 | = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | |
| 27 | ||
| 28 | error[E0133]: access to union field is unsafe and requires unsafe function or block | |
| 29 | --> $DIR/union.rs:41:22 | |
| 30 | | | |
| 31 | LL | Foo { pizza: Pizza { .. } } => {} | |
| 32 | | ^^^^^^^^^^^^ access to union field | |
| 33 | | | |
| 34 | = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | |
| 35 | ||
| 36 | error: aborting due to 4 previous errors | |
| 37 | ||
| 38 | For more information about this error, try `rustc --explain E0133`. |
tests/ui/unsafe/union_access_through_block.rs deleted-15| ... | ... | @@ -1,15 +0,0 @@ |
| 1 | //@ check-pass | |
| 2 | #[derive(Copy, Clone)] | |
| 3 | pub struct Foo { a: bool } | |
| 4 | ||
| 5 | pub union Bar { | |
| 6 | a: Foo, | |
| 7 | b: u32, | |
| 8 | } | |
| 9 | pub fn baz(mut bar: Bar) { | |
| 10 | unsafe { | |
| 11 | { bar.a }.a = true; | |
| 12 | } | |
| 13 | } | |
| 14 | ||
| 15 | fn main() {} |
tests/ui/unsafe/union_destructure.rs deleted-50| ... | ... | @@ -1,50 +0,0 @@ |
| 1 | //@ run-pass | |
| 2 | #![allow(unreachable_patterns)] | |
| 3 | ||
| 4 | #[derive(Copy, Clone)] | |
| 5 | #[allow(dead_code)] | |
| 6 | struct Pie { | |
| 7 | slices: u8, | |
| 8 | size: u8, | |
| 9 | } | |
| 10 | ||
| 11 | union Foo { | |
| 12 | #[allow(dead_code)] | |
| 13 | bar: i8, | |
| 14 | baz: Pie, | |
| 15 | } | |
| 16 | ||
| 17 | fn main() { | |
| 18 | let u = Foo { bar: 5 }; | |
| 19 | let (Some(Foo { bar: _ }) | None) = Some(u); | |
| 20 | let u = Foo { bar: 6 }; | |
| 21 | let (Some(Foo { bar: _ }) | Some(Foo { bar: _ }) | None) = Some(u); | |
| 22 | unsafe { | |
| 23 | let u = Foo { bar: 7 }; | |
| 24 | let (Foo { bar } | Foo { bar }) = u; | |
| 25 | assert_eq!(bar, 7) | |
| 26 | } | |
| 27 | let u = Foo { bar: 8 }; | |
| 28 | match Some(u) { | |
| 29 | Some(Foo { bar: _ }) => 3, | |
| 30 | None => 4, | |
| 31 | }; | |
| 32 | ||
| 33 | let u = Foo { bar: 9 }; | |
| 34 | unsafe { | |
| 35 | match u { | |
| 36 | Foo { baz: Pie { .. } } => {} | |
| 37 | }; | |
| 38 | } | |
| 39 | let u = Foo { bar: 10 }; | |
| 40 | unsafe { | |
| 41 | match u { | |
| 42 | Foo { baz: Pie { slices: _, size: _ } } => {} | |
| 43 | }; | |
| 44 | } | |
| 45 | ||
| 46 | let u = Foo { bar: 11 }; | |
| 47 | match u { | |
| 48 | Foo { baz: _ } => {} | |
| 49 | }; | |
| 50 | } |
tests/ui/unsafe/union_wild_or_wild.rs deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | //@ check-pass | |
| 2 | union X { a: i8 } | |
| 3 | ||
| 4 | fn main() { | |
| 5 | let x = X { a: 5 }; | |
| 6 | match x { | |
| 7 | X { a: _ | _ } => {}, | |
| 8 | } | |
| 9 | } |
triagebot.toml+5| ... | ... | @@ -194,6 +194,11 @@ Hi relnotes-interest-group, this issue/PR could use some help in reviewing / |
| 194 | 194 | adjusting release notes. Could you take a look if available? Thanks <3 |
| 195 | 195 | """ |
| 196 | 196 | |
| 197 | [ping.gpu-target] | |
| 198 | message = """\ | |
| 199 | Hi GPU experts, this issue/PR could use some guidance on how this should be | |
| 200 | resolved/implemented. Could you take a look if available? Thanks <3 | |
| 201 | """ | |
| 197 | 202 | |
| 198 | 203 | # ------------------------------------------------------------------------------ |
| 199 | 204 | # Autolabels |