Skip to content

Commit 64a7ed3

Browse files
committed
Revert order of constant evaluation errors
Point at theh code the user wrote first and std functions last. ``` error[E0080]: evaluation of constant value failed --> $DIR/const-errs-dont-conflict-103369.rs:5:25 | LL | impl ConstGenericTrait<{my_fn(1)}> for () {} | ^^^^^^^^ Some error occurred | note: called from `my_fn` --> $DIR/const-errs-dont-conflict-103369.rs:10:5 | LL | panic!("Some error occurred"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) ``` instead of ``` error[E0080]: evaluation of constant value failed --> $DIR/const-errs-dont-conflict-103369.rs:10:5 | LL | panic!("Some error occurred"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Some error occurred | note: called from `<() as ConstGenericTrait<{my_fn(1)}>>::{constant#0}` --> $DIR/const-errs-dont-conflict-103369.rs:5:25 | LL | impl ConstGenericTrait<{my_fn(1)}> for () {} | ^^^^^^^^ = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) ```
1 parent 474462f commit 64a7ed3

File tree

71 files changed

+429
-512
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+429
-512
lines changed

compiler/rustc_const_eval/src/const_eval/error.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub fn get_span_and_frames<'tcx>(
6969
let mut stacktrace = Frame::generate_stacktrace_from_stack(stack);
7070
// Filter out `requires_caller_location` frames.
7171
stacktrace.retain(|frame| !frame.instance.def.requires_caller_location(*tcx));
72-
let span = stacktrace.first().map(|f| f.span).unwrap_or(tcx.span);
72+
let span = stacktrace.last().map(|f| f.span).unwrap_or(tcx.span);
7373

7474
let mut frames = Vec::new();
7575

@@ -111,6 +111,10 @@ pub fn get_span_and_frames<'tcx>(
111111
add_frame(frame);
112112
}
113113
}
114+
frames.reverse();
115+
if frames.len() > 0 {
116+
frames.remove(0);
117+
}
114118

