mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-28 03:24:11 +00:00
Print a backtrace in const eval if interrupted
Demo:
```rust
#![feature(const_eval_limit)]
#![const_eval_limit = "0"]
const OW: u64 = {
let mut res: u64 = 0;
let mut i = 0;
while i < u64::MAX {
res = res.wrapping_add(i);
i += 1;
}
res
};
fn main() {
println!("{}", OW);
}
```
```
╭ ➜ ben@archlinux:~/rust
╰ ➤ rustc +stage1 spin.rs
^Cerror[E0080]: evaluation of constant value failed
--> spin.rs:8:33
|
8 | res = res.wrapping_add(i);
| ^ Compilation was interrupted
note: erroneous constant used
--> spin.rs:15:20
|
15 | println!("{}", OW);
| ^^
note: erroneous constant used
--> spin.rs:15:20
|
15 | println!("{}", OW);
| ^^
|
= note: this note originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to previous error
For more information about this error, try `rustc --explain E0080`.
```
68 lines
2.2 KiB
Rust
68 lines
2.2 KiB
Rust
/*!
|
|
|
|
Rust MIR: a lowered representation of Rust.
|
|
|
|
*/
|
|
|
|
#![allow(internal_features)]
|
|
#![allow(rustc::diagnostic_outside_of_impl)]
|
|
#![feature(rustdoc_internals)]
|
|
#![doc(rust_logo)]
|
|
#![feature(assert_matches)]
|
|
#![feature(box_patterns)]
|
|
#![feature(decl_macro)]
|
|
#![feature(generic_nonzero)]
|
|
#![feature(let_chains)]
|
|
#![feature(slice_ptr_get)]
|
|
#![feature(strict_provenance)]
|
|
#![feature(never_type)]
|
|
#![feature(trait_alias)]
|
|
#![feature(try_blocks)]
|
|
#![feature(yeet_expr)]
|
|
#![feature(if_let_guard)]
|
|
|
|
#[macro_use]
|
|
extern crate tracing;
|
|
#[macro_use]
|
|
extern crate rustc_middle;
|
|
|
|
pub mod const_eval;
|
|
mod errors;
|
|
pub mod interpret;
|
|
pub mod transform;
|
|
pub mod util;
|
|
|
|
use std::sync::atomic::AtomicBool;
|
|
|
|
pub use errors::ReportErrorExt;
|
|
|
|
use rustc_middle::{ty, util::Providers};
|
|
|
|
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
|
|
|
|
pub fn provide(providers: &mut Providers) {
|
|
const_eval::provide(providers);
|
|
providers.tag_for_variant = const_eval::tag_for_variant_provider;
|
|
providers.eval_to_const_value_raw = const_eval::eval_to_const_value_raw_provider;
|
|
providers.eval_to_allocation_raw = const_eval::eval_to_allocation_raw_provider;
|
|
providers.eval_static_initializer = const_eval::eval_static_initializer_provider;
|
|
providers.hooks.const_caller_location = util::caller_location::const_caller_location_provider;
|
|
providers.eval_to_valtree = |tcx, param_env_and_value| {
|
|
let (param_env, raw) = param_env_and_value.into_parts();
|
|
const_eval::eval_to_valtree(tcx, param_env, raw)
|
|
};
|
|
providers.hooks.try_destructure_mir_constant_for_user_output =
|
|
const_eval::try_destructure_mir_constant_for_user_output;
|
|
providers.valtree_to_const_val = |tcx, (ty, valtree)| {
|
|
const_eval::valtree_to_const_value(tcx, ty::ParamEnv::empty().and(ty), valtree)
|
|
};
|
|
providers.check_validity_requirement = |tcx, (init_kind, param_env_and_ty)| {
|
|
util::check_validity_requirement(tcx, init_kind, param_env_and_ty)
|
|
};
|
|
}
|
|
|
|
/// `rustc_driver::main` installs a handler that will set this to `true` if
|
|
/// the compiler has been sent a request to shut down, such as by a Ctrl-C.
|
|
/// This static lives here because it is only read by the interpreter.
|
|
pub static CTRL_C_RECEIVED: AtomicBool = AtomicBool::new(false);
|