From 77dae2d25d900a8e7493c548498cdc94bdcee3d9 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 6 Feb 2022 12:16:49 -0800 Subject: [PATCH] skip const eval if we have an error in borrowck --- .../src/const_eval/eval_queries.rs | 3 +++ .../src/interpret/eval_context.rs | 6 +++++- compiler/rustc_middle/src/ty/context.rs | 15 ++++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs index 9dc34260de7..7235b8416ad 100644 --- a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs +++ b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs @@ -287,6 +287,9 @@ pub fn eval_to_allocation_raw_provider<'tcx>( if let Some(error_reported) = tcx.typeck_opt_const_arg(def).tainted_by_errors { return Err(ErrorHandled::Reported(error_reported)); } + if tcx.mir_borrowck_opt_const_arg(def).tainted_by_errors { + return Err(ErrorHandled::Reported(ErrorReported {})); + } } if !tcx.is_mir_available(def.did) { tcx.sess.delay_span_bug( diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs index 0a8112da2ab..00c066a2851 100644 --- a/compiler/rustc_const_eval/src/interpret/eval_context.rs +++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs @@ -514,10 +514,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { if let Some(def) = def.as_local() { if self.tcx.has_typeck_results(def.did) { if let Some(error_reported) = self.tcx.typeck_opt_const_arg(def).tainted_by_errors { - throw_inval!(AlreadyReported(error_reported)) + throw_inval!(AlreadyReported(error_reported)); + } + if self.tcx.mir_borrowck_opt_const_arg(def).tainted_by_errors { + throw_inval!(AlreadyReported(rustc_errors::ErrorReported {})); } } } + trace!("load mir(instance={:?}, promoted={:?})", instance, promoted); if let Some(promoted) = promoted { return Ok(&self.tcx.promoted_mir_opt_const_arg(def)[promoted]); diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index a119655a90b..4a3efb5c1b8 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -8,7 +8,9 @@ use crate::lint::{struct_lint_level, LintDiagnosticBuilder, LintLevelSource}; use crate::middle::resolve_lifetime::{self, LifetimeScopeForPath}; use crate::middle::stability; use crate::mir::interpret::{self, Allocation, ConstValue, Scalar}; -use crate::mir::{Body, Field, Local, Place, PlaceElem, ProjectionKind, Promoted}; +use crate::mir::{ + Body, BorrowCheckResult, Field, Local, Place, PlaceElem, ProjectionKind, Promoted, +}; use crate::thir::Thir; use crate::traits; use crate::ty::query::{self, TyCtxtAt}; @@ -1061,6 +1063,17 @@ impl<'tcx> TyCtxt<'tcx> { } } + pub fn mir_borrowck_opt_const_arg( + self, + def: ty::WithOptConstParam, + ) -> &'tcx BorrowCheckResult<'tcx> { + if let Some(param_did) = def.const_param_did { + self.mir_borrowck_const_arg((def.did, param_did)) + } else { + self.mir_borrowck(def.did) + } + } + pub fn alloc_steal_thir(self, thir: Thir<'tcx>) -> &'tcx Steal> { self.arena.alloc(Steal::new(thir)) }