1
Fork 0

Rollup merge of #128978 - compiler-errors:assert-matches, r=jieyouxu

Use `assert_matches` around the compiler more

It's a useful assertion, especially since it actually prints out the LHS.
This commit is contained in:
Guillaume Gomez 2024-08-12 17:09:19 +02:00 committed by GitHub
commit 7c6dca9050
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
39 changed files with 100 additions and 49 deletions

View file

@ -1,3 +1,5 @@
use std::assert_matches::assert_matches;
use rustc_macros::{extension, HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
use super::Const;
@ -80,7 +82,7 @@ impl<'tcx> Expr<'tcx> {
}
pub fn binop_args(self) -> (Ty<'tcx>, Ty<'tcx>, Const<'tcx>, Const<'tcx>) {
assert!(matches!(self.kind, ExprKind::Binop(_)));
assert_matches!(self.kind, ExprKind::Binop(_));
match self.args().as_slice() {
[lhs_ty, rhs_ty, lhs_ct, rhs_ct] => (
@ -101,7 +103,7 @@ impl<'tcx> Expr<'tcx> {
}
pub fn unop_args(self) -> (Ty<'tcx>, Const<'tcx>) {
assert!(matches!(self.kind, ExprKind::UnOp(_)));
assert_matches!(self.kind, ExprKind::UnOp(_));
match self.args().as_slice() {
[ty, ct] => (ty.expect_ty(), ct.expect_const()),
@ -125,7 +127,7 @@ impl<'tcx> Expr<'tcx> {
}
pub fn call_args(self) -> (Ty<'tcx>, Const<'tcx>, impl Iterator<Item = Const<'tcx>>) {
assert!(matches!(self.kind, ExprKind::FunctionCall));
assert_matches!(self.kind, ExprKind::FunctionCall);
match self.args().as_slice() {
[func_ty, func, rest @ ..] => (
@ -152,7 +154,7 @@ impl<'tcx> Expr<'tcx> {
}
pub fn cast_args(self) -> (Ty<'tcx>, Const<'tcx>, Ty<'tcx>) {
assert!(matches!(self.kind, ExprKind::Cast(_)));
assert_matches!(self.kind, ExprKind::Cast(_));
match self.args().as_slice() {
[value_ty, value, to_ty] => {