Skip to content

Commit 6024e3e

Browse files
Fix irrefutable pattern errors
1 parent 7c5be7d commit 6024e3e

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

vm/src/pyobject.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,11 +1537,8 @@ impl PyObject {
15371537
}
15381538

15391539
pub fn payload<T: PyObjectPayload2>(&self) -> Option<&T> {
1540-
if let PyObjectPayload::AnyRustValue { ref value } = self.payload {
1541-
value.downcast_ref()
1542-
} else {
1543-
None
1544-
}
1540+
let PyObjectPayload::AnyRustValue { ref value } = self.payload;
1541+
value.downcast_ref()
15451542
}
15461543
}
15471544

vm/src/stdlib/re.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,20 +191,19 @@ fn match_end(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
191191

192192
/// Retrieve inner rust regex from python object:
193193
fn get_regex<'a>(obj: &'a PyObjectRef) -> &'a Regex {
194-
if let PyObjectPayload::AnyRustValue { ref value } = obj.payload {
195-
if let Some(regex) = value.downcast_ref::<Regex>() {
196-
return regex;
197-
}
194+
// TODO: Regex shouldn't be stored in payload directly, create newtype wrapper
195+
let PyObjectPayload::AnyRustValue { ref value } = obj.payload;
196+
if let Some(regex) = value.downcast_ref::<Regex>() {
197+
return regex;
198198
}
199199
panic!("Inner error getting regex {:?}", obj);
200200
}
201201

202202
/// Retrieve inner rust match from python object:
203203
fn get_match<'a>(obj: &'a PyObjectRef) -> &'a PyMatch {
204-
if let PyObjectPayload::AnyRustValue { ref value } = obj.payload {
205-
if let Some(value) = value.downcast_ref::<PyMatch>() {
206-
return value;
207-
}
204+
let PyObjectPayload::AnyRustValue { ref value } = obj.payload;
205+
if let Some(value) = value.downcast_ref::<PyMatch>() {
206+
return value;
208207
}
209208
panic!("Inner error getting match {:?}", obj);
210209
}

vm/src/stdlib/socket.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,9 @@ impl Socket {
127127
}
128128

129129
fn get_socket<'a>(obj: &'a PyObjectRef) -> impl DerefMut<Target = Socket> + 'a {
130-
if let PyObjectPayload::AnyRustValue { ref value } = obj.payload {
131-
if let Some(socket) = value.downcast_ref::<RefCell<Socket>>() {
132-
return socket.borrow_mut();
133-
}
130+
let PyObjectPayload::AnyRustValue { ref value } = obj.payload;
131+
if let Some(socket) = value.downcast_ref::<RefCell<Socket>>() {
132+
return socket.borrow_mut();
134133
}
135134
panic!("Inner error getting socket {:?}", obj);
136135
}

0 commit comments

Comments
 (0)