From f03c2aef470250fbc2a2552c146bc19ffe08422c Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Thu, 1 Dec 2022 19:13:18 +0000 Subject: [PATCH] Add tests --- .../ui/inline-const/expr-unsafe-err.mir.stderr | 11 +++++++++++ src/test/ui/inline-const/expr-unsafe-err.rs | 11 +++++++++++ .../ui/inline-const/expr-unsafe-err.thir.stderr | 11 +++++++++++ src/test/ui/inline-const/expr-unsafe.mir.stderr | 14 ++++++++++++++ src/test/ui/inline-const/expr-unsafe.rs | 16 ++++++++++++++++ .../ui/inline-const/expr-unsafe.thir.stderr | 17 +++++++++++++++++ 6 files changed, 80 insertions(+) create mode 100644 src/test/ui/inline-const/expr-unsafe-err.mir.stderr create mode 100644 src/test/ui/inline-const/expr-unsafe-err.rs create mode 100644 src/test/ui/inline-const/expr-unsafe-err.thir.stderr create mode 100644 src/test/ui/inline-const/expr-unsafe.mir.stderr create mode 100644 src/test/ui/inline-const/expr-unsafe.rs create mode 100644 src/test/ui/inline-const/expr-unsafe.thir.stderr diff --git a/src/test/ui/inline-const/expr-unsafe-err.mir.stderr b/src/test/ui/inline-const/expr-unsafe-err.mir.stderr new file mode 100644 index 00000000000..1bec41e2efa --- /dev/null +++ b/src/test/ui/inline-const/expr-unsafe-err.mir.stderr @@ -0,0 +1,11 @@ +error[E0133]: call to unsafe function is unsafe and requires unsafe function or block + --> $DIR/expr-unsafe-err.rs:8:9 + | +LL | require_unsafe(); + | ^^^^^^^^^^^^^^^^ call to unsafe function + | + = note: consult the function's documentation for information on how to avoid undefined behavior + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/inline-const/expr-unsafe-err.rs b/src/test/ui/inline-const/expr-unsafe-err.rs new file mode 100644 index 00000000000..adf05d352ea --- /dev/null +++ b/src/test/ui/inline-const/expr-unsafe-err.rs @@ -0,0 +1,11 @@ +// revisions: mir thir +// [thir]compile-flags: -Z thir-unsafeck +#![feature(inline_const)] +const unsafe fn require_unsafe() -> usize { 1 } + +fn main() { + const { + require_unsafe(); + //~^ ERROR [E0133] + } +} diff --git a/src/test/ui/inline-const/expr-unsafe-err.thir.stderr b/src/test/ui/inline-const/expr-unsafe-err.thir.stderr new file mode 100644 index 00000000000..c971e8afb35 --- /dev/null +++ b/src/test/ui/inline-const/expr-unsafe-err.thir.stderr @@ -0,0 +1,11 @@ +error[E0133]: call to unsafe function `require_unsafe` is unsafe and requires unsafe function or block + --> $DIR/expr-unsafe-err.rs:8:9 + | +LL | require_unsafe(); + | ^^^^^^^^^^^^^^^^ call to unsafe function + | + = note: consult the function's documentation for information on how to avoid undefined behavior + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/inline-const/expr-unsafe.mir.stderr b/src/test/ui/inline-const/expr-unsafe.mir.stderr new file mode 100644 index 00000000000..1ab6e42fba0 --- /dev/null +++ b/src/test/ui/inline-const/expr-unsafe.mir.stderr @@ -0,0 +1,14 @@ +warning: unnecessary `unsafe` block + --> $DIR/expr-unsafe.rs:12:13 + | +LL | unsafe {} + | ^^^^^^ unnecessary `unsafe` block + | +note: the lint level is defined here + --> $DIR/expr-unsafe.rs:4:9 + | +LL | #![warn(unused_unsafe)] + | ^^^^^^^^^^^^^ + +warning: 1 warning emitted + diff --git a/src/test/ui/inline-const/expr-unsafe.rs b/src/test/ui/inline-const/expr-unsafe.rs new file mode 100644 index 00000000000..d71efd33db1 --- /dev/null +++ b/src/test/ui/inline-const/expr-unsafe.rs @@ -0,0 +1,16 @@ +// check-pass +// revisions: mir thir +// [thir]compile-flags: -Z thir-unsafeck +#![warn(unused_unsafe)] +#![feature(inline_const)] +const unsafe fn require_unsafe() -> usize { 1 } + +fn main() { + unsafe { + const { + require_unsafe(); + unsafe {} + //~^ WARNING unnecessary `unsafe` block + } + } +} diff --git a/src/test/ui/inline-const/expr-unsafe.thir.stderr b/src/test/ui/inline-const/expr-unsafe.thir.stderr new file mode 100644 index 00000000000..4737444fb61 --- /dev/null +++ b/src/test/ui/inline-const/expr-unsafe.thir.stderr @@ -0,0 +1,17 @@ +warning: unnecessary `unsafe` block + --> $DIR/expr-unsafe.rs:12:13 + | +LL | unsafe { + | ------ because it's nested under this `unsafe` block +... +LL | unsafe {} + | ^^^^^^ unnecessary `unsafe` block + | +note: the lint level is defined here + --> $DIR/expr-unsafe.rs:4:9 + | +LL | #![warn(unused_unsafe)] + | ^^^^^^^^^^^^^ + +warning: 1 warning emitted +