115119
(span, frames)
116120
}
@@ -147,11 +151,8 @@ where
147151
}
148152
// Report remaining errors.
149153
_ => {
150-
let (our_span, mut frames) = get_span_and_frames();
154+
let (our_span, frames) = get_span_and_frames();
151155
let span = span.substitute_dummy(our_span);
152-
if frames.len() > 0 {
153-
frames.remove(0);
154-
}
155156
let err = mk(span, frames);
156157
let mut err = tcx.dcx().create_err(err);
157158
// We allow invalid programs in infallible promoteds since invalid layouts can occur

tests/ui/borrowck/issue-81899.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
// Regression test for #81899.
22
// The `panic!()` below is important to trigger the fixed ICE.
33

4-
const _CONST: &[u8] = &f(&[], |_| {});
4+
const _CONST: &[u8] = &f(&[], |_| {}); //~ ERROR evaluation of constant value failed
55
//~^ constant
66

77
const fn f<F>(_: &[u8], _: F) -> &[u8]
88
where
99
F: FnMut(&u8),
1010
{
11-
panic!() //~ ERROR evaluation of constant value failed
12-
//~^ panic
11+
panic!() //~ panic
1312
}
1413

1514
fn main() {}

tests/ui/borrowck/issue-81899.stderr

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
error[E0080]: evaluation of constant value failed
2-
--> $DIR/issue-81899.rs:11:5
3-
|
4-
LL | panic!()
5-
| ^^^^^^^^ explicit panic
6-
|
7-
note: called from `_CONST`
82
--> $DIR/issue-81899.rs:4:24
93
|
104
LL | const _CONST: &[u8] = &f(&[], |_| {});
11-
| ^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^ explicit panic
6+
|
7+
note: called from `f::<{closure@$DIR/issue-81899.rs:4:31: 4:34}>`
8+
--> $DIR/issue-81899.rs:11:5
9+
|
10+
LL | panic!()
11+
| ^^^^^^^^
1212
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
1313

1414
note: erroneous constant encountered
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
// Regression test related to issue 88434
22

3-
const _CONST: &() = &f(&|_| {});
3+
const _CONST: &() = &f(&|_| {}); //~ ERROR evaluation of constant value failed
44
//~^ constant
55

66
const fn f<F>(_: &F)
77
where
88
F: FnMut(&u8),
99
{
10-
panic!() //~ ERROR evaluation of constant value failed
11-
//~^ panic
10+
panic!() //~ panic
1211
}
1312

1413
fn main() { }

tests/ui/borrowck/issue-88434-minimal-example.stderr

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
error[E0080]: evaluation of constant value failed
2-
--> $DIR/issue-88434-minimal-example.rs:10:5
3-
|
4-
LL | panic!()
5-
| ^^^^^^^^ explicit panic
6-
|
7-
note: called from `_CONST`
82
--> $DIR/issue-88434-minimal-example.rs:3:22
93
|
104
LL | const _CONST: &() = &f(&|_| {});
11-
| ^^^^^^^^^^
5+
| ^^^^^^^^^^ explicit panic
6+
|
7+
note: called from `f::<{closure@$DIR/issue-88434-minimal-example.rs:3:25: 3:28}>`
8+
--> $DIR/issue-88434-minimal-example.rs:10:5
9+
|
10+
LL | panic!()
11+
| ^^^^^^^^
1212
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
1313

1414
note: erroneous constant encountered
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
// Regression test for issue 88434
22

3-
const _CONST: &[u8] = &f(&[], |_| {});
3+
const _CONST: &[u8] = &f(&[], |_| {}); //~ ERROR evaluation of constant value failed
44
//~^ constant
55

66
const fn f<F>(_: &[u8], _: F) -> &[u8]
77
where
88
F: FnMut(&u8),
99
{
10-
panic!() //~ ERROR evaluation of constant value failed
11-
//~^ panic
10+
panic!() //~ panic
1211
}
1312

1413
fn main() { }

tests/ui/borrowck/issue-88434-removal-index-should-be-less.stderr

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
error[E0080]: evaluation of constant value failed
2-
--> $DIR/issue-88434-removal-index-should-be-less.rs:10:5
3-
|
4-
LL | panic!()
5-
| ^^^^^^^^ explicit panic
6-
|
7-
note: called from `_CONST`
82
--> $DIR/issue-88434-removal-index-should-be-less.rs:3:24
93
|
104
LL | const _CONST: &[u8] = &f(&[], |_| {});
11-
| ^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^ explicit panic
6+
|
7+
note: called from `f::<{closure@$DIR/issue-88434-removal-index-should-be-less.rs:3:31: 3:34}>`
8+
--> $DIR/issue-88434-removal-index-should-be-less.rs:10:5
9+
|
10+
LL | panic!()
11+
| ^^^^^^^^
1212
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
1313

1414
note: erroneous constant encountered

tests/ui/coherence/const-errs-dont-conflict-103369.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
pub trait ConstGenericTrait<const N: u32> {}
44

5-
impl ConstGenericTrait<{my_fn(1)}> for () {}
5+
impl ConstGenericTrait<{my_fn(1)}> for () {} //~ ERROR E0080
66

7-
impl ConstGenericTrait<{my_fn(2)}> for () {}
7+
impl ConstGenericTrait<{my_fn(2)}> for () {} //~ ERROR E0080
88

99
const fn my_fn(v: u32) -> u32 {
10-
panic!("Some error occurred"); //~ ERROR E0080
11-
//~| ERROR E0080
10+
panic!("Some error occurred");
1211
}
1312

1413
fn main() {}

tests/ui/coherence/const-errs-dont-conflict-103369.stderr

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
error[E0080]: evaluation of constant value failed
2-
--> $DIR/const-errs-dont-conflict-103369.rs:10:5
3-
|
4-
LL | panic!("Some error occurred");
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Some error occurred
6-
|
7-
note: called from `<() as ConstGenericTrait<{my_fn(1)}>>::{constant#0}`
82
--> $DIR/const-errs-dont-conflict-103369.rs:5:25
93
|
104
LL | impl ConstGenericTrait<{my_fn(1)}> for () {}
11-
| ^^^^^^^^
12-
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
13-
14-
error[E0080]: evaluation of constant value failed
5+
| ^^^^^^^^ Some error occurred
6+
|
7+
note: called from `my_fn`
158
--> $DIR/const-errs-dont-conflict-103369.rs:10:5
169
|
1710
LL | panic!("Some error occurred");
18-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Some error occurred
19-
|
20-
note: called from `<() as ConstGenericTrait<{my_fn(2)}>>::{constant#0}`
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
13+
14+
error[E0080]: evaluation of constant value failed
2115
--> $DIR/const-errs-dont-conflict-103369.rs:7:25
2216
|
2317
LL | impl ConstGenericTrait<{my_fn(2)}> for () {}
24-
| ^^^^^^^^
18+
| ^^^^^^^^ Some error occurred
19+
|
20+
note: called from `my_fn`
21+
--> $DIR/const-errs-dont-conflict-103369.rs:10:5
22+
|
23+
LL | panic!("Some error occurred");
24+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2525
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
2626

2727
error: aborting due to 2 previous errors

tests/ui/const-generics/issues/issue-100313.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ impl<const B: &'static bool> T<B> {
77
const fn set_false(&self) {
88
unsafe {
99
*(B as *const bool as *mut bool) = false;
10-
//~^ ERROR evaluation of constant value failed [E0080]
1110
}
1211
}
1312
}
1413

