ci: updates for rust 1.71

This commit is contained in:
David Hewitt 2023-07-14 10:28:17 +01:00
parent bb05896324
commit b65cbb958b
22 changed files with 88 additions and 44 deletions

View file

@ -10,7 +10,7 @@ fn iter_dict(b: &mut Bencher<'_>) {
let dict = (0..LEN as u64).map(|i| (i, i * 2)).into_py_dict(py);
let mut sum = 0;
b.iter(|| {
for (k, _v) in dict.iter() {
for (k, _v) in dict {
let i: u64 = k.extract().unwrap();
sum += i;
}

View file

@ -9,7 +9,7 @@ fn iter_list(b: &mut Bencher<'_>) {
let list = PyList::new(py, 0..LEN);
let mut sum = 0;
b.iter(|| {
for x in list.iter() {
for x in list {
let i: u64 = x.extract().unwrap();
sum += i;
}

View file

@ -24,7 +24,7 @@ fn iter_set(b: &mut Bencher<'_>) {
let set = PySet::new(py, &(0..LEN).collect::<Vec<_>>()).unwrap();
let mut sum = 0;
b.iter(|| {
for x in set.iter() {
for x in set {
let i: u64 = x.extract().unwrap();
sum += i;
}

View file

@ -9,7 +9,7 @@ fn iter_tuple(b: &mut Bencher<'_>) {
let tuple = PyTuple::new(py, 0..LEN);
let mut sum = 0;
b.iter(|| {
for x in tuple.iter() {
for x in tuple {
let i: u64 = x.extract().unwrap();
sum += i;
}

View file

@ -97,7 +97,7 @@ pub fn impl_methods(
let mut implemented_proto_fragments = HashSet::new();
for iimpl in impls.iter_mut() {
for iimpl in impls {
match iimpl {
syn::ImplItem::Fn(meth) => {
let mut fun_options = PyFunctionOptions::from_attrs(&mut meth.attrs)?;

View file

@ -79,7 +79,7 @@ pub fn get_doc(attrs: &[syn::Attribute], mut text_signature: Option<String>) ->
let mut first = true;
let mut current_part = text_signature.unwrap_or_default();
for attr in attrs.iter() {
for attr in attrs {
if attr.path().is_ident("doc") {
if let Ok(nv) = attr.meta.require_name_value() {
if !first {

View file

@ -22,7 +22,7 @@ impl DictSize {
fn iter_dict(&mut self, _py: Python<'_>, dict: &PyDict) -> PyResult<u32> {
let mut seen = 0u32;
for (sym, values) in dict.iter() {
for (sym, values) in dict {
seen += 1;
println!(
"{:4}/{:4} iterations:{}=>{}",

View file

@ -57,7 +57,7 @@ where
fn extract(ob: &'source PyAny) -> Result<Self, PyErr> {
let dict: &PyDict = ob.downcast()?;
let mut ret = hashbrown::HashMap::with_capacity_and_hasher(dict.len(), S::default());
for (k, v) in dict.iter() {
for (k, v) in dict {
ret.insert(K::extract(k)?, V::extract(v)?);
}
Ok(ret)

View file

@ -125,7 +125,7 @@ where
fn extract(ob: &'source PyAny) -> Result<Self, PyErr> {
let dict: &PyDict = ob.downcast()?;
let mut ret = indexmap::IndexMap::with_capacity_and_hasher(dict.len(), S::default());
for (k, v) in dict.iter() {
for (k, v) in dict {
ret.insert(K::extract(k)?, V::extract(v)?);
}
Ok(ret)

View file

@ -74,7 +74,7 @@ where
fn extract(ob: &'source PyAny) -> Result<Self, PyErr> {
let dict: &PyDict = ob.downcast()?;
let mut ret = collections::HashMap::with_capacity_and_hasher(dict.len(), S::default());
for (k, v) in dict.iter() {
for (k, v) in dict {
ret.insert(K::extract(k)?, V::extract(v)?);
}
Ok(ret)
@ -94,7 +94,7 @@ where
fn extract(ob: &'source PyAny) -> Result<Self, PyErr> {
let dict: &PyDict = ob.downcast()?;
let mut ret = collections::BTreeMap::new();
for (k, v) in dict.iter() {
for (k, v) in dict {
ret.insert(K::extract(k)?, V::extract(v)?);
}
Ok(ret)

View file

@ -724,7 +724,7 @@ impl_native_exception!(
#[cfg(test)]
macro_rules! test_exception {
($exc_ty:ident $(, $constructor:expr)?) => {
($exc_ty:ident $(, |$py:tt| $constructor:expr )?) => {
#[allow(non_snake_case)]
#[test]
fn $exc_ty () {
@ -735,7 +735,7 @@ macro_rules! test_exception {
let err: $crate::PyErr = {
None
$(
.or(Some($constructor(py)))
.or(Some({ let $py = py; $constructor }))
)?
.unwrap_or($exc_ty::new_err("a test exception"))
};
@ -770,12 +770,12 @@ pub mod asyncio {
test_exception!(CancelledError);
test_exception!(InvalidStateError);
test_exception!(TimeoutError);
test_exception!(IncompleteReadError, |_| {
IncompleteReadError::new_err(("partial", "expected"))
});
test_exception!(LimitOverrunError, |_| {
LimitOverrunError::new_err(("message", "consumed"))
});
test_exception!(IncompleteReadError, |_| IncompleteReadError::new_err((
"partial", "expected"
)));
test_exception!(LimitOverrunError, |_| LimitOverrunError::new_err((
"message", "consumed"
)));
test_exception!(QueueEmpty);
test_exception!(QueueFull);
}
@ -1033,9 +1033,10 @@ mod tests {
});
}
#[cfg(Py_3_11)]
test_exception!(PyBaseExceptionGroup, |_| {
PyBaseExceptionGroup::new_err(("msg", vec![PyValueError::new_err("err")]))
});
test_exception!(PyBaseExceptionGroup, |_| PyBaseExceptionGroup::new_err((
"msg",
vec![PyValueError::new_err("err")]
)));
test_exception!(PyBaseException);
test_exception!(PyException);
test_exception!(PyStopAsyncIteration);
@ -1072,10 +1073,9 @@ mod tests {
let err = std::str::from_utf8(invalid_utf8).expect_err("should be invalid utf8");
PyErr::from_value(PyUnicodeDecodeError::new_utf8(py, invalid_utf8, err).unwrap())
});
test_exception!(PyUnicodeEncodeError, |py: Python<'_>| {
py.eval("chr(40960).encode('ascii')", None, None)
.unwrap_err()
});
test_exception!(PyUnicodeEncodeError, |py| py
.eval("chr(40960).encode('ascii')", None, None)
.unwrap_err());
test_exception!(PyUnicodeTranslateError, |_| {
PyUnicodeTranslateError::new_err(("\u{3042}", 0, 1, "ouch"))
});

View file

@ -654,7 +654,7 @@ mod tests {
// Can't just compare against a vector of tuples since we don't have a guaranteed ordering.
let mut key_sum = 0;
let mut value_sum = 0;
for el in dict.items().iter() {
for el in dict.items() {
let tuple = el.downcast::<PyTuple>().unwrap();
key_sum += tuple.get_item(0).unwrap().extract::<i32>().unwrap();
value_sum += tuple.get_item(1).unwrap().extract::<i32>().unwrap();
@ -675,7 +675,7 @@ mod tests {
let dict: &PyDict = ob.downcast(py).unwrap();
// Can't just compare against a vector of tuples since we don't have a guaranteed ordering.
let mut key_sum = 0;
for el in dict.keys().iter() {
for el in dict.keys() {
key_sum += el.extract::<i32>().unwrap();
}
assert_eq!(7 + 8 + 9, key_sum);
@ -693,7 +693,7 @@ mod tests {
let dict: &PyDict = ob.downcast(py).unwrap();
// Can't just compare against a vector of tuples since we don't have a guaranteed ordering.
let mut values_sum = 0;
for el in dict.values().iter() {
for el in dict.values() {
values_sum += el.extract::<i32>().unwrap();
}
assert_eq!(32 + 42 + 123, values_sum);
@ -711,7 +711,7 @@ mod tests {
let dict: &PyDict = ob.downcast(py).unwrap();
let mut key_sum = 0;
let mut value_sum = 0;
for (key, value) in dict.iter() {
for (key, value) in dict {
key_sum += key.extract::<i32>().unwrap();
value_sum += value.extract::<i32>().unwrap();
}
@ -731,7 +731,7 @@ mod tests {
let ob = v.to_object(py);
let dict: &PyDict = ob.downcast(py).unwrap();
for (key, value) in dict.iter() {
for (key, value) in dict {
dict.set_item(key, value.extract::<i32>().unwrap() + 7)
.unwrap();
}

View file

@ -260,7 +260,7 @@ mod tests {
let set = PyFrozenSet::new(py, &[1]).unwrap();
// iter method
for el in set.iter() {
for el in set {
assert_eq!(1i32, el.extract::<i32>().unwrap());
}

View file

@ -474,7 +474,7 @@ mod tests {
let v = vec![2, 3, 5, 7];
let list = PyList::new(py, &v);
let mut idx = 0;
for el in list.iter() {
for el in list {
assert_eq!(v[idx], el.extract::<i32>().unwrap());
idx += 1;
}

View file

@ -773,7 +773,7 @@ mod tests {
let seq = ob.downcast::<PySequence>(py).unwrap();
let repeat_seq = seq.repeat(3).unwrap();
assert_eq!(6, repeat_seq.len().unwrap());
let repeated = vec!["foo", "bar", "foo", "bar", "foo", "bar"];
let repeated = ["foo", "bar", "foo", "bar", "foo", "bar"];
for (el, rpt) in repeat_seq.iter().unwrap().zip(repeated.iter()) {
assert_eq!(*rpt, el.unwrap().extract::<String>().unwrap());
}

View file

@ -368,7 +368,7 @@ mod tests {
let set = PySet::new(py, &[1]).unwrap();
// iter method
for el in set.iter() {
for el in set {
assert_eq!(1i32, el.extract::<'_, i32>().unwrap());
}

View file

@ -296,7 +296,7 @@ mod tests {
#[test]
fn test_to_str_surrogate() {
Python::with_gil(|py| {
let obj: PyObject = py.eval(r#"'\ud800'"#, None, None).unwrap().into();
let obj: PyObject = py.eval(r"'\ud800'", None, None).unwrap().into();
let py_string: &PyString = obj.downcast(py).unwrap();
assert!(py_string.to_str().is_err());
})
@ -316,7 +316,7 @@ mod tests {
fn test_to_string_lossy() {
Python::with_gil(|py| {
let obj: PyObject = py
.eval(r#"'🐈 Hello \ud800World'"#, None, None)
.eval(r"'🐈 Hello \ud800World'", None, None)
.unwrap()
.into();
let py_string: &PyString = obj.downcast(py).unwrap();

View file

@ -8,7 +8,7 @@ fn iter_dict_nosegv() {
const LEN: usize = 10_000_000;
let dict = (0..LEN as u64).map(|i| (i, i * 2)).into_py_dict(py);
let mut sum = 0;
for (k, _v) in dict.iter() {
for (k, _v) in dict {
let i: u64 = k.extract().unwrap();
sum += i;
}

View file

@ -1,6 +1,8 @@
error[E0597]: `local_data` does not live long enough
--> tests/ui/invalid_closure.rs:7:27
|
6 | let local_data = vec![0, 1, 2, 3, 4];
| ---------- binding `local_data` declared here
7 | let ref_: &[u8] = &local_data;
| ^^^^^^^^^^^ borrowed value does not live long enough
...

View file

@ -25,6 +25,9 @@ error[E0271]: type mismatch resolving `<Foo as PyClass>::Frozen == False`
note: required by a bound in `pyo3::PyCell::<T>::borrow_mut`
--> src/pycell.rs
|
| pub fn borrow_mut(&self) -> PyRefMut<'_, T>
| ---------- required by a bound in this associated function
| where
| T: PyClass<Frozen = False>,
| ^^^^^^^^^^^^^^ required by this bound in `PyCell::<T>::borrow_mut`
@ -37,6 +40,9 @@ error[E0271]: type mismatch resolving `<ImmutableChild as PyClass>::Frozen == Fa
note: required by a bound in `pyo3::PyCell::<T>::borrow_mut`
--> src/pycell.rs
|
| pub fn borrow_mut(&self) -> PyRefMut<'_, T>
| ---------- required by a bound in this associated function
| where
| T: PyClass<Frozen = False>,
| ^^^^^^^^^^^^^^ required by this bound in `PyCell::<T>::borrow_mut`
@ -49,6 +55,9 @@ error[E0271]: type mismatch resolving `<MutableBase as PyClass>::Frozen == True`
note: required by a bound in `pyo3::Py::<T>::get`
--> src/instance.rs
|
| pub fn get(&self) -> &T
| --- required by a bound in this associated function
| where
| T: PyClass<Frozen = True> + Sync,
| ^^^^^^^^^^^^^ required by this bound in `Py::<T>::get`
@ -61,5 +70,8 @@ error[E0271]: type mismatch resolving `<MutableBase as PyClass>::Frozen == True`
note: required by a bound in `pyo3::PyCell::<T>::get`
--> src/pycell.rs
|
| pub fn get(&self) -> &T
| --- required by a bound in this associated function
| where
| T: PyClass<Frozen = True> + Sync,
| ^^^^^^^^^^^^^ required by this bound in `PyCell::<T>::get`

View file

@ -7,11 +7,27 @@ error[E0277]: `*mut pyo3::Python<'static>` cannot be shared between threads safe
| required by a bound introduced by this call
|
= help: within `pyo3::Python<'_>`, the trait `Sync` is not implemented for `*mut pyo3::Python<'static>`
= note: required because it appears within the type `PhantomData<*mut Python<'static>>`
= note: required because it appears within the type `NotSend`
note: required because it appears within the type `PhantomData<*mut Python<'static>>`
--> $RUST/core/src/marker.rs
|
| pub struct PhantomData<T: ?Sized>;
| ^^^^^^^^^^^
note: required because it appears within the type `NotSend`
--> src/impl_/not_send.rs
|
| pub(crate) struct NotSend(PhantomData<*mut Python<'static>>);
| ^^^^^^^
= note: required because it appears within the type `(&GILGuard, NotSend)`
= note: required because it appears within the type `PhantomData<(&GILGuard, NotSend)>`
= note: required because it appears within the type `Python<'_>`
note: required because it appears within the type `PhantomData<(&GILGuard, NotSend)>`
--> $RUST/core/src/marker.rs
|
| pub struct PhantomData<T: ?Sized>;
| ^^^^^^^^^^^
note: required because it appears within the type `Python<'_>`
--> src/marker.rs
|
| pub struct Python<'py>(PhantomData<(&'py GILGuard, NotSend)>);
| ^^^^^^
= note: required for `&pyo3::Python<'_>` to implement `Send`
note: required because it's used within this closure
--> tests/ui/not_send.rs:4:22
@ -22,5 +38,8 @@ note: required because it's used within this closure
note: required by a bound in `pyo3::Python::<'py>::allow_threads`
--> src/marker.rs
|
| pub fn allow_threads<T, F>(self, f: F) -> T
| ------------- required by a bound in this associated function
| where
| F: Ungil + FnOnce() -> T,
| ^^^^^ required by this bound in `Python::<'py>::allow_threads`

View file

@ -10,8 +10,16 @@ error[E0277]: `UnsafeCell<PyObject>` cannot be shared between threads safely
| |_________^ `UnsafeCell<PyObject>` cannot be shared between threads safely
|
= help: within `&PyString`, the trait `Sync` is not implemented for `UnsafeCell<PyObject>`
= note: required because it appears within the type `PyAny`
= note: required because it appears within the type `PyString`
note: required because it appears within the type `PyAny`
--> src/types/any.rs
|
| pub struct PyAny(UnsafeCell<ffi::PyObject>);
| ^^^^^
note: required because it appears within the type `PyString`
--> src/types/string.rs
|
| pub struct PyString(PyAny);
| ^^^^^^^^
= note: required because it appears within the type `&PyString`
= note: required for `&&PyString` to implement `Send`
note: required because it's used within this closure
@ -23,5 +31,8 @@ note: required because it's used within this closure
note: required by a bound in `pyo3::Python::<'py>::allow_threads`
--> src/marker.rs
|
| pub fn allow_threads<T, F>(self, f: F) -> T
| ------------- required by a bound in this associated function
| where
| F: Ungil + FnOnce() -> T,
| ^^^^^ required by this bound in `Python::<'py>::allow_threads`