diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 7a1dc5ebe0f04..6983cda6ddf3b 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -385,14 +385,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> { } else if let Some(static_def_id) = constant.check_static_ptr(tcx) { let unnormalized_ty = tcx.type_of(static_def_id).instantiate_identity(); let normalized_ty = self.cx.normalize(unnormalized_ty, locations); - let literal_ty = constant.const_.ty().builtin_deref(true).unwrap_or_else(|| { - span_mirbug_and_err!( - self, - constant, - "bad static type {:?}", - constant.const_.ty() - ) - }); + let literal_ty = constant.const_.ty().builtin_deref(true).unwrap(); if let Err(terr) = self.cx.eq_types( literal_ty, diff --git a/compiler/rustc_mir_build/src/build/expr/into.rs b/compiler/rustc_mir_build/src/build/expr/into.rs index 1c805ed20cc36..83b913bf4f884 100644 --- a/compiler/rustc_mir_build/src/build/expr/into.rs +++ b/compiler/rustc_mir_build/src/build/expr/into.rs @@ -406,6 +406,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { vec![destination_block] }; + let mut has_type_error = false; + let operands = operands .into_iter() .map(|op| match *op { @@ -441,6 +443,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } } thir::InlineAsmOperand::Const { value, span } => { + has_type_error |= + matches!(value.ty().kind(), rustc_middle::ty::Error(_)); + mir::InlineAsmOperand::Const { value: Box::new(ConstOperand { span, @@ -484,26 +489,31 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { this.cfg.push_assign_unit(block, source_info, destination, this.tcx); } - this.cfg.terminate( - block, - source_info, - TerminatorKind::InlineAsm { - template, - operands, - options, - line_spans, - targets: targets.into_boxed_slice(), - unwind: if options.contains(InlineAsmOptions::MAY_UNWIND) { - UnwindAction::Continue - } else { - UnwindAction::Unreachable + if has_type_error { + this.cfg.terminate(block, source_info, TerminatorKind::Unreachable); + destination_block.unit() + } else { + this.cfg.terminate( + block, + source_info, + TerminatorKind::InlineAsm { + template, + operands, + options, + line_spans, + targets: targets.into_boxed_slice(), + unwind: if options.contains(InlineAsmOptions::MAY_UNWIND) { + UnwindAction::Continue + } else { + UnwindAction::Unreachable + }, }, - }, - ); - if options.contains(InlineAsmOptions::MAY_UNWIND) { - this.diverge_from(block); + ); + if options.contains(InlineAsmOptions::MAY_UNWIND) { + this.diverge_from(block); + } + destination_block.unit() } - destination_block.unit() } // These cases don't actually need a destination