1514
const _: () = {
1615
let x = T::<{ &true }>;
17-
x.set_false();
16+
x.set_false(); //~ ERROR evaluation of constant value failed [E0080]
1817
};
1918

2019
fn main() {}

tests/ui/const-generics/issues/issue-100313.stderr

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
error[E0080]: evaluation of constant value failed
2-
--> $DIR/issue-100313.rs:9:13
2+
--> $DIR/issue-100313.rs:16:5
33
|
4-
LL | *(B as *const bool as *mut bool) = false;
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ writing to ALLOC0 which is read-only
4+
LL | x.set_false();
5+
| ^^^^^^^^^^^^^ writing to ALLOC0 which is read-only
66
|
7-
note: called from `_`
8-
--> $DIR/issue-100313.rs:17:5
7+
note: called from `T::<&true>::set_false`
8+
--> $DIR/issue-100313.rs:9:13
99
|
10-
LL | x.set_false();
11-
| ^^^^^^^^^^^^^
10+
LL | *(B as *const bool as *mut bool) = false;
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

1313
error: aborting due to 1 previous error
1414

tests/ui/const-ptr/forbidden_slices.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ pub static S8: &[u64] = unsafe {
4848
pub static R0: &[u32] = unsafe { from_ptr_range(ptr::null()..ptr::null()) };
4949
//~^ ERROR it is undefined behavior to use this value
5050
pub static R1: &[()] = unsafe { from_ptr_range(ptr::null()..ptr::null()) }; // errors inside libcore
51+
//~^ ERROR could not evaluate static initializer
5152
pub static R2: &[u32] = unsafe {
5253
let ptr = &D0 as *const u32;
5354
from_ptr_range(ptr..ptr.add(2)) // errors inside libcore
55+
//~^ ERROR could not evaluate static initializer
5456
};
5557
pub static R4: &[u8] = unsafe {
5658
//~^ ERROR: it is undefined behavior to use this value
@@ -74,13 +76,16 @@ pub static R7: &[u16] = unsafe {
7476
};
7577
pub static R8: &[u64] = unsafe {
7678
let ptr = (&D4 as *const [u32; 2] as *const u32).byte_add(1).cast::<u64>();
77-
from_ptr_range(ptr..ptr.add(1)) //~ called from `R8`
79+
from_ptr_range(ptr..ptr.add(1))
80+
//~^ ERROR could not evaluate static initializer
7881
};
7982

8083
// This is sneaky: &D0 and &D0 point to different objects
8184
// (even if at runtime they have the same address)
8285
pub static R9: &[u32] = unsafe { from_ptr_range(&D0..(&D0 as *const u32).add(1)) };
86+
//~^ ERROR could not evaluate static initializer
8387
pub static R10: &[u32] = unsafe { from_ptr_range(&D0..&D0) };
88+
//~^ ERROR could not evaluate static initializer
8489

8590
const D0: u32 = 0x11111111; // Constant chosen for endianness-independent behavior.
8691
const D1: MaybeUninit<&u32> = MaybeUninit::uninit();

0 commit comments

Comments
 (0)