Skip to content

Commit ce90db1

Browse files
committed
Deduplicate const eval error spans for better output
1 parent 4473027 commit ce90db1

File tree

4 files changed

+15
-29
lines changed

4 files changed

+15
-29
lines changed

src/librustc/mir/interpret/error.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> {
116116
// point to the `const` statement as a secondary span
117117
// they don't have any label
118118
for sp in primary_spans {
119-
lint.span_label(sp, "");
119+
if sp != span {
120+
lint.span_label(sp, "");
121+
}
120122
}
121123
}
122124
lint.emit();

src/test/ui/consts/const-eval/promoted_errors.stderr

+2-6
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,11 @@ warning: reaching this expression at runtime will panic or abort
5050
--> $DIR/promoted_errors.rs:14:20
5151
|
5252
LL | println!("{}", 1/(false as u32));
53-
| ^^^^^^^^^^^^^^^^
54-
| |
55-
| attempt to divide by zero
53+
| ^^^^^^^^^^^^^^^^ attempt to divide by zero
5654

5755
warning: reaching this expression at runtime will panic or abort
5856
--> $DIR/promoted_errors.rs:9:20
5957
|
6058
LL | println!("{}", 1/(1-1));
61-
| ^^^^^^^
62-
| |
63-
| attempt to divide by zero
59+
| ^^^^^^^ attempt to divide by zero
6460

src/test/ui/consts/dangling-alloc-id-ice.stderr

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
error: any use of this value will cause an error
22
--> $DIR/dangling-alloc-id-ice.rs:8:1
33
|
4-
LL | const FOO: &() = {
5-
| _^
6-
| |_|
7-
| ||
8-
LL | || let y = ();
9-
LL | || unsafe { Foo { y: &y }.long_live_the_unit }
10-
LL | || };
11-
| || ^
12-
| ||__|
13-
| |___type validation failed: encountered dangling pointer in final constant
14-
|
4+
LL | / const FOO: &() = {
5+
LL | | let y = ();
6+
LL | | unsafe { Foo { y: &y }.long_live_the_unit }
7+
LL | | };
8+
| |__^ type validation failed: encountered dangling pointer in final constant
159
|
1610
= note: #[deny(const_err)] on by default
1711

src/test/ui/consts/dangling_raw_ptr.stderr

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
error: any use of this value will cause an error
22
--> $DIR/dangling_raw_ptr.rs:1:1
33
|
4-
LL | const FOO: *const u32 = {
5-
| _^
6-
| |_|
7-
| ||
8-
LL | || let x = 42;
9-
LL | || &x
10-
LL | || };
11-
| || ^
12-
| ||__|
13-
| |___type validation failed: encountered dangling pointer in final constant
14-
|
4+
LL | / const FOO: *const u32 = {
5+
LL | | let x = 42;
6+
LL | | &x
7+
LL | | };
8+
| |__^ type validation failed: encountered dangling pointer in final constant
159
|
1610
= note: #[deny(const_err)] on by default
1711

0 commit comments

Comments
 (0)