Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust 1.62 #2489

Merged
merged 3 commits into from
Jul 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pyo3-build-config/src/impl_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,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 @@ -1229,7 +1230,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 @@ -598,6 +598,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
15 changes: 9 additions & 6 deletions src/impl_/frompyobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,26 @@ 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 = extract_traceback(py, error.clone_ref(py)),
));
)
.unwrap();
}
PyTypeError::new_err(err_msg)
}

/// Flattens a chain of errors into a single string.
fn extract_traceback(py: Python<'_>, mut error: PyErr) -> String {
use std::fmt::Write;

let mut error_msg = error.to_string();
while let Some(cause) = error.cause(py) {
error_msg.push_str(", caused by ");
error_msg.push_str(&cause.to_string());
write!(&mut error_msg, ", caused by {}", cause).unwrap();
error = cause
}
error_msg
Expand Down
16 changes: 12 additions & 4 deletions tests/test_compile_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,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 @@ -62,7 +63,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 @@ -84,7 +85,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,12 +99,20 @@ fn _test_compile_errors() {
fn tests_rust_1_60(t: &trybuild::TestCases) {
t.compile_fail("tests/ui/invalid_intern_arg.rs");
t.compile_fail("tests/ui/invalid_frozen_pyclass_borrow.rs");
t.compile_fail("tests/ui/invalid_pymethod_receiver.rs");
t.compile_fail("tests/ui/missing_intopy.rs");
}

#[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");
t.compile_fail("tests/ui/missing_intopy.rs");
}

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

#[cfg(feature = "nightly")]
Expand Down
3 changes: 3 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,6 +14,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: required by a bound in `PyRefMut`
--> src/pycell.rs
Expand All @@ -27,6 +29,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: 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 @@ -12,8 +12,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
|
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.

10 changes: 10 additions & 0 deletions tests/ui/missing_intopy.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ error[E0277]: the trait bound `Blah: IntoPyCallbackOutput<_>` is not satisfied
3 | #[pyo3::pyfunction]
| ^^^^^^^^^^^^^^^^^^^ the trait `IntoPyCallbackOutput<_>` is not implemented for `Blah`
|
= help: the following other types implement trait `IntoPyCallbackOutput<Target>`:
<() as IntoPyCallbackOutput<()>>
<() as IntoPyCallbackOutput<i32>>
<*mut PyObject as IntoPyCallbackOutput<*mut PyObject>>
<HashCallbackOutput as IntoPyCallbackOutput<isize>>
<IterANextOutput<Py<PyAny>, Py<PyAny>> as IntoPyCallbackOutput<*mut PyObject>>
<IterANextOutput<T, U> as IntoPyCallbackOutput<IterANextOutput<Py<PyAny>, Py<PyAny>>>>
<IterNextOutput<Py<PyAny>, Py<PyAny>> as IntoPyCallbackOutput<*mut PyObject>>
<IterNextOutput<T, U> as IntoPyCallbackOutput<IterNextOutput<Py<PyAny>, Py<PyAny>>>>
and 7 others
note: required by a bound in `pyo3::callback::convert`
--> src/callback.rs
|
Expand Down