Skip to content

Commit 3805bdc

Browse files
committed
invalidate the mir instead
1 parent f449f71 commit 3805bdc

File tree

2 files changed

+29
-26
lines changed
  • compiler
    • rustc_borrowck/src/type_check
    • rustc_mir_build/src/build/expr

2 files changed

+29
-26
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -385,14 +385,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
385385
} else if let Some(static_def_id) = constant.check_static_ptr(tcx) {
386386
let unnormalized_ty = tcx.type_of(static_def_id).instantiate_identity();
387387
let normalized_ty = self.cx.normalize(unnormalized_ty, locations);
388-
let literal_ty = constant.const_.ty().builtin_deref(true).unwrap_or_else(|| {
389-
span_mirbug_and_err!(
390-
self,
391-
constant,
392-
"bad static type {:?}",
393-
constant.const_.ty()
394-
)
395-
});
388+
let literal_ty = constant.const_.ty().builtin_deref(true).unwrap();
396389

397390
if let Err(terr) = self.cx.eq_types(
398391
literal_ty,

compiler/rustc_mir_build/src/build/expr/into.rs

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
406406
vec![destination_block]
407407
};
408408

409+
let mut has_type_error = false;
410+
409411
let operands = operands
410412
.into_iter()
411413
.map(|op| match *op {
@@ -441,6 +443,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
441443
}
442444
}
443445
thir::InlineAsmOperand::Const { value, span } => {
446+
has_type_error |=
447+
matches!(value.ty().kind(), rustc_middle::ty::Error(_));
448+
444449
mir::InlineAsmOperand::Const {
445450
value: Box::new(ConstOperand {
446451
span,
@@ -484,26 +489,31 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
484489
this.cfg.push_assign_unit(block, source_info, destination, this.tcx);
485490
}
486491

487-
this.cfg.terminate(
488-
block,
489-
source_info,
490-
TerminatorKind::InlineAsm {
491-
template,
492-
operands,
493-
options,
494-
line_spans,
495-
targets: targets.into_boxed_slice(),
496-
unwind: if options.contains(InlineAsmOptions::MAY_UNWIND) {
497-
UnwindAction::Continue
498-
} else {
499-
UnwindAction::Unreachable
492+
if has_type_error {
493+
this.cfg.terminate(block, source_info, TerminatorKind::Unreachable);
494+
destination_block.unit()
495+
} else {
496+
this.cfg.terminate(
497+
block,
498+
source_info,
499+
TerminatorKind::InlineAsm {
500+
template,
501+
operands,
502+
options,
503+
line_spans,
504+
targets: targets.into_boxed_slice(),
505+
unwind: if options.contains(InlineAsmOptions::MAY_UNWIND) {
506+
UnwindAction::Continue
507+
} else {
508+
UnwindAction::Unreachable
509+
},
500510
},
501-
},
502-
);
503-
if options.contains(InlineAsmOptions::MAY_UNWIND) {
504-
this.diverge_from(block);
511+
);
512+
if options.contains(InlineAsmOptions::MAY_UNWIND) {
513+
this.diverge_from(block);
514+
}
515+
destination_block.unit()
505516
}
506-
destination_block.unit()
507517
}
508518

509519
// These cases don't actually need a destination

0 commit comments

Comments
 (0)