Skip to content

Commit 2c56842

Browse files
committed
avoid mutable state and override main message
1 parent d3da411 commit 2c56842

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

src/librustc/mir/interpret/error.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,15 @@ impl<'tcx> ConstEvalErr<'tcx> {
137137
message: &str,
138138
lint_root: Option<hir::HirId>,
139139
) -> Result<DiagnosticBuilder<'tcx>, ErrorHandled> {
140-
let mut must_error = false;
141-
match self.error {
140+
let must_error = match self.error {
142141
err_inval!(Layout(LayoutError::Unknown(_))) |
143142
err_inval!(TooGeneric) =>
144143
return Err(ErrorHandled::TooGeneric),
145144
err_inval!(TypeckError) =>
146145
return Err(ErrorHandled::Reported),
147-
err_inval!(Layout(LayoutError::SizeOverflow(_))) => must_error = true,
148-
_ => {},
149-
}
146+
err_inval!(Layout(LayoutError::SizeOverflow(_))) => true,
147+
_ => false,
148+
};
150149
trace!("reporting const eval failure at {:?}", self.span);
151150
let mut err = if let (Some(lint_root), false) = (lint_root, must_error) {
152151
let hir_id = self.stacktrace
@@ -161,6 +160,8 @@ impl<'tcx> ConstEvalErr<'tcx> {
161160
tcx.span,
162161
message,
163162
)
163+
} else if must_error {
164+
struct_error(tcx, &self.error.to_string())
164165
} else {
165166
struct_error(tcx, message)
166167
};

src/test/ui/consts/issue-55878.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// error-pattern: reaching this expression at runtime will panic or abort
1+
// error-pattern: the type `[u8; 18446744073709551615]` is too big for the current architecture
22
fn main() {
33
println!("Size: {}", std::mem::size_of::<[u8; std::u64::MAX as usize]>());
44
}

src/test/ui/consts/issue-55878.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0080]: reaching this expression at runtime will panic or abort
1+
error[E0080]: the type `[u8; 18446744073709551615]` is too big for the current architecture
22
--> $SRC_DIR/libcore/mem/mod.rs:LL:COL
33
|
44
LL | intrinsics::size_of::<T>()

src/test/ui/issues/issue-56762.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ impl TooBigArray {
1717
}
1818

1919
static MY_TOO_BIG_ARRAY_1: TooBigArray = TooBigArray::new();
20-
//~^ ERROR could not evaluate static initializer
20+
//~^ ERROR the type `[u8; 2305843009213693951]` is too big for the current architecture
2121
static MY_TOO_BIG_ARRAY_2: [u8; HUGE_SIZE] = [0x00; HUGE_SIZE];
22-
//~^ ERROR could not evaluate static initializer
22+
//~^ ERROR the type `[u8; 2305843009213693951]` is too big for the current architecture
2323

2424
fn main() { }

src/test/ui/issues/issue-56762.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error[E0080]: could not evaluate static initializer
1+
error[E0080]: the type `[u8; 2305843009213693951]` is too big for the current architecture
22
--> $DIR/issue-56762.rs:19:1
33
|
44
LL | static MY_TOO_BIG_ARRAY_1: TooBigArray = TooBigArray::new();
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the type `[u8; 2305843009213693951]` is too big for the current architecture
66

7-
error[E0080]: could not evaluate static initializer
7+
error[E0080]: the type `[u8; 2305843009213693951]` is too big for the current architecture
88
--> $DIR/issue-56762.rs:21:1
99
|
1010
LL | static MY_TOO_BIG_ARRAY_2: [u8; HUGE_SIZE] = [0x00; HUGE_SIZE];

0 commit comments

Comments
 (0)