Skip to content

Commit 8bce9af

Browse files
committed
add error_occured field to ConstQualifs, fix #76064
1 parent 7f5a42b commit 8bce9af

File tree

6 files changed

+30
-6
lines changed

6 files changed

+30
-6
lines changed

compiler/rustc_middle/src/mir/query.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,15 @@ pub struct BorrowCheckResult<'tcx> {
233233

234234
/// The result of the `mir_const_qualif` query.
235235
///
236-
/// Each field corresponds to an implementer of the `Qualif` trait in
237-
/// `librustc_mir/transform/check_consts/qualifs.rs`. See that file for more information on each
236+
/// Each field (except `error_occured`) corresponds to an implementer of the `Qualif` trait in
237+
/// `rustc_mir/src/transform/check_consts/qualifs.rs`. See that file for more information on each
238238
/// `Qualif`.
239239
#[derive(Clone, Copy, Debug, Default, TyEncodable, TyDecodable, HashStable)]
240240
pub struct ConstQualifs {
241241
pub has_mut_interior: bool,
242242
pub needs_drop: bool,
243243
pub custom_eq: bool,
244+
pub error_occured: bool,
244245
}
245246

246247
/// After we borrow check a closure, we are left with various

compiler/rustc_mir/src/const_eval/eval_queries.rs

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::interpret::{
99
use rustc_hir::def::DefKind;
1010
use rustc_middle::mir;
1111
use rustc_middle::mir::interpret::ErrorHandled;
12+
use rustc_errors::ErrorReported;
1213
use rustc_middle::traits::Reveal;
1314
use rustc_middle::ty::print::with_no_trimmed_paths;
1415
use rustc_middle::ty::{self, subst::Subst, TyCtxt};
@@ -274,6 +275,10 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
274275
return Err(ErrorHandled::Reported(error_reported));
275276
}
276277
}
278+
let qualif = tcx.mir_const_qualif_opt_const_arg(def);
279+
if qualif.error_occured {
280+
return Err(ErrorHandled::Reported(ErrorReported {}));
281+
}
277282
}
278283

279284
let is_static = tcx.is_static(def.did);

compiler/rustc_mir/src/transform/check_consts/qualifs.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ use rustc_trait_selection::traits;
99

1010
use super::ConstCx;
1111

12-
pub fn in_any_value_of_ty(cx: &ConstCx<'_, 'tcx>, ty: Ty<'tcx>) -> ConstQualifs {
12+
pub fn in_any_value_of_ty(cx: &ConstCx<'_, 'tcx>, ty: Ty<'tcx>, error_occured: bool) -> ConstQualifs {
1313
ConstQualifs {
1414
has_mut_interior: HasMutInterior::in_any_value_of_ty(cx, ty),
1515
needs_drop: NeedsDrop::in_any_value_of_ty(cx, ty),
1616
custom_eq: CustomEq::in_any_value_of_ty(cx, ty),
17+
error_occured,
1718
}
1819
}
1920

compiler/rustc_mir/src/transform/check_consts/validation.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl Qualifs<'mir, 'tcx> {
123123
has_mut_interior.get().contains(local) || self.indirectly_mutable(ccx, local, location)
124124
}
125125

126-
fn in_return_place(&mut self, ccx: &'mir ConstCx<'mir, 'tcx>) -> ConstQualifs {
126+
fn in_return_place(&mut self, ccx: &'mir ConstCx<'mir, 'tcx>, error_occured: bool) -> ConstQualifs {
127127
// Find the `Return` terminator if one exists.
128128
//
129129
// If no `Return` terminator exists, this MIR is divergent. Just return the conservative
@@ -139,7 +139,7 @@ impl Qualifs<'mir, 'tcx> {
139139
.map(|(bb, _)| bb);
140140

141141
let return_block = match return_block {
142-
None => return qualifs::in_any_value_of_ty(ccx, ccx.body.return_ty()),
142+
None => return qualifs::in_any_value_of_ty(ccx, ccx.body.return_ty(), error_occured),
143143
Some(bb) => bb,
144144
};
145145

@@ -170,6 +170,7 @@ impl Qualifs<'mir, 'tcx> {
170170
needs_drop: self.needs_drop(ccx, RETURN_PLACE, return_loc),
171171
has_mut_interior: self.has_mut_interior(ccx, RETURN_PLACE, return_loc),
172172
custom_eq,
173+
error_occured,
173174
}
174175
}
175176
}
@@ -276,7 +277,7 @@ impl Validator<'mir, 'tcx> {
276277
}
277278

278279
pub fn qualifs_in_return_place(&mut self) -> ConstQualifs {
279-
self.qualifs.in_return_place(self.ccx)
280+
self.qualifs.in_return_place(self.ccx, self.error_emitted)
280281
}
281282

282283
/// Emits an error if an expression cannot be evaluated in the current context.

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

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

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

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0658]: panicking in constants is unstable
2+
--> $DIR/issue-76064.rs:1:17
3+
|
4+
LL | struct Bug([u8; panic!(1)]);
5+
| ^^^^^^^^^
6+
|
7+
= note: see issue #51999 <https://github.com/rust-lang/rust/issues/51999> for more information
8+
= help: add `#![feature(const_panic)]` to the crate attributes to enable
9+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
10+
11+
error: aborting due to previous error
12+
13+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)