Skip to content

Commit 2705a92

Browse files
authored
Merge pull request #2040 from davidhewitt/rust-1.57
rust: support 1.57
2 parents 43c9955 + 4c8abd1 commit 2705a92

11 files changed

+48
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4141

4242
- Fix undefined symbol for `PyObject_HasAttr` on PyPy. [#2025](https://github.com/PyO3/pyo3/pull/2025)
4343
- Fix memory leak in `PyErr::into_value`. [#2026](https://github.com/PyO3/pyo3/pull/2026)
44+
- Fix clippy warning `needless-option-as-deref` in code generated by `#[pyfunction]` and `#[pymethods]`. [#2040](https://github.com/PyO3/pyo3/pull/2040)
4445

4546
## [0.15.1] - 2021-11-19
4647

pyo3-macros-backend/src/params.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ fn impl_arg_param(
292292

293293
Ok(quote_arg_span! {
294294
let #mut_ _tmp: #target_ty = #arg_value_or_default;
295+
#[allow(clippy::needless_option_as_deref)]
295296
let #arg_name = #borrow_tmp;
296297
})
297298
} else {

src/buffer.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ fn is_matching_endian(c: u8) -> bool {
163163
}
164164

165165
/// Trait implemented for possible element types of `PyBuffer`.
166+
///
167+
/// # Safety
168+
///
169+
/// This trait must only be implemented for types which represent valid elements of Python buffers.
166170
pub unsafe trait Element: Copy {
167171
/// Gets whether the element specified in the format string is potentially compatible.
168172
/// Alignment and size are checked separately from this function.

src/conversion.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,10 @@ impl IntoPy<Py<PyTuple>> for () {
463463
}
464464

465465
/// Raw level conversion between `*mut ffi::PyObject` and PyO3 types.
466+
///
467+
/// # Safety
468+
///
469+
/// See safety notes on individual functions.
466470
pub unsafe trait FromPyPointer<'p>: Sized {
467471
/// Convert from an arbitrary `PyObject`.
468472
///

src/instance.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ use std::ptr::NonNull;
1717
/// PyO3 is designed in a way that all references to those types are bound
1818
/// to the GIL, which is why you can get a token from all references of those
1919
/// types.
20+
///
21+
/// # Safety
22+
///
23+
/// This trait must only be implemented for types which cannot be accessed without the GIL.
2024
pub unsafe trait PyNativeType: Sized {
2125
/// Returns a GIL marker constrained to the lifetime of this type.
2226
#[inline]

src/type_object.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ use std::thread::{self, ThreadId};
1616
/// is of `PyAny`.
1717
///
1818
/// This trait is intended to be used internally.
19+
///
20+
/// # Safety
21+
///
22+
/// This trait must only be implemented for types which represent valid layouts of Python objects.
1923
pub unsafe trait PyLayout<T> {}
2024

2125
/// `T: PySizedLayout<U>` represents that `T` is not a instance of
@@ -31,6 +35,11 @@ pub trait PySizedLayout<T>: PyLayout<T> + Sized {}
3135
/// - the return value of type_object must always point to the same PyTypeObject instance
3236
///
3337
/// It is safely implemented by the `pyclass` macro.
38+
///
39+
/// # Safety
40+
///
41+
/// Implementations must provide an implementation for `type_object_raw` which infallibly produces a
42+
/// non-null pointer to the corresponding Python type object.
3443
pub unsafe trait PyTypeInfo: Sized {
3544
/// Class name.
3645
const NAME: &'static str;
@@ -57,6 +66,8 @@ pub unsafe trait PyTypeInfo: Sized {
5766

5867
/// Python object types that have a corresponding type object.
5968
///
69+
/// # Safety
70+
///
6071
/// This trait is marked unsafe because not fulfilling the contract for type_object
6172
/// leads to UB.
6273
///

tests/test_compile_error.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,13 @@ fn _test_compile_errors() {
2525
t.compile_fail("tests/ui/invalid_pymethods.rs");
2626
t.compile_fail("tests/ui/invalid_pymethod_names.rs");
2727
t.compile_fail("tests/ui/invalid_pymodule_args.rs");
28-
t.compile_fail("tests/ui/invalid_argument_attributes.rs");
2928
t.compile_fail("tests/ui/missing_clone.rs");
3029
t.compile_fail("tests/ui/reject_generics.rs");
31-
t.compile_fail("tests/ui/wrong_aspyref_lifetimes.rs");
3230

3331
tests_rust_1_49(&t);
34-
tests_rust_1_54(&t);
3532
tests_rust_1_55(&t);
3633
tests_rust_1_56(&t);
34+
tests_rust_1_57(&t);
3735

3836
#[rustversion::since(1.49)]
3937
fn tests_rust_1_49(t: &trybuild::TestCases) {
@@ -42,14 +40,6 @@ fn _test_compile_errors() {
4240
#[rustversion::before(1.49)]
4341
fn tests_rust_1_49(_t: &trybuild::TestCases) {}
4442

45-
#[rustversion::since(1.54)]
46-
fn tests_rust_1_54(t: &trybuild::TestCases) {
47-
t.compile_fail("tests/ui/invalid_frompy_derive.rs");
48-
t.compile_fail("tests/ui/static_ref.rs");
49-
}
50-
#[rustversion::before(1.54)]
51-
fn tests_rust_1_54(_t: &trybuild::TestCases) {}
52-
5343
#[rustversion::since(1.55)]
5444
fn tests_rust_1_55(t: &trybuild::TestCases) {
5545
t.compile_fail("tests/ui/invalid_pymethod_receiver.rs");
@@ -70,4 +60,15 @@ fn _test_compile_errors() {
7060

7161
#[rustversion::before(1.56)]
7262
fn tests_rust_1_56(_t: &trybuild::TestCases) {}
63+
64+
#[rustversion::since(1.57)]
65+
fn tests_rust_1_57(t: &trybuild::TestCases) {
66+
t.compile_fail("tests/ui/invalid_argument_attributes.rs");
67+
t.compile_fail("tests/ui/invalid_frompy_derive.rs");
68+
t.compile_fail("tests/ui/static_ref.rs");
69+
t.compile_fail("tests/ui/wrong_aspyref_lifetimes.rs");
70+
}
71+
72+
#[rustversion::before(1.57)]
73+
fn tests_rust_1_57(_t: &trybuild::TestCases) {}
7374
}

tests/ui/invalid_argument_attributes.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ error: expected `from_py_with`
55
| ^^^
66

77
error: expected `=`
8-
--> tests/ui/invalid_argument_attributes.rs:7:32
8+
--> tests/ui/invalid_argument_attributes.rs:7:45
99
|
1010
7 | fn from_py_with_no_value(#[pyo3(from_py_with)] param: String) {}
11-
| ^^^^^^^^^^^^^^
11+
| ^
1212

1313
error: expected `from_py_with`
1414
--> tests/ui/invalid_argument_attributes.rs:10:31

tests/ui/invalid_frompy_derive.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ error: attribute name cannot be empty
109109
| ^^
110110

111111
error: unexpected end of input, expected string literal
112-
--> tests/ui/invalid_frompy_derive.rs:100:21
112+
--> tests/ui/invalid_frompy_derive.rs:100:22
113113
|
114114
100 | #[pyo3(attribute())]
115-
| ^^
115+
| ^
116116

117117
error: expected at most one argument: `item` or `item(key)`
118118
--> tests/ui/invalid_frompy_derive.rs:106:20
@@ -121,10 +121,10 @@ error: expected at most one argument: `item` or `item(key)`
121121
| ^
122122

123123
error: unexpected end of input, expected literal
124-
--> tests/ui/invalid_frompy_derive.rs:112:16
124+
--> tests/ui/invalid_frompy_derive.rs:112:17
125125
|
126126
112 | #[pyo3(item())]
127-
| ^^
127+
| ^
128128

129129
error: only one of `attribute` or `item` can be provided
130130
--> tests/ui/invalid_frompy_derive.rs:118:5
@@ -171,10 +171,10 @@ error: cannot derive FromPyObject for empty structs and variants
171171
= note: this error originates in the derive macro `FromPyObject` (in Nightly builds, run with -Z macro-backtrace for more info)
172172

173173
error: expected `=`
174-
--> tests/ui/invalid_frompy_derive.rs:158:11
174+
--> tests/ui/invalid_frompy_derive.rs:158:24
175175
|
176176
158 | #[pyo3(from_py_with)]
177-
| ^^^^^^^^^^^^^^
177+
| ^
178178

179179
error: expected string literal
180180
--> tests/ui/invalid_frompy_derive.rs:164:27

tests/ui/static_ref.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'py`
44
4 | #[pyfunction]
55
| ^^^^^^^^^^^^^
66
|
7-
note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the body at 4:1...
7+
note: first, the lifetime cannot outlive the anonymous lifetime #1 defined here...
88
--> tests/ui/static_ref.rs:4:1
99
|
1010
4 | #[pyfunction]

0 commit comments

Comments
 (0)