Skip to content

Commit ab04526

Browse files
Annotate some more bugs
1 parent 5d0b0d1 commit ab04526

File tree

9 files changed

+24
-26
lines changed

9 files changed

+24
-26
lines changed

compiler/rustc_ast_lowering/src/asm.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
336336
hir::InlineAsmOperand::Const { .. }
337337
| hir::InlineAsmOperand::SymFn { .. }
338338
| hir::InlineAsmOperand::SymStatic { .. } => {
339-
unreachable!()
339+
unreachable!("{op:?} is not a register operand");
340340
}
341341
};
342342

@@ -380,7 +380,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
380380
{
381381
reg_sym.as_str()
382382
} else {
383-
unreachable!();
383+
unreachable!("{op:?} is not a register operand");
384384
}
385385
};
386386

compiler/rustc_ast_lowering/src/item.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
415415
}
416416
ItemKind::MacroDef(MacroDef { body, macro_rules }) => {
417417
let body = P(self.lower_delim_args(body));
418-
let DefKind::Macro(macro_kind) = self.tcx.def_kind(self.local_def_id(id)) else {
419-
unreachable!()
418+
let def_id = self.local_def_id(id);
419+
let def_kind = self.tcx.def_kind(def_id);
420+
let DefKind::Macro(macro_kind) = def_kind else {
421+
unreachable!(
422+
"expected DefKind::Macro for macro item, found {}",
423+
def_kind.descr(def_id.to_def_id())
424+
);
420425
};
421426
let macro_def = self.arena.alloc(ast::MacroDef { body, macro_rules: *macro_rules });
422427
hir::ItemKind::Macro(macro_def, macro_kind)

compiler/rustc_hir_analysis/src/check/wfcheck.rs

-9
Original file line numberDiff line numberDiff line change
@@ -994,15 +994,6 @@ fn check_associated_item(
994994
})
995995
}
996996

997-
fn item_adt_kind(kind: &ItemKind<'_>) -> Option<AdtKind> {
998-
match kind {
999-
ItemKind::Struct(..) => Some(AdtKind::Struct),
1000-
ItemKind::Union(..) => Some(AdtKind::Union),
1001-
ItemKind::Enum(..) => Some(AdtKind::Enum),
1002-
_ => None,
1003-
}
1004-
}
1005-
1006997
/// In a type definition, we check that to ensure that the types of the fields are well-formed.
1007998
fn check_type_defn<'tcx>(
1008999
tcx: TyCtxt<'tcx>,

compiler/rustc_hir_typeck/src/cast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
149149
}
150150
}
151151

152-
#[derive(Copy, Clone)]
152+
#[derive(Copy, Clone, Debug)]
153153
pub enum CastError {
154154
ErrorGuaranteed(ErrorGuaranteed),
155155

compiler/rustc_middle/src/ty/consts/int.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl std::fmt::Debug for ConstInt {
7171
(4, _) => write!(fmt, "_i32")?,
7272
(8, _) => write!(fmt, "_i64")?,
7373
(16, _) => write!(fmt, "_i128")?,
74-
_ => bug!(),
74+
(sz, _) => bug!("unexpected int size i{sz}"),
7575
}
7676
}
7777
Ok(())
@@ -105,7 +105,7 @@ impl std::fmt::Debug for ConstInt {
105105
(4, _) => write!(fmt, "_u32")?,
106106
(8, _) => write!(fmt, "_u64")?,
107107
(16, _) => write!(fmt, "_u128")?,
108-
_ => bug!(),
108+
(sz, _) => bug!("unexpected unsigned int size u{sz}"),
109109
}
110110
}
111111
Ok(())

compiler/rustc_middle/src/ty/util.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -421,13 +421,10 @@ impl<'tcx> TyCtxt<'tcx> {
421421

422422
let impl_args = match *self.type_of(impl_def_id).instantiate_identity().kind() {
423423
ty::Adt(def_, args) if def_ == def => args,
424-
_ => bug!(),
424+
_ => span_bug!(self.def_span(impl_def_id), "expected ADT for self type of `Drop` impl"),
425425
};
426426

427-
let item_args = match *self.type_of(def.did()).instantiate_identity().kind() {
428-
ty::Adt(def_, args) if def_ == def => args,
429-
_ => bug!(),
430-
};
427+
let item_args = ty::GenericArgs::identity_for_item(self, def.did());
431428

432429
let result = iter::zip(item_args, impl_args)
433430
.filter(|&(_, k)| {

compiler/rustc_mir_build/src/build/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -640,15 +640,19 @@ fn construct_error(tcx: TyCtxt<'_>, def_id: LocalDefId, guar: ErrorGuaranteed) -
640640
}
641641
DefKind::Closure if coroutine_kind.is_some() => {
642642
let coroutine_ty = tcx.type_of(def_id).instantiate_identity();
643-
let ty::Coroutine(_, args, _) = coroutine_ty.kind() else { bug!() };
643+
let ty::Coroutine(_, args, _) = coroutine_ty.kind() else {
644+
bug!("expected type of coroutine-like closure to be a coroutine")
645+
};
644646
let args = args.as_coroutine();
645647
let yield_ty = args.yield_ty();
646648
let return_ty = args.return_ty();
647649
(vec![coroutine_ty, args.resume_ty()], return_ty, Some(yield_ty))
648650
}
649651
DefKind::Closure => {
650652
let closure_ty = tcx.type_of(def_id).instantiate_identity();
651-
let ty::Closure(_, args) = closure_ty.kind() else { bug!() };
653+
let ty::Closure(_, args) = closure_ty.kind() else {
654+
bug!("expected type of closure to be a closure")
655+
};
652656
let args = args.as_closure();
653657
let sig = tcx.liberate_late_bound_regions(def_id.to_def_id(), args.sig());
654658
let self_ty = match args.kind() {

compiler/rustc_mir_build/src/thir/cx/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ impl<'tcx> Cx<'tcx> {
798798
hir::ExprKind::Tup(fields) => ExprKind::Tuple { fields: self.mirror_exprs(fields) },
799799

800800
hir::ExprKind::Yield(v, _) => ExprKind::Yield { value: self.mirror_expr(v) },
801-
hir::ExprKind::Err(_) => unreachable!(),
801+
hir::ExprKind::Err(_) => unreachable!("cannot lower a `hir::ExprKind::Err` to THIR"),
802802
};
803803

804804
Expr { temp_lifetime, ty: expr_ty, span: expr.span, kind }

compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,9 @@ impl<'tcx> ConstToPat<'tcx> {
492492
PatKind::Constant { value: mir::Const::Ty(ty::Const::new_value(tcx, cv, ty)) }
493493
}
494494
ty::FnPtr(..) => {
495-
// Valtree construction would never succeed for these, so this is unreachable.
496-
unreachable!()
495+
unreachable!(
496+
"Valtree construction would never succeed for FnPtr, so this is unreachable."
497+
)
497498
}
498499
_ => {
499500
let err = InvalidPattern { span, non_sm_ty: ty };

0 commit comments

Comments
 (0)