Skip to content

Commit

Permalink
Rust 1.62 (PyO3#2489)
Browse files Browse the repository at this point in the history
* Rust 1.62

* Make rust happy

* Just use a doctest instead

Co-authored-by: mejrs <>
  • Loading branch information
mejrs authored and davidhewitt committed Jul 26, 2022
1 parent 526023c commit 2674034
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 44 deletions.
6 changes: 4 additions & 2 deletions pyo3-build-config/src/impl_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,8 @@ impl BuildFlags {
script.push_str("config = sysconfig.get_config_vars()\n");

for k in &BuildFlags::ALL {
script.push_str(&format!("print(config.get('{}', '0'))\n", k));
use std::fmt::Write;
writeln!(&mut script, "print(config.get('{}', '0'))", k).unwrap();
}

let stdout = run_python_script(interpreter.as_ref(), &script)?;
Expand Down Expand Up @@ -1225,7 +1226,8 @@ fn find_sysconfigdata(cross: &CrossCompileConfig) -> Result<Option<PathBuf>> {
sysconfigdata files found:",
);
for path in sysconfig_paths {
error_msg += &format!("\n\t{}", path.display());
use std::fmt::Write;
write!(&mut error_msg, "\n\t{}", path.display()).unwrap();
}
bail!("{}\n", error_msg);
}
Expand Down
17 changes: 17 additions & 0 deletions src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,23 @@ where
}
}

/// ```rust,compile_fail
/// use pyo3::prelude::*;
///
/// #[pyclass]
/// struct TestClass {
/// num: u32,
/// }
///
/// let t = TestClass { num: 10 };
///
/// Python::with_gil(|py| {
/// let pyvalue = Py::new(py, t).unwrap().to_object(py);
/// let t: TestClass = pyvalue.extract(py).unwrap();
/// })
/// ```
mod test_no_clone {}

