make more matches exhaustive
This commit is contained in:
parent
c177e68015
commit
4a90a58c34
1 changed files with 41 additions and 20 deletions
|
@ -583,11 +583,15 @@ impl<'tcx> Validator<'_, 'tcx> {
|
||||||
|
|
||||||
fn validate_rvalue(&self, rvalue: &Rvalue<'tcx>) -> Result<(), Unpromotable> {
|
fn validate_rvalue(&self, rvalue: &Rvalue<'tcx>) -> Result<(), Unpromotable> {
|
||||||
match rvalue {
|
match rvalue {
|
||||||
Rvalue::Use(operand) | Rvalue::Repeat(operand, _) | Rvalue::UnaryOp(_, operand) => {
|
Rvalue::Use(operand)
|
||||||
|
| Rvalue::Repeat(operand, _)
|
||||||
|
| Rvalue::UnaryOp(UnOp::Not | UnOp::Neg, operand) => {
|
||||||
self.validate_operand(operand)?;
|
self.validate_operand(operand)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Rvalue::Discriminant(place) | Rvalue::Len(place) => self.validate_place(place.as_ref())?,
|
Rvalue::Discriminant(place) | Rvalue::Len(place) => {
|
||||||
|
self.validate_place(place.as_ref())?
|
||||||
|
}
|
||||||
|
|
||||||
Rvalue::ThreadLocalRef(_) => return Err(Unpromotable),
|
Rvalue::ThreadLocalRef(_) => return Err(Unpromotable),
|
||||||
|
|
||||||
|
@ -606,35 +610,52 @@ impl<'tcx> Validator<'_, 'tcx> {
|
||||||
self.validate_operand(operand)?;
|
self.validate_operand(operand)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Rvalue::BinaryOp(op, lhs, rhs)
|
Rvalue::BinaryOp(op, lhs, rhs) | Rvalue::CheckedBinaryOp(op, lhs, rhs) => {
|
||||||
| Rvalue::CheckedBinaryOp(op, lhs, rhs) => {
|
|
||||||
let op = *op;
|
let op = *op;
|
||||||
if let ty::RawPtr(_) | ty::FnPtr(..) = lhs.ty(self.body, self.tcx).kind() {
|
if let ty::RawPtr(_) | ty::FnPtr(..) = lhs.ty(self.body, self.tcx).kind() {
|
||||||
assert!(
|
|
||||||
op == BinOp::Eq
|
|
||||||
|| op == BinOp::Ne
|
|
||||||
|| op == BinOp::Le
|
|
||||||
|| op == BinOp::Lt
|
|
||||||
|| op == BinOp::Ge
|
|
||||||
|| op == BinOp::Gt
|
|
||||||
|| op == BinOp::Offset
|
|
||||||
);
|
|
||||||
|
|
||||||
// raw pointer operations are not allowed inside consts and thus not promotable
|
// raw pointer operations are not allowed inside consts and thus not promotable
|
||||||
|
assert!(matches!(
|
||||||
|
op,
|
||||||
|
BinOp::Eq
|
||||||
|
| BinOp::Ne
|
||||||
|
| BinOp::Le
|
||||||
|
| BinOp::Lt
|
||||||
|
| BinOp::Ge
|
||||||
|
| BinOp::Gt
|
||||||
|
| BinOp::Offset
|
||||||
|
));
|
||||||
return Err(Unpromotable);
|
return Err(Unpromotable);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: reject operations that can fail -- namely, division and modulo.
|
match op {
|
||||||
|
// FIXME: reject operations that can fail -- namely, division and modulo.
|
||||||
|
BinOp::Eq
|
||||||
|
| BinOp::Ne
|
||||||
|
| BinOp::Le
|
||||||
|
| BinOp::Lt
|
||||||
|
| BinOp::Ge
|
||||||
|
| BinOp::Gt
|
||||||
|
| BinOp::Offset
|
||||||
|
| BinOp::Add
|
||||||
|
| BinOp::Sub
|
||||||
|
| BinOp::Mul
|
||||||
|
| BinOp::Div
|
||||||
|
| BinOp::Rem
|
||||||
|
| BinOp::BitXor
|
||||||
|
| BinOp::BitAnd
|
||||||
|
| BinOp::BitOr
|
||||||
|
| BinOp::Shl
|
||||||
|
| BinOp::Shr => {}
|
||||||
|
}
|
||||||
|
|
||||||
self.validate_operand(lhs)?;
|
self.validate_operand(lhs)?;
|
||||||
self.validate_operand(rhs)?;
|
self.validate_operand(rhs)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Rvalue::NullaryOp(op, _) => {
|
Rvalue::NullaryOp(op, _) => match op {
|
||||||
if matches!(op, NullOp::Box) {
|
NullOp::Box => return Err(Unpromotable),
|
||||||
return Err(Unpromotable);
|
NullOp::SizeOf => {}
|
||||||
}
|
},
|
||||||
}
|
|
||||||
|
|
||||||
Rvalue::AddressOf(_, place) => {
|
Rvalue::AddressOf(_, place) => {
|
||||||
// We accept `&raw *`, i.e., raw reborrows -- creating a raw pointer is
|
// We accept `&raw *`, i.e., raw reborrows -- creating a raw pointer is
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue