From ce90db1ff103224bc2a63e7a9ac503259fbe7eb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Mon, 11 Mar 2019 09:43:05 -0700 Subject: [PATCH] Deduplicate const eval error spans for better output --- src/librustc/mir/interpret/error.rs | 4 +++- .../ui/consts/const-eval/promoted_errors.stderr | 8 ++------ src/test/ui/consts/dangling-alloc-id-ice.stderr | 16 +++++----------- src/test/ui/consts/dangling_raw_ptr.stderr | 16 +++++----------- 4 files changed, 15 insertions(+), 29 deletions(-) diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs index 5cd1ced2022..fc04c7672db 100644 --- a/src/librustc/mir/interpret/error.rs +++ b/src/librustc/mir/interpret/error.rs @@ -116,7 +116,9 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> { // point to the `const` statement as a secondary span // they don't have any label for sp in primary_spans { - lint.span_label(sp, ""); + if sp != span { + lint.span_label(sp, ""); + } } } lint.emit(); diff --git a/src/test/ui/consts/const-eval/promoted_errors.stderr b/src/test/ui/consts/const-eval/promoted_errors.stderr index ca870c649f5..c9d5ede61ad 100644 --- a/src/test/ui/consts/const-eval/promoted_errors.stderr +++ b/src/test/ui/consts/const-eval/promoted_errors.stderr @@ -50,15 +50,11 @@ warning: reaching this expression at runtime will panic or abort --> $DIR/promoted_errors.rs:14:20 | LL | println!("{}", 1/(false as u32)); - | ^^^^^^^^^^^^^^^^ - | | - | attempt to divide by zero + | ^^^^^^^^^^^^^^^^ attempt to divide by zero warning: reaching this expression at runtime will panic or abort --> $DIR/promoted_errors.rs:9:20 | LL | println!("{}", 1/(1-1)); - | ^^^^^^^ - | | - | attempt to divide by zero + | ^^^^^^^ attempt to divide by zero diff --git a/src/test/ui/consts/dangling-alloc-id-ice.stderr b/src/test/ui/consts/dangling-alloc-id-ice.stderr index ba640b90e7d..87f84480bf6 100644 --- a/src/test/ui/consts/dangling-alloc-id-ice.stderr +++ b/src/test/ui/consts/dangling-alloc-id-ice.stderr @@ -1,17 +1,11 @@ error: any use of this value will cause an error --> $DIR/dangling-alloc-id-ice.rs:8:1 | -LL | const FOO: &() = { - | _^ - | |_| - | || -LL | || let y = (); -LL | || unsafe { Foo { y: &y }.long_live_the_unit } -LL | || }; - | || ^ - | ||__| - | |___type validation failed: encountered dangling pointer in final constant - | +LL | / const FOO: &() = { +LL | | let y = (); +LL | | unsafe { Foo { y: &y }.long_live_the_unit } +LL | | }; + | |__^ type validation failed: encountered dangling pointer in final constant | = note: #[deny(const_err)] on by default diff --git a/src/test/ui/consts/dangling_raw_ptr.stderr b/src/test/ui/consts/dangling_raw_ptr.stderr index cedcbf819e2..0168c08f011 100644 --- a/src/test/ui/consts/dangling_raw_ptr.stderr +++ b/src/test/ui/consts/dangling_raw_ptr.stderr @@ -1,17 +1,11 @@ error: any use of this value will cause an error --> $DIR/dangling_raw_ptr.rs:1:1 | -LL | const FOO: *const u32 = { - | _^ - | |_| - | || -LL | || let x = 42; -LL | || &x -LL | || }; - | || ^ - | ||__| - | |___type validation failed: encountered dangling pointer in final constant - | +LL | / const FOO: *const u32 = { +LL | | let x = 42; +LL | | &x +LL | | }; + | |__^ type validation failed: encountered dangling pointer in final constant | = note: #[deny(const_err)] on by default