Skip to content

Commit a431174

Browse files
add tainted_by_errors to mir::Body
1 parent 29c2bb5 commit a431174

File tree

10 files changed

+37
-23
lines changed

10 files changed

+37
-23
lines changed

compiler/rustc_const_eval/src/transform/check_consts/check.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl<'mir, 'tcx> Qualifs<'mir, 'tcx> {
120120
fn in_return_place(
121121
&mut self,
122122
ccx: &'mir ConstCx<'mir, 'tcx>,
123-
error_occured: Option<ErrorReported>,
123+
tainted_by_errors: Option<ErrorReported>,
124124
) -> ConstQualifs {
125125
// Find the `Return` terminator if one exists.
126126
//
@@ -134,7 +134,9 @@ impl<'mir, 'tcx> Qualifs<'mir, 'tcx> {
134134
.map(|(bb, _)| bb);
135135

136136
let return_block = match return_block {
137-
None => return qualifs::in_any_value_of_ty(ccx, ccx.body.return_ty(), error_occured),
137+
None => {
138+
return qualifs::in_any_value_of_ty(ccx, ccx.body.return_ty(), tainted_by_errors);
139+
}
138140
Some(bb) => bb,
139141
};
140142

@@ -166,7 +168,7 @@ impl<'mir, 'tcx> Qualifs<'mir, 'tcx> {
166168
needs_non_const_drop: self.needs_non_const_drop(ccx, RETURN_PLACE, return_loc),
167169
has_mut_interior: self.has_mut_interior(ccx, RETURN_PLACE, return_loc),
168170
custom_eq,
169-
error_occured,
171+
tainted_by_errors,
170172
}
171173
}
172174
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ use super::ConstCx;
1717
pub fn in_any_value_of_ty<'tcx>(
1818
cx: &ConstCx<'_, 'tcx>,
1919
ty: Ty<'tcx>,
20-
error_occured: Option<ErrorReported>,
20+
tainted_by_errors: Option<ErrorReported>,
2121
) -> ConstQualifs {
2222
ConstQualifs {
2323
has_mut_interior: HasMutInterior::in_any_value_of_ty(cx, ty),
2424
needs_drop: NeedsDrop::in_any_value_of_ty(cx, ty),
2525
needs_non_const_drop: NeedsNonConstDrop::in_any_value_of_ty(cx, ty),
2626
custom_eq: CustomEq::in_any_value_of_ty(cx, ty),
27-
error_occured,
27+
tainted_by_errors,
2828
}
2929
}
3030

compiler/rustc_const_eval/src/transform/promote_consts.rs

+1
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,7 @@ pub fn promote_candidates<'tcx>(
974974
vec![],
975975
body.span,
976976
body.generator_kind(),
977+
body.tainted_by_errors,
977978
);
978979

979980
let promoter = Promoter {

compiler/rustc_middle/src/mir/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::ty::subst::{Subst, SubstsRef};
1313
use crate::ty::{self, List, Ty, TyCtxt};
1414
use crate::ty::{AdtDef, InstanceDef, Region, ScalarInt, UserTypeAnnotationIndex};
1515

16+
use rustc_errors::ErrorReported;
1617
use rustc_hir::def::{CtorKind, Namespace};
1718
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX};
1819
use rustc_hir::{self, GeneratorKind};
@@ -284,6 +285,8 @@ pub struct Body<'tcx> {
284285

285286
predecessor_cache: PredecessorCache,
286287
is_cyclic: GraphIsCyclicCache,
288+
289+
pub tainted_by_errors: Option<ErrorReported>,
287290
}
288291

