Skip to content

Commit 77dae2d

Browse files
skip const eval if we have an error in borrowck
1 parent 4ad272b commit 77dae2d

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
287287
if let Some(error_reported) = tcx.typeck_opt_const_arg(def).tainted_by_errors {
288288
return Err(ErrorHandled::Reported(error_reported));
289289
}
290+
if tcx.mir_borrowck_opt_const_arg(def).tainted_by_errors {
291+
return Err(ErrorHandled::Reported(ErrorReported {}));
292+
}
290293
}
291294
if !tcx.is_mir_available(def.did) {
292295
tcx.sess.delay_span_bug(

compiler/rustc_const_eval/src/interpret/eval_context.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,10 +514,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
514514
if let Some(def) = def.as_local() {
515515
if self.tcx.has_typeck_results(def.did) {
516516
if let Some(error_reported) = self.tcx.typeck_opt_const_arg(def).tainted_by_errors {
517-
throw_inval!(AlreadyReported(error_reported))
517+
throw_inval!(AlreadyReported(error_reported));
518+
}
519+
if self.tcx.mir_borrowck_opt_const_arg(def).tainted_by_errors {
520+
throw_inval!(AlreadyReported(rustc_errors::ErrorReported {}));
518521
}
519522
}
520523
}
524+
521525
trace!("load mir(instance={:?}, promoted={:?})", instance, promoted);
522526
if let Some(promoted) = promoted {
523527
return Ok(&self.tcx.promoted_mir_opt_const_arg(def)[promoted]);

compiler/rustc_middle/src/ty/context.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ use crate::lint::{struct_lint_level, LintDiagnosticBuilder, LintLevelSource};
88
use crate::middle::resolve_lifetime::{self, LifetimeScopeForPath};
99
use crate::middle::stability;
1010
use crate::mir::interpret::{self, Allocation, ConstValue, Scalar};
11-
use crate::mir::{Body, Field, Local, Place, PlaceElem, ProjectionKind, Promoted};
11+
use crate::mir::{
12+
Body, BorrowCheckResult, Field, Local, Place, PlaceElem, ProjectionKind, Promoted,
13+
};
1214
use crate::thir::Thir;
1315
use crate::traits;
1416
use crate::ty::query::{self, TyCtxtAt};
@@ -1061,6 +1063,17 @@ impl<'tcx> TyCtxt<'tcx> {
10611063
}
10621064
}
10631065

1066+
pub fn mir_borrowck_opt_const_arg(
1067+
self,
1068+
def: ty::WithOptConstParam<LocalDefId>,
1069+
) -> &'tcx BorrowCheckResult<'tcx> {
1070+
if let Some(param_did) = def.const_param_did {
1071+
self.mir_borrowck_const_arg((def.did, param_did))
1072+
} else {
1073+
self.mir_borrowck(def.did)
1074+
}
1075+
}
1076+
10641077
pub fn alloc_steal_thir(self, thir: Thir<'tcx>) -> &'tcx Steal<Thir<'tcx>> {
10651078
self.arena.alloc(Steal::new(thir))
10661079
}

0 commit comments

Comments
 (0)