1
Fork 0

Rollup merge of #118962 - compiler-errors:bugs, r=TaKO8Ki

Annotate some bugs

Gives a semi-helpful message to some `bug!()`/`unreachable!()`/`panic!()`. This also works around some other bugs/panics/etc that weren't needed, and also makes some of them into `span_bug!`s so they also have a useful span.

Note to reviewer: best to disable whitespace when comparing for some cases where indentation changed.

cc #118955
This commit is contained in:
Matthias Krüger 2023-12-15 15:53:51 +01:00 committed by GitHub
commit 2f8867e03c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
41 changed files with 319 additions and 223 deletions

View file

@ -640,7 +640,9 @@ fn construct_error(tcx: TyCtxt<'_>, def_id: LocalDefId, guar: ErrorGuaranteed) -
}
DefKind::Closure if coroutine_kind.is_some() => {
let coroutine_ty = tcx.type_of(def_id).instantiate_identity();
let ty::Coroutine(_, args, _) = coroutine_ty.kind() else { bug!() };
let ty::Coroutine(_, args, _) = coroutine_ty.kind() else {
bug!("expected type of coroutine-like closure to be a coroutine")
};
let args = args.as_coroutine();
let yield_ty = args.yield_ty();
let return_ty = args.return_ty();
@ -648,7 +650,9 @@ fn construct_error(tcx: TyCtxt<'_>, def_id: LocalDefId, guar: ErrorGuaranteed) -
}
DefKind::Closure => {
let closure_ty = tcx.type_of(def_id).instantiate_identity();
let ty::Closure(_, args) = closure_ty.kind() else { bug!() };
let ty::Closure(_, args) = closure_ty.kind() else {
bug!("expected type of closure to be a closure")
};
let args = args.as_closure();
let sig = tcx.liberate_late_bound_regions(def_id.to_def_id(), args.sig());
let self_ty = match args.kind() {

View file

@ -782,7 +782,7 @@ impl<'tcx> Cx<'tcx> {
hir::ExprKind::Tup(fields) => ExprKind::Tuple { fields: self.mirror_exprs(fields) },
hir::ExprKind::Yield(v, _) => ExprKind::Yield { value: self.mirror_expr(v) },
hir::ExprKind::Err(_) => unreachable!(),
hir::ExprKind::Err(_) => unreachable!("cannot lower a `hir::ExprKind::Err` to THIR"),
};
Expr { temp_lifetime, ty: expr_ty, span: expr.span, kind }

View file

@ -492,8 +492,9 @@ impl<'tcx> ConstToPat<'tcx> {
PatKind::Constant { value: mir::Const::Ty(ty::Const::new_value(tcx, cv, ty)) }
}
ty::FnPtr(..) => {
// Valtree construction would never succeed for these, so this is unreachable.
unreachable!()
unreachable!(
"Valtree construction would never succeed for FnPtr, so this is unreachable."
)
}
_ => {
let err = InvalidPattern { span, non_sm_ty: ty };