Skip to content

Commit

Permalink
Annotate some more bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Dec 15, 2023
1 parent 70b9dad commit 1cc0d7d
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 26 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hir::InlineAsmOperand::Const { .. }
| hir::InlineAsmOperand::SymFn { .. }
| hir::InlineAsmOperand::SymStatic { .. } => {
unreachable!()
unreachable!("{op:?} is not a register operand");
}
};

Expand Down Expand Up @@ -380,7 +380,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
{
reg_sym.as_str()
} else {
unreachable!();
unreachable!("{op:?} is not a register operand");
}
};

Expand Down
9 changes: 7 additions & 2 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
ItemKind::MacroDef(MacroDef { body, macro_rules }) => {
let body = P(self.lower_delim_args(body));
let DefKind::Macro(macro_kind) = self.tcx.def_kind(self.local_def_id(id)) else {
unreachable!()
let def_id = self.local_def_id(id);
let def_kind = self.tcx.def_kind(def_id);
let DefKind::Macro(macro_kind) = def_kind else {
unreachable!(
"expected DefKind::Macro for macro item, found {}",
def_kind.descr(def_id.to_def_id())
);
};
let macro_def = self.arena.alloc(ast::MacroDef { body, macro_rules: *macro_rules });
hir::ItemKind::Macro(macro_def, macro_kind)
Expand Down
9 changes: 0 additions & 9 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -994,15 +994,6 @@ fn check_associated_item(
})
}

fn item_adt_kind(kind: &ItemKind<'_>) -> Option<AdtKind> {
match kind {
ItemKind::Struct(..) => Some(AdtKind::Struct),
ItemKind::Union(..) => Some(AdtKind::Union),
ItemKind::Enum(..) => Some(AdtKind::Enum),
_ => None,
}
}

/// In a type definition, we check that to ensure that the types of the fields are well-formed.
fn check_type_defn<'tcx>(
tcx: TyCtxt<'tcx>,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}

#[derive(Copy, Clone)]
#[derive(Copy, Clone, Debug)]
pub enum CastError {
ErrorGuaranteed(ErrorGuaranteed),

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/consts/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl std::fmt::Debug for ConstInt {
(4, _) => write!(fmt, "_i32")?,
(8, _) => write!(fmt, "_i64")?,
(16, _) => write!(fmt, "_i128")?,
_ => bug!(),
(sz, _) => bug!("unexpected int size i{sz}"),
}
}
Ok(())
Expand Down Expand Up @@ -105,7 +105,7 @@ impl std::fmt::Debug for ConstInt {
(4, _) => write!(fmt, "_u32")?,
(8, _) => write!(fmt, "_u64")?,
(16, _) => write!(fmt, "_u128")?,
_ => bug!(),
(sz, _) => bug!("unexpected unsigned int size u{sz}"),
}
}
Ok(())
Expand Down
7 changes: 2 additions & 5 deletions compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,13 +421,10 @@ impl<'tcx> TyCtxt<'tcx> {

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

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

let result = iter::zip(item_args, impl_args)
.filter(|&(_, k)| {
Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_mir_build/src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,15 +640,19 @@ 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();
(vec![coroutine_ty, args.resume_ty()], return_ty, Some(yield_ty))
}
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() {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/thir/cx/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down

0 comments on commit 1cc0d7d

Please sign in to comment.