#[cfg(test)]
mod tests {
use crate::types::{IntoPyDict, PyAny, PyDict, PyList};
Expand Down
10 changes: 6 additions & 4 deletions src/impl_/frompyobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ pub fn failed_to_extract_enum(
error_names.join(" | ")
);
for ((variant_name, error_name), error) in variant_names.iter().zip(error_names).zip(errors) {
err_msg.push('\n');
err_msg.push_str(&format!(
"- variant {variant_name} ({error_name}): {error_msg}",
use std::fmt::Write;
write!(
&mut err_msg,
"\n- variant {variant_name} ({error_name}): {error_msg}",
variant_name = variant_name,
error_name = error_name,
error_msg = error.value(py).str().unwrap().to_str().unwrap(),
));
)
.unwrap();
}
PyTypeError::new_err(err_msg)
}
13 changes: 11 additions & 2 deletions tests/test_compile_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ fn _test_compile_errors() {
tests_rust_1_57(&t);
tests_rust_1_58(&t);
tests_rust_1_60(&t);
tests_rust_1_62(&t);

#[rustversion::since(1.49)]
fn tests_rust_1_49(t: &trybuild::TestCases) {
Expand All @@ -59,7 +60,7 @@ fn _test_compile_errors() {
#[rustversion::since(1.56)]
fn tests_rust_1_56(t: &trybuild::TestCases) {
t.compile_fail("tests/ui/invalid_closure.rs");
t.compile_fail("tests/ui/invalid_result_conversion.rs");

t.compile_fail("tests/ui/pyclass_send.rs");
}

Expand All @@ -81,7 +82,6 @@ fn _test_compile_errors() {
fn tests_rust_1_58(t: &trybuild::TestCases) {
t.compile_fail("tests/ui/invalid_pyfunctions.rs");
t.compile_fail("tests/ui/invalid_pymethods.rs");
t.compile_fail("tests/ui/missing_clone.rs");
t.compile_fail("tests/ui/not_send.rs");
t.compile_fail("tests/ui/not_send2.rs");
t.compile_fail("tests/ui/not_send3.rs");
Expand All @@ -99,6 +99,15 @@ fn _test_compile_errors() {

#[rustversion::before(1.60)]
fn tests_rust_1_60(_t: &trybuild::TestCases) {}

#[rustversion::since(1.62)]
fn tests_rust_1_62(t: &trybuild::TestCases) {
t.compile_fail("tests/ui/invalid_pymethod_receiver.rs");
t.compile_fail("tests/ui/invalid_result_conversion.rs");
}

#[rustversion::before(1.62)]
fn tests_rust_1_62(_t: &trybuild::TestCases) {}
}

#[cfg(feature = "nightly")]
Expand Down
20 changes: 20 additions & 0 deletions tests/ui/abi3_nativetype_inheritance.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ error[E0277]: the trait bound `PyDict: PyClass` is not satisfied
5 | #[pyclass(extends=PyDict)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `PyClass` is not implemented for `PyDict`
|
= help: the trait `PyClass` is implemented for `TestClass`
= note: required because of the requirements on the impl of `PyClassBaseType` for `PyDict`
= note: this error originates in the attribute macro `pyclass` (in Nightly builds, run with -Z macro-backtrace for more info)

Expand All @@ -13,7 +14,26 @@ error[E0277]: the trait bound `PyDict: PyClass` is not satisfied
5 | #[pyclass(extends=PyDict)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `PyClass` is not implemented for `PyDict`
|
= help: the trait `PyClass` is implemented for `TestClass`
= note: required because of the requirements on the impl of `PyClassBaseType` for `PyDict`
<<<<<<< HEAD
=======
note: required by a bound in `PyRefMut`
--> src/pycell.rs
|
| pub struct PyRefMut<'p, T: PyClass<Frozen = False>> {
| ^^^^^^^^^^^^^^ required by this bound in `PyRefMut`
= note: this error originates in the attribute macro `pyclass` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `PyDict: PyClass` is not satisfied
--> tests/ui/abi3_nativetype_inheritance.rs:5:1
|
5 | #[pyclass(extends=PyDict)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `PyClass` is not implemented for `PyDict`
|
= help: the trait `PyClass` is implemented for `TestClass`
= note: required because of the requirements on the impl of `PyClassBaseType` for `PyDict`
>>>>>>> 58d4ba833e (Rust 1.62 (#2489))
note: required by a bound in `ThreadCheckerInherited`
--> src/impl_/pyclass.rs
|
Expand Down
16 changes: 10 additions & 6 deletions tests/ui/invalid_pymethod_receiver.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ error[E0277]: the trait bound `i32: From<&PyCell<MyClass>>` is not satisfied
8 | fn method_with_invalid_self_type(slf: i32, py: Python<'_>, index: u32) {}
| ^^^ the trait `From<&PyCell<MyClass>>` is not implemented for `i32`
|
= help: the following implementations were found:
<i32 as From<NonZeroI32>>
<i32 as From<bool>>
<i32 as From<i16>>
<i32 as From<i8>>
and 71 others
= help: the following other types implement trait `From<T>`:
<f32 as From<i16>>
<f32 as From<i8>>
<f32 as From<u16>>
<f32 as From<u8>>
<f64 as From<f32>>
<f64 as From<i16>>
<f64 as From<i32>>
<f64 as From<i8>>
and 67 others
= note: required because of the requirements on the impl of `Into<i32>` for `&PyCell<MyClass>`
= note: required because of the requirements on the impl of `TryFrom<&PyCell<MyClass>>` for `i32`
3 changes: 1 addition & 2 deletions tests/ui/invalid_result_conversion.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ error[E0277]: the trait bound `Result<(), MyError>: IntoPyCallbackOutput<_>` is
21 | #[pyfunction]
| ^^^^^^^^^^^^^ the trait `IntoPyCallbackOutput<_>` is not implemented for `Result<(), MyError>`
|
= help: the following implementations were found:
<Result<T, E> as IntoPyCallbackOutput<U>>
= help: the trait `IntoPyCallbackOutput<U>` is implemented for `Result<T, E>`
note: required by a bound in `pyo3::callback::convert`
--> src/callback.rs:182:8
|
Expand Down
16 changes: 0 additions & 16 deletions tests/ui/missing_clone.rs

This file was deleted.

12 changes: 0 additions & 12 deletions tests/ui/missing_clone.stderr

This file was deleted.

0 comments on commit 2674034

Please sign in to comment.