Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup leftovers of const_err lint #115771

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions compiler/rustc_const_eval/src/const_eval/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use rustc_errors::{DiagnosticArgValue, DiagnosticMessage, IntoDiagnostic, IntoDi
use rustc_middle::mir::AssertKind;
use rustc_middle::ty::TyCtxt;
use rustc_middle::ty::{layout::LayoutError, ConstInt};
use rustc_span::source_map::Spanned;
use rustc_span::{ErrorGuaranteed, Span, Symbol};

use super::InterpCx;
Expand Down Expand Up @@ -132,35 +131,17 @@ where
{
// Special handling for certain errors
match error {
// Don't emit a new diagnostic for these errors
// Don't emit a new diagnostic for these errors, they are already reported elsewhere or
// should remain silent.
err_inval!(Layout(LayoutError::Unknown(_))) | err_inval!(TooGeneric) => {
ErrorHandled::TooGeneric
}
err_inval!(AlreadyReported(guar)) => ErrorHandled::Reported(guar),
err_inval!(Layout(LayoutError::ReferencesError(guar))) => {
ErrorHandled::Reported(guar.into())
}
err_inval!(Layout(layout_error @ LayoutError::SizeOverflow(_))) => {
// We must *always* hard error on these, even if the caller wants just a lint.
// The `message` makes little sense here, this is a more serious error than the
// caller thinks anyway.
// See <https://github.com/rust-lang/rust/pull/63152>.
let (our_span, frames) = get_span_and_frames();
let span = span.unwrap_or(our_span);
let mut err =
tcx.sess.create_err(Spanned { span, node: layout_error.into_diagnostic() });
err.code(rustc_errors::error_code!(E0080));
let Some((mut err, handler)) = err.into_diagnostic() else {
panic!("did not emit diag");
};
for frame in frames {
err.eager_subdiagnostic(handler, frame);
}

ErrorHandled::Reported(handler.emit_diagnostic(&mut err).unwrap().into())
}
// Report remaining errors.
_ => {
// Report as hard error.
let (our_span, frames) = get_span_and_frames();
let span = span.unwrap_or(our_span);
let err = mk(span, frames);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/const_eval/eval_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
};
let alloc_id = mplace.ptr().provenance.unwrap();

// Validation failed, report an error. This is always a hard error.
// Validation failed, report an error.
if let Err(error) = validation {
let (error, backtrace) = error.into_parts();
backtrace.print_backtrace();
Expand Down
4 changes: 3 additions & 1 deletion tests/ui/limits/issue-55878.stderr
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
error[E0080]: values of the type `[u8; usize::MAX]` are too big for the current architecture
error[E0080]: evaluation of constant value failed
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
|
= note: values of the type `[u8; usize::MAX]` are too big for the current architecture
|
note: inside `std::mem::size_of::<[u8; usize::MAX]>`
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
note: inside `main`
Expand Down
6 changes: 4 additions & 2 deletions tests/ui/limits/issue-56762.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ impl TooBigArray {
}

static MY_TOO_BIG_ARRAY_1: TooBigArray = TooBigArray::new();
//~^ ERROR values of the type `[u8; 2305843009213693951]` are too big
//~^ ERROR could not evaluate static initializer
//~| too big
static MY_TOO_BIG_ARRAY_2: [u8; HUGE_SIZE] = [0x00; HUGE_SIZE];
//~^ ERROR values of the type `[u8; 2305843009213693951]` are too big
//~^ ERROR could not evaluate static initializer
//~| too big

fn main() { }
10 changes: 5 additions & 5 deletions tests/ui/limits/issue-56762.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
error[E0080]: values of the type `[u8; 2305843009213693951]` are too big for the current architecture
error[E0080]: could not evaluate static initializer
--> $DIR/issue-56762.rs:16:1
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that this is always a hard error I don't see a good reason to emit a different diagnostic just for the "too big" case.

|
LL | static MY_TOO_BIG_ARRAY_1: TooBigArray = TooBigArray::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ values of the type `[u8; 2305843009213693951]` are too big for the current architecture

error[E0080]: values of the type `[u8; 2305843009213693951]` are too big for the current architecture
--> $DIR/issue-56762.rs:18:1
error[E0080]: could not evaluate static initializer
--> $DIR/issue-56762.rs:19:1
|
LL | static MY_TOO_BIG_ARRAY_2: [u8; HUGE_SIZE] = [0x00; HUGE_SIZE];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ values of the type `[u8; 2305843009213693951]` are too big for the current architecture

error: aborting due to 2 previous errors

Expand Down
Loading