Auto merge of #115748 - RalfJung:post-mono, r=oli-obk

move required_consts check to general post-mono-check function

This factors some code that is common between the interpreter and the codegen backends into shared helper functions. Also as a side-effect the interpreter now uses the same `eval` functions as everyone else to get the evaluated MIR constants.

Also this is in preparation for another post-mono check that will be needed for (the current hackfix for) https://github.com/rust-lang/rust/issues/115709: ensuring that all locals are dynamically sized.

I didn't expect this to change diagnostics, but it's just cycle errors that change.

r? `@oli-obk`
This commit is contained in:
bors 2023-09-18 19:41:21 +00:00
commit e9dc753b7b
3 changed files with 5 additions and 5 deletions

View file

@ -204,7 +204,7 @@ fn is_value_unfrozen_raw<'tcx>(
// similar to 2., but with the a frozen variant) (e.g. borrowing // similar to 2., but with the a frozen variant) (e.g. borrowing
// `borrow_interior_mutable_const::enums::AssocConsts::TO_BE_FROZEN_VARIANT`). // `borrow_interior_mutable_const::enums::AssocConsts::TO_BE_FROZEN_VARIANT`).
// I chose this way because unfrozen enums as assoc consts are rare (or, hopefully, none). // I chose this way because unfrozen enums as assoc consts are rare (or, hopefully, none).
err == ErrorHandled::TooGeneric matches!(err, ErrorHandled::TooGeneric(..))
}, },
|val| val.map_or(true, |val| inner(cx, val, ty)), |val| val.map_or(true, |val| inner(cx, val, ty)),
) )
@ -244,8 +244,8 @@ pub fn const_eval_resolve<'tcx>(
}; };
tcx.const_eval_global_id_for_typeck(param_env, cid, span) tcx.const_eval_global_id_for_typeck(param_env, cid, span)
}, },
Ok(None) => Err(ErrorHandled::TooGeneric), Ok(None) => Err(ErrorHandled::TooGeneric(span.unwrap_or(rustc_span::DUMMY_SP))),
Err(err) => Err(ErrorHandled::Reported(err.into())), Err(err) => Err(ErrorHandled::Reported(err.into(), span.unwrap_or(rustc_span::DUMMY_SP))),
} }
} }

View file

@ -4,7 +4,7 @@ error[E0080]: evaluation of `main::{constant#3}` failed
LL | const { &ARR[idx4()] }; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true. LL | const { &ARR[idx4()] }; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true.
| ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4 | ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4
note: erroneous constant used note: erroneous constant encountered
--> $DIR/test.rs:37:5 --> $DIR/test.rs:37:5
| |
LL | const { &ARR[idx4()] }; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true. LL | const { &ARR[idx4()] }; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true.

View file

@ -24,7 +24,7 @@ error[E0080]: evaluation of `main::{constant#3}` failed
LL | const { &ARR[idx4()] }; LL | const { &ARR[idx4()] };
| ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4 | ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4
note: erroneous constant used note: erroneous constant encountered
--> $DIR/indexing_slicing_index.rs:48:5 --> $DIR/indexing_slicing_index.rs:48:5
| |
LL | const { &ARR[idx4()] }; LL | const { &ARR[idx4()] };