Skip to content

Commit a840ebb

Browse files
committed
Support Rust 1.39.0
1 parent 6440814 commit a840ebb

File tree

7 files changed

+48
-28
lines changed

7 files changed

+48
-28
lines changed

.travis.yml

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ jobs:
2323
- name: Nightly
2424
python: "3.7"
2525
env: TRAVIS_RUST_VERSION=nightly FEATURES="nightly"
26+
- name: Minimum Stable
27+
python: "3.7"
28+
env: TRAVIS_RUST_VERSION=1.39.0
2629
- name: PyPy3.5 7.0 # Tested via anaconda PyPy (since travis's PyPy version is too old)
2730
python: "3.7"
2831
env: FEATURES="pypy" PATH="$PATH:/opt/anaconda/envs/pypy3/bin"

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ unindent = { version = "0.1.4", optional = true }
3333
[dev-dependencies]
3434
assert_approx_eq = "1.1.0"
3535
trybuild = "1.0.23"
36+
rustversion = "1.0"
3637

3738
[features]
3839
default = ["macros"]

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[![Actions Status](https://github.com/PyO3/pyo3/workflows/Test/badge.svg)](https://github.com/PyO3/pyo3/actions)
55
[![codecov](https://codecov.io/gh/PyO3/pyo3/branch/master/graph/badge.svg)](https://codecov.io/gh/PyO3/pyo3)
66
[![crates.io](http://meritbadge.herokuapp.com/pyo3)](https://crates.io/crates/pyo3)
7+
[![minimum rustc 1.42](https://img.shields.io/badge/rustc-1.39+-blue.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html)
78
[![Join the dev chat](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/PyO3/Lobby)
89

910
[Rust](http://www.rust-lang.org/) bindings for [Python](https://www.python.org/). This includes running and interacting with Python code from a Rust binary, as well as writing native Python modules.
@@ -16,7 +17,7 @@ A comparison with rust-cpython can be found [in the guide](https://pyo3.rs/maste
1617

1718
## Usage
1819

19-
PyO3 supports Python 3.5 and up. The minimum required Rust version is 1.44.
20+
PyO3 supports Python 3.5 and up. The minimum required Rust version is 1.39.0.
2021

2122
PyPy is also supported (via cpyext) for Python 3.5 only, targeted PyPy version is 7.0.0.
2223
Please refer to the [pypy section in the guide](https://pyo3.rs/master/pypy.html).

build.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ impl FromStr for PythonInterpreterKind {
6969
type Err = Box<dyn std::error::Error>;
7070
fn from_str(s: &str) -> Result<Self> {
7171
match s {
72-
"CPython" => Ok(Self::CPython),
73-
"PyPy" => Ok(Self::PyPy),
72+
"CPython" => Ok(PythonInterpreterKind::CPython),
73+
"PyPy" => Ok(PythonInterpreterKind::PyPy),
7474
_ => Err(format!("Invalid interpreter: {}", s).into()),
7575
}
7676
}
@@ -295,7 +295,7 @@ fn run_python_script(interpreter: &Path, script: &str) -> Result<String> {
295295
);
296296
}
297297
}
298-
Ok(ok) if !ok.status.success() => bail!("Python script failed: {}"),
298+
Ok(ref ok) if !ok.status.success() => bail!("Python script failed: {}"),
299299
Ok(ok) => Ok(String::from_utf8(ok.stdout)?),
300300
}
301301
}

pyo3-derive-backend/src/pyfunction.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -179,22 +179,25 @@ pub fn parse_name_attribute(attrs: &mut Vec<syn::Attribute>) -> syn::Result<Opti
179179
_ => true,
180180
});
181181

182-
match &*name_attrs {
183-
[] => Ok(None),
184-
[(syn::Lit::Str(s), span)] => {
182+
if 1 < name_attrs.len() {
183+
return Err(syn::Error::new(
184+
name_attrs[0].1,
185+
"#[name] can not be specified multiple times",
186+
));
187+
}
188+
189+
match name_attrs.get(0) {
190+
Some((syn::Lit::Str(s), span)) => {
185191
let mut ident: syn::Ident = s.parse()?;
186192
// This span is the whole attribute span, which is nicer for reporting errors.
187193
ident.set_span(*span);
188194
Ok(Some(ident))
189195
}
190-
[(_, span)] => Err(syn::Error::new(
196+
Some((_, span)) => Err(syn::Error::new(
191197
*span,
192198
"Expected string literal for #[name] argument",
193199
)),
194-
[(_, span), ..] => Err(syn::Error::new(
195-
*span,
196-
"#[name] can not be specified multiple times",
197-
)),
200+
None => Ok(None),
198201
}
199202
}
200203

pyo3-derive-backend/src/pymethod.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -512,10 +512,11 @@ fn impl_arg_param(
512512
};
513513
if let syn::Type::Reference(tref) = ty {
514514
let (tref, mut_) = tref_preprocess(tref);
515-
let as_deref = if mut_.is_some() {
516-
quote! { as_deref_mut }
515+
// To support Rustc 1.39.0, we don't use as_deref here...
516+
let tmp_as_deref = if mut_.is_some() {
517+
quote! { _tmp.as_mut().map(std::ops::DerefMut::deref_mut) }
517518
} else {
518-
quote! { as_deref }
519+
quote! { _tmp.as_ref().map(std::ops::Deref::deref) }
519520
};
520521
// Get Option<&T> from Option<PyRef<T>>
521522
quote! {
@@ -525,7 +526,7 @@ fn impl_arg_param(
525526
},
526527
None => #default,
527528
};
528-
let #arg_name = _tmp.#as_deref();
529+
let #arg_name = #tmp_as_deref;
529530
}
530531
} else {
531532
quote! {
@@ -731,8 +732,9 @@ pub(crate) fn impl_py_getter_def(
731732

732733
/// Split an argument of pyo3::Python from the front of the arg list, if present
733734
fn split_off_python_arg<'a>(args: &'a [FnArg<'a>]) -> (Option<&FnArg>, &[FnArg]) {
734-
match args {
735-
[py, rest @ ..] if utils::if_type_is_python(&py.ty) => (Some(py), rest),
736-
rest => (None, rest),
735+
if args.get(0).map(|py| utils::if_type_is_python(&py.ty)) == Some(true) {
736+
(Some(&args[0]), &args[1..])
737+
} else {
738+
(None, args)
737739
}
738740
}

tests/test_compile_error.rs

+19-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
#[test]
22
fn test_compile_errors() {
33
let t = trybuild::TestCases::new();
4-
t.compile_fail("tests/ui/invalid_macro_args.rs");
5-
t.compile_fail("tests/ui/invalid_property_args.rs");
6-
t.compile_fail("tests/ui/invalid_pyclass_args.rs");
7-
t.compile_fail("tests/ui/missing_clone.rs");
8-
t.compile_fail("tests/ui/reject_generics.rs");
9-
t.compile_fail("tests/ui/wrong_aspyref_lifetimes.rs");
10-
t.compile_fail("tests/ui/static_ref.rs");
11-
#[cfg(not(feature = "nightly"))]
12-
t.compile_fail("tests/ui/invalid_pymethod_names.rs");
4+
testcase_common(&t);
5+
testcase_latest_stable(&t);
6+
7+
fn testcase_common(t: &trybuild::TestCases) {
8+
t.compile_fail("tests/ui/invalid_macro_args.rs");
9+
t.compile_fail("tests/ui/invalid_property_args.rs");
10+
t.compile_fail("tests/ui/invalid_pyclass_args.rs");
11+
t.compile_fail("tests/ui/missing_clone.rs");
12+
t.compile_fail("tests/ui/reject_generics.rs");
13+
t.compile_fail("tests/ui/wrong_aspyref_lifetimes.rs");
14+
t.compile_fail("tests/ui/invalid_pymethod_names.rs");
15+
}
16+
17+
#[rustversion::all(since(1.43))]
18+
fn testcase_latest_stable(t: &trybuild::TestCases) {
19+
t.compile_fail("tests/ui/static_ref.rs");
20+
}
21+
#[rustversion::before(1.43)]
22+
fn testcase_latest_stable(_t: &trybuild::TestCases) {}
1323
}

0 commit comments

Comments
 (0)