diff options
| author | Mara Bos <m-ou.se@m-ou.se> | 2021-07-09 16:20:36 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-09 16:20:36 +0200 |
| commit | 2152c145d3a59a8a47bf370198b11410e329a71c (patch) | |
| tree | f323430d928a70862f2133445bf052030b3d886f /src/test | |
| parent | 98f35589f73e9f2a024928ed0ebe2151613630f8 (diff) | |
| parent | 0a4b53f57dc36e3f997a72161a0eb6426122e6bd (diff) | |
| download | rust-2152c145d3a59a8a47bf370198b11410e329a71c.tar.gz rust-2152c145d3a59a8a47bf370198b11410e329a71c.zip | |
Rollup merge of #87000 - m-ou-se:const-panic-track-caller, r=oli-obk
Use #[track_caller] in const panic diagnostics. This change stops const panic diagnostics from reporting inside #[track_caller] functions by skipping over them.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/consts/const-eval/const_panic_track_caller.rs | 23 | ||||
| -rw-r--r-- | src/test/ui/consts/const-eval/const_panic_track_caller.stderr | 15 | ||||
| -rw-r--r-- | src/test/ui/consts/const-unwrap.rs | 5 | ||||
| -rw-r--r-- | src/test/ui/consts/const-unwrap.stderr | 14 |
4 files changed, 42 insertions, 15 deletions
diff --git a/src/test/ui/consts/const-eval/const_panic_track_caller.rs b/src/test/ui/consts/const-eval/const_panic_track_caller.rs new file mode 100644 index 00000000000..7c2532673c8 --- /dev/null +++ b/src/test/ui/consts/const-eval/const_panic_track_caller.rs @@ -0,0 +1,23 @@ +#![feature(const_panic)] +#![allow(non_fmt_panics)] +#![crate_type = "lib"] + +#[track_caller] +const fn a() -> u32 { + panic!("hey") +} + +#[track_caller] +const fn b() -> u32 { + a() +} + +const fn c() -> u32 { + b() + //~^ ERROR evaluation of constant value failed + //~| NOTE the evaluated program panicked + //~| NOTE inside +} + +const X: u32 = c(); +//~^ NOTE inside diff --git a/src/test/ui/consts/const-eval/const_panic_track_caller.stderr b/src/test/ui/consts/const-eval/const_panic_track_caller.stderr new file mode 100644 index 00000000000..9a458db6ea2 --- /dev/null +++ b/src/test/ui/consts/const-eval/const_panic_track_caller.stderr @@ -0,0 +1,15 @@ +error[E0080]: evaluation of constant value failed + --> $DIR/const_panic_track_caller.rs:16:5 + | +LL | b() + | ^^^ + | | + | the evaluated program panicked at 'hey', $DIR/const_panic_track_caller.rs:16:5 + | inside `c` at $DIR/const_panic_track_caller.rs:16:5 +... +LL | const X: u32 = c(); + | --- inside `X` at $DIR/const_panic_track_caller.rs:22:16 + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-unwrap.rs b/src/test/ui/consts/const-unwrap.rs index 6ed60ed87bf..729ae535cef 100644 --- a/src/test/ui/consts/const-unwrap.rs +++ b/src/test/ui/consts/const-unwrap.rs @@ -4,9 +4,8 @@ const FOO: i32 = Some(42i32).unwrap(); -// This causes an error, but it is attributed to the `panic` *inside* `Option::unwrap` (maybe due -// to `track_caller`?). A note points to the originating `const`. -const BAR: i32 = Option::<i32>::None.unwrap(); //~ NOTE +const BAR: i32 = Option::<i32>::None.unwrap(); +//~^ERROR: evaluation of constant value failed fn main() { println!("{}", FOO); diff --git a/src/test/ui/consts/const-unwrap.stderr b/src/test/ui/consts/const-unwrap.stderr index 9a820ff7217..d2cbe4550f4 100644 --- a/src/test/ui/consts/const-unwrap.stderr +++ b/src/test/ui/consts/const-unwrap.stderr @@ -1,18 +1,8 @@ error[E0080]: evaluation of constant value failed - --> $SRC_DIR/core/src/option.rs:LL:COL - | -LL | None => panic!("called `Option::unwrap()` on a `None` value"), - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | the evaluated program panicked at 'called `Option::unwrap()` on a `None` value', $DIR/const-unwrap.rs:9:38 - | inside `Option::<i32>::unwrap` at $SRC_DIR/core/src/panic.rs:LL:COL - | - ::: $DIR/const-unwrap.rs:9:18 + --> $DIR/const-unwrap.rs:7:18 | LL | const BAR: i32 = Option::<i32>::None.unwrap(); - | ---------------------------- inside `BAR` at $DIR/const-unwrap.rs:9:18 - | - = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'called `Option::unwrap()` on a `None` value', $DIR/const-unwrap.rs:7:38 error: aborting due to previous error |
