add error_occured field to ConstQualifs, fix #76064

This commit is contained in:
Vishnunarayan K I 2020-11-06 20:46:38 +05:30
parent 7f5a42b073
commit 8bce9af78c
6 changed files with 30 additions and 6 deletions

View File

@ -233,14 +233,15 @@ pub struct BorrowCheckResult<'tcx> {
/// The result of the `mir_const_qualif` query.
///
/// Each field corresponds to an implementer of the `Qualif` trait in
/// `librustc_mir/transform/check_consts/qualifs.rs`. See that file for more information on each
/// Each field (except `error_occured`) corresponds to an implementer of the `Qualif` trait in
/// `rustc_mir/src/transform/check_consts/qualifs.rs`. See that file for more information on each
/// `Qualif`.
#[derive(Clone, Copy, Debug, Default, TyEncodable, TyDecodable, HashStable)]
pub struct ConstQualifs {
pub has_mut_interior: bool,
pub needs_drop: bool,
pub custom_eq: bool,
pub error_occured: bool,
}
/// After we borrow check a closure, we are left with various

View File

@ -9,6 +9,7 @@ use crate::interpret::{
use rustc_hir::def::DefKind;
use rustc_middle::mir;
use rustc_middle::mir::interpret::ErrorHandled;
use rustc_errors::ErrorReported;
use rustc_middle::traits::Reveal;
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::{self, subst::Subst, TyCtxt};
@ -274,6 +275,10 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
return Err(ErrorHandled::Reported(error_reported));
}
}
let qualif = tcx.mir_const_qualif_opt_const_arg(def);
if qualif.error_occured {
return Err(ErrorHandled::Reported(ErrorReported {}));
}
}
let is_static = tcx.is_static(def.did);

View File

@ -9,11 +9,12 @@ use rustc_trait_selection::traits;
use super::ConstCx;
pub fn in_any_value_of_ty(cx: &ConstCx<'_, 'tcx>, ty: Ty<'tcx>) -> ConstQualifs {
pub fn in_any_value_of_ty(cx: &ConstCx<'_, 'tcx>, ty: Ty<'tcx>, error_occured: bool) -> ConstQualifs {
ConstQualifs {
has_mut_interior: HasMutInterior::in_any_value_of_ty(cx, ty),
needs_drop: NeedsDrop::in_any_value_of_ty(cx, ty),
custom_eq: CustomEq::in_any_value_of_ty(cx, ty),
error_occured,
}
}

View File

@ -123,7 +123,7 @@ impl Qualifs<'mir, 'tcx> {
has_mut_interior.get().contains(local) || self.indirectly_mutable(ccx, local, location)
}
fn in_return_place(&mut self, ccx: &'mir ConstCx<'mir, 'tcx>) -> ConstQualifs {
fn in_return_place(&mut self, ccx: &'mir ConstCx<'mir, 'tcx>, error_occured: bool) -> ConstQualifs {
// Find the `Return` terminator if one exists.
//
// If no `Return` terminator exists, this MIR is divergent. Just return the conservative
@ -139,7 +139,7 @@ impl Qualifs<'mir, 'tcx> {
.map(|(bb, _)| bb);
let return_block = match return_block {
None => return qualifs::in_any_value_of_ty(ccx, ccx.body.return_ty()),
None => return qualifs::in_any_value_of_ty(ccx, ccx.body.return_ty(), error_occured),
Some(bb) => bb,
};
@ -170,6 +170,7 @@ impl Qualifs<'mir, 'tcx> {
needs_drop: self.needs_drop(ccx, RETURN_PLACE, return_loc),
has_mut_interior: self.has_mut_interior(ccx, RETURN_PLACE, return_loc),
custom_eq,
error_occured,
}
}
}
@ -276,7 +277,7 @@ impl Validator<'mir, 'tcx> {
}
pub fn qualifs_in_return_place(&mut self) -> ConstQualifs {
self.qualifs.in_return_place(self.ccx)
self.qualifs.in_return_place(self.ccx, self.error_emitted)
}
/// Emits an error if an expression cannot be evaluated in the current context.

View File

@ -0,0 +1,3 @@
struct Bug([u8; panic!(1)]); //~ ERROR panicking in constants is unstable
fn main() {}

View File

@ -0,0 +1,13 @@
error[E0658]: panicking in constants is unstable
--> $DIR/issue-76064.rs:1:17
|
LL | struct Bug([u8; panic!(1)]);
| ^^^^^^^^^
|
= note: see issue #51999 <https://github.com/rust-lang/rust/issues/51999> for more information
= help: add `#![feature(const_panic)]` to the crate attributes to enable
= note: this error originates in a macro (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 E0658`.