289292
impl<'tcx> Body<'tcx> {
@@ -297,6 +300,7 @@ impl<'tcx> Body<'tcx> {
297300
var_debug_info: Vec<VarDebugInfo<'tcx>>,
298301
span: Span,
299302
generator_kind: Option<GeneratorKind>,
303+
tainted_by_errors: Option<ErrorReported>,
300304
) -> Self {
301305
// We need `arg_count` locals, and one for the return place.
302306
assert!(
@@ -329,6 +333,7 @@ impl<'tcx> Body<'tcx> {
329333
is_polymorphic: false,
330334
predecessor_cache: PredecessorCache::new(),
331335
is_cyclic: GraphIsCyclicCache::new(),
336+
tainted_by_errors,
332337
};
333338
body.is_polymorphic = body.has_param_types_or_consts();
334339
body
@@ -356,6 +361,7 @@ impl<'tcx> Body<'tcx> {
356361
is_polymorphic: false,
357362
predecessor_cache: PredecessorCache::new(),
358363
is_cyclic: GraphIsCyclicCache::new(),
364+
tainted_by_errors: None,
359365
};
360366
body.is_polymorphic = body.has_param_types_or_consts();
361367
body

compiler/rustc_middle/src/mir/query.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ pub struct ConstQualifs {
228228
pub needs_drop: bool,
229229
pub needs_non_const_drop: bool,
230230
pub custom_eq: bool,
231-
pub error_occured: Option<ErrorReported>,
231+
pub tainted_by_errors: Option<ErrorReported>,
232232
}
233233

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

compiler/rustc_middle/src/ty/structural_impls.rs

+1
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ TrivialTypeFoldableAndLiftImpls! {
253253
crate::ty::UniverseIndex,
254254
crate::ty::Variance,
255255
::rustc_span::Span,
256+
::rustc_errors::ErrorReported,
256257
}
257258

258259
///////////////////////////////////////////////////////////////////////////

compiler/rustc_mir_build/src/build/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_
104104
let span_with_body = span_with_body.unwrap_or_else(|| tcx.hir().span(id));
105105

106106
tcx.infer_ctxt().enter(|infcx| {
107-
let body = if let Some(ErrorReported) = typeck_results.tainted_by_errors {
108-
build::construct_error(&infcx, def, id, body_id, body_owner_kind)
107+
let body = if let Some(error_reported) = typeck_results.tainted_by_errors {
108+
build::construct_error(&infcx, def, id, body_id, body_owner_kind, error_reported)
109109
} else if body_owner_kind.is_fn_or_closure() {
110110
// fetch the fully liberated fn signature (that is, all bound
111111
// types/lifetimes replaced)
@@ -715,6 +715,7 @@ fn construct_error<'a, 'tcx>(
715715
hir_id: hir::HirId,
716716
body_id: hir::BodyId,
717717
body_owner_kind: hir::BodyOwnerKind,
718+
err: ErrorReported,
718719
) -> Body<'tcx> {
719720
let tcx = infcx.tcx;
720721
let span = tcx.hir().span(hir_id);
@@ -769,6 +770,7 @@ fn construct_error<'a, 'tcx>(
769770
vec![],
770771
span,
771772
generator_kind,
773+
Some(err),
772774
);
773775
body.generator.as_mut().map(|gen| gen.yield_ty = Some(ty));
774776
body
@@ -857,6 +859,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
857859
self.var_debug_info,
858860
self.fn_span,
859861
self.generator_kind,
862+
self.typeck_results.tainted_by_errors,
860863
)
861864
}
862865

compiler/rustc_mir_transform/src/const_prop.rs

+1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
145145
Default::default(),
146146
body.span,
147147
body.generator_kind(),
148+
body.tainted_by_errors,
148149
);
149150

150151
// FIXME(oli-obk, eddyb) Optimize locals (or even local paths) to hold

compiler/rustc_mir_transform/src/lib.rs

+13-15
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,11 @@ fn mir_promoted<'tcx>(
252252
// Ensure that we compute the `mir_const_qualif` for constants at
253253
// this point, before we steal the mir-const result.
254254
// Also this means promotion can rely on all const checks having been done.
255-
let _ = tcx.mir_const_qualif_opt_const_arg(def);
255+
let const_qualifs = tcx.mir_const_qualif_opt_const_arg(def);
256256
let mut body = tcx.mir_const(def).steal();
257+
if let Some(error_reported) = const_qualifs.tainted_by_errors {
258+
body.tainted_by_errors = Some(error_reported);
259+
}
257260

258261
let mut required_consts = Vec::new();
259262
let mut required_consts_visitor = RequiredConstsVisitor::new(&mut required_consts);
@@ -358,13 +361,7 @@ fn mir_drops_elaborated_and_const_checked<'tcx>(
358361
return tcx.mir_drops_elaborated_and_const_checked(def);
359362
}
360363

361-
// (Mir-)Borrowck uses `mir_promoted`, so we have to force it to
362-
// execute before we can steal.
363-
if let Some(param_did) = def.const_param_did {
364-
tcx.ensure().mir_borrowck_const_arg((def.did, param_did));
365-
} else {
366-
tcx.ensure().mir_borrowck(def.did);
367-
}
364+
let mir_borrowck = tcx.mir_borrowck_opt_const_arg(def);
368365

369366
let is_fn_like = tcx.hir().get_by_def_id(def.did).fn_kind().is_some();
370367
if is_fn_like {
@@ -379,6 +376,9 @@ fn mir_drops_elaborated_and_const_checked<'tcx>(
379376

380377
let (body, _) = tcx.mir_promoted(def);
381378
let mut body = body.steal();
379+
if let Some(error_reported) = mir_borrowck.tainted_by_errors {
380+
body.tainted_by_errors = Some(error_reported);
381+
}
382382

383383
// IMPORTANT
384384
pm::run_passes(tcx, &mut body, &[&remove_false_edges::RemoveFalseEdges]);
@@ -544,15 +544,13 @@ fn promoted_mir<'tcx>(
544544
return tcx.arena.alloc(IndexVec::new());
545545
}
546546

547-
if let Some(param_did) = def.const_param_did {
548-
tcx.ensure().mir_borrowck_const_arg((def.did, param_did));
549-
} else {
550-
tcx.ensure().mir_borrowck(def.did);
551-
}
552-
let (_, promoted) = tcx.mir_promoted(def);
553-
let mut promoted = promoted.steal();
547+
let tainted_by_errors = tcx.mir_borrowck_opt_const_arg(def).tainted_by_errors;
548+
let mut promoted = tcx.mir_promoted(def).1.steal();
554549

555550
for body in &mut promoted {
551+
if let Some(error_reported) = tainted_by_errors {
552+
body.tainted_by_errors = Some(error_reported);
553+
}
556554
run_post_borrowck_cleanup_passes(tcx, body);
557555
}
558556

compiler/rustc_mir_transform/src/shim.rs

+2
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ fn new_body<'tcx>(
235235
vec![],
236236
span,
237237
None,
238+
// FIXME(compiler-errors): is this correct?
239+
None,
238240
)
239241
}
240242

0 commit comments

Comments
 (0)