Skip to content

Commit 6d9cadc

Browse files
committed
rust: updates for rust & clippy 1.54
1 parent 3241467 commit 6d9cadc

20 files changed

+50
-57
lines changed

benches/bench_call.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ fn bench_call_0(b: &mut Bencher) {
1818
"#
1919
);
2020

21-
let foo = module.getattr("foo").unwrap();
21+
let foo_module = module.getattr("foo").unwrap();
2222

2323
b.iter(|| {
2424
for _ in 0..1000 {
25-
foo.call0().unwrap();
25+
foo_module.call0().unwrap();
2626
}
2727
});
2828
})
@@ -38,11 +38,11 @@ fn bench_call_method_0(b: &mut Bencher) {
3838
"#
3939
);
4040

41-
let foo = module.getattr("Foo").unwrap().call0().unwrap();
41+
let foo_module = module.getattr("Foo").unwrap().call0().unwrap();
4242

4343
b.iter(|| {
4444
for _ in 0..1000 {
45-
foo.call_method0("foo").unwrap();
45+
foo_module.call_method0("foo").unwrap();
4646
}
4747
});
4848
})

build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ fn emit_cargo_configuration(interpreter_config: &InterpreterConfig) -> Result<()
108108
match (is_extension_module, target_os.as_str()) {
109109
(_, "windows") => {
110110
// always link on windows, even with extension module
111-
println!("{}", get_rustc_link_lib(&interpreter_config)?);
111+
println!("{}", get_rustc_link_lib(interpreter_config)?);
112112
// Set during cross-compiling.
113113
if let Some(libdir) = &interpreter_config.libdir {
114114
println!("cargo:rustc-link-search=native={}", libdir);
@@ -126,7 +126,7 @@ fn emit_cargo_configuration(interpreter_config: &InterpreterConfig) -> Result<()
126126
(false, _) | (_, "android") => {
127127
// other systems, only link libs if not extension module
128128
// android always link.
129-
println!("{}", get_rustc_link_lib(&interpreter_config)?);
129+
println!("{}", get_rustc_link_lib(interpreter_config)?);
130130
if let Some(libdir) = &interpreter_config.libdir {
131131
println!("cargo:rustc-link-search=native={}", libdir);
132132
}

pyo3-build-config/src/impl_.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ impl BuildFlags {
431431
script.push_str(&format!("print(config.get('{}', '0'))\n", k));
432432
}
433433

434-
let stdout = run_python_script(&interpreter, &script)?;
434+
let stdout = run_python_script(interpreter, &script)?;
435435
let split_stdout: Vec<&str> = stdout.trim_end().lines().collect();
436436
ensure!(
437437
split_stdout.len() == BuildFlags::ALL.len(),
@@ -573,7 +573,7 @@ fn ends_with(entry: &DirEntry, pat: &str) -> bool {
573573
///
574574
/// [1]: https://github.com/python/cpython/blob/3.5/Lib/sysconfig.py#L389
575575
fn find_sysconfigdata(cross: &CrossCompileConfig) -> Result<PathBuf> {
576-
let sysconfig_paths = search_lib_dir(&cross.lib_dir, &cross);
576+
let sysconfig_paths = search_lib_dir(&cross.lib_dir, cross);
577577
let sysconfig_name = env_var("_PYTHON_SYSCONFIGDATA_NAME");
578578
let mut sysconfig_paths = sysconfig_paths
579579
.iter()

pyo3-macros-backend/src/from_pyobject.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl<'a> Container<'a> {
186186
/// Build derivation body for a struct.
187187
fn build(&self) -> TokenStream {
188188
match &self.ty {
189-
ContainerType::StructNewtype(ident) => self.build_newtype_struct(Some(&ident)),
189+
ContainerType::StructNewtype(ident) => self.build_newtype_struct(Some(ident)),
190190
ContainerType::TupleNewtype => self.build_newtype_struct(None),
191191
ContainerType::Tuple(len) => self.build_tuple_struct(*len),
192192
ContainerType::Struct(tups) => self.build_struct(tups),

pyo3-macros-backend/src/method.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ impl<'a> FnSpec<'a> {
266266
let python_name = python_name.as_ref().unwrap_or(name).unraw();
267267

268268
let doc = utils::get_doc(
269-
&meth_attrs,
269+
meth_attrs,
270270
options
271271
.text_signature
272272
.as_ref()
@@ -413,7 +413,7 @@ impl<'a> FnSpec<'a> {
413413
Argument::Arg(path, opt) | Argument::Kwarg(path, opt) => {
414414
if path.is_ident(name) {
415415
if let Some(val) = opt {
416-
let i: syn::Expr = syn::parse_str(&val).unwrap();
416+
let i: syn::Expr = syn::parse_str(val).unwrap();
417417
return Some(i.into_token_stream());
418418
}
419419
}

pyo3-macros-backend/src/params.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn accept_args_kwargs(attrs: &[Argument]) -> (bool, bool) {
2929

3030
/// Return true if the argument list is simply (*args, **kwds).
3131
pub fn is_forwarded_args(args: &[FnArg<'_>], attrs: &[Argument]) -> bool {
32-
args.len() == 2 && is_args(attrs, &args[0].name) && is_kwargs(attrs, &args[1].name)
32+
args.len() == 2 && is_args(attrs, args[0].name) && is_kwargs(attrs, args[1].name)
3333
}
3434

3535
fn is_args(attrs: &[Argument], name: &syn::Ident) -> bool {
@@ -70,7 +70,7 @@ pub fn impl_arg_params(
7070
for (i, arg) in spec.args.iter().enumerate() {
7171
arg_convert.push(impl_arg_param(
7272
arg,
73-
&spec,
73+
spec,
7474
i,
7575
None,
7676
&mut 0,
@@ -90,12 +90,12 @@ pub fn impl_arg_params(
9090
let mut keyword_only_parameters = Vec::new();
9191

9292
for arg in spec.args.iter() {
93-
if arg.py || is_args(&spec.attrs, &arg.name) || is_kwargs(&spec.attrs, &arg.name) {
93+
if arg.py || is_args(&spec.attrs, arg.name) || is_kwargs(&spec.attrs, arg.name) {
9494
continue;
9595
}
9696
let name = arg.name.unraw().to_string();
97-
let kwonly = spec.is_kw_only(&arg.name);
98-
let required = !(arg.optional.is_some() || spec.default_value(&arg.name).is_some());
97+
let kwonly = spec.is_kw_only(arg.name);
98+
let required = !(arg.optional.is_some() || spec.default_value(arg.name).is_some());
9999

100100
if kwonly {
101101
keyword_only_parameters.push(quote! {
@@ -118,8 +118,8 @@ pub fn impl_arg_params(
118118
let mut option_pos = 0;
119119
for (idx, arg) in spec.args.iter().enumerate() {
120120
param_conversion.push(impl_arg_param(
121-
&arg,
122-
&spec,
121+
arg,
122+
spec,
123123
idx,
124124
self_,
125125
&mut option_pos,
@@ -212,15 +212,15 @@ fn impl_arg_param(
212212
|e| pyo3::derive_utils::argument_extraction_error(#py, stringify!(#name), e)
213213
};
214214

215-
if is_args(&spec.attrs, &name) {
215+
if is_args(&spec.attrs, name) {
216216
ensure_spanned!(
217217
arg.optional.is_none(),
218218
arg.name.span() => "args cannot be optional"
219219
);
220220
return Ok(quote_arg_span! {
221221
let #arg_name = _args.unwrap().extract().map_err(#transform_error)?;
222222
});
223-
} else if is_kwargs(&spec.attrs, &name) {
223+
} else if is_kwargs(&spec.attrs, name) {
224224
ensure_spanned!(
225225
arg.optional.is_some(),
226226
arg.name.span() => "kwargs must be Option<_>"
@@ -259,7 +259,7 @@ fn impl_arg_param(
259259
}
260260
};
261261

262-
return if let syn::Type::Reference(tref) = unwrap_ty_group(arg.optional.unwrap_or(&ty)) {
262+
return if let syn::Type::Reference(tref) = unwrap_ty_group(arg.optional.unwrap_or(ty)) {
263263
let (tref, mut_) = preprocess_tref(tref, self_);
264264
let (target_ty, borrow_tmp) = if arg.optional.is_some() {
265265
// Get Option<&T> from Option<PyRef<T>>

pyo3-macros-backend/src/pyclass.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ pub fn build_py_class(
262262

263263
impl_class(
264264
&class.ident,
265-
&args,
265+
args,
266266
doc,
267267
field_options,
268268
methods_type,
@@ -452,7 +452,7 @@ fn impl_class(
452452
let (impl_inventory, for_each_py_method) = match methods_type {
453453
PyClassMethodsType::Specialization => (None, quote! { visitor(collector.py_methods()); }),
454454
PyClassMethodsType::Inventory => (
455-
Some(impl_methods_inventory(&cls)),
455+
Some(impl_methods_inventory(cls)),
456456
quote! {
457457
for inventory in pyo3::inventory::iter::<<Self as pyo3::class::impl_::HasMethodsInventory>::Methods>() {
458458
visitor(pyo3::class::impl_::PyMethodsInventory::get(inventory));

pyo3-macros-backend/src/pymethod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ pub fn impl_py_getter_def(cls: &syn::Type, property_type: PropertyType) -> Resul
303303
fn split_off_python_arg<'a>(args: &'a [FnArg<'a>]) -> (Option<&FnArg>, &[FnArg]) {
304304
if args
305305
.get(0)
306-
.map(|py| utils::is_python(&py.ty))
306+
.map(|py| utils::is_python(py.ty))
307307
.unwrap_or(false)
308308
{
309309
(Some(&args[0]), &args[1..])

src/buffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ mod tests {
666666
let gil = Python::acquire_gil();
667667
let py = gil.python();
668668
let bytes = py.eval("b'abcde'", None, None).unwrap();
669-
let buffer = PyBuffer::get(&bytes).unwrap();
669+
let buffer = PyBuffer::get(bytes).unwrap();
670670
assert_eq!(buffer.dimensions(), 1);
671671
assert_eq!(buffer.item_count(), 5);
672672
assert_eq!(buffer.format().to_str().unwrap(), "B");

src/conversions/osstr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl IntoPy<PyObject> for &'_ OsStr {
121121
impl ToPyObject for Cow<'_, OsStr> {
122122
#[inline]
123123
fn to_object(&self, py: Python) -> PyObject {
124-
(&self as &OsStr).to_object(py)
124+
(self as &OsStr).to_object(py)
125125
}
126126
}
127127

@@ -135,7 +135,7 @@ impl IntoPy<PyObject> for Cow<'_, OsStr> {
135135
impl ToPyObject for OsString {
136136
#[inline]
137137
fn to_object(&self, py: Python) -> PyObject {
138-
(&self as &OsStr).to_object(py)
138+
(self as &OsStr).to_object(py)
139139
}
140140
}
141141

src/exceptions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,15 +402,15 @@ mod tests {
402402
let error_type = py.get_type::<CustomError>();
403403
let ctx = [("CustomError", error_type)].into_py_dict(py);
404404
let type_description: String = py
405-
.eval("str(CustomError)", None, Some(&ctx))
405+
.eval("str(CustomError)", None, Some(ctx))
406406
.unwrap()
407407
.extract()
408408
.unwrap();
409409
assert_eq!(type_description, "<class 'mymodule.CustomError'>");
410410
py.run(
411411
"assert CustomError('oops').args == ('oops',)",
412412
None,
413-
Some(&ctx),
413+
Some(ctx),
414414
)
415415
.unwrap();
416416
}

src/types/dict.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ mod tests {
724724
assert_eq!(iter.size_hint(), (v.len() - 1, Some(v.len() - 1)));
725725

726726
// Exhust iterator.
727-
while let Some(_) = iter.next() {}
727+
for _ in &mut iter { }
728728

729729
assert_eq!(iter.size_hint(), (0, Some(0)));
730730
}

src/types/list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ mod tests {
366366
assert_eq!(iter.size_hint(), (v.len() - 1, Some(v.len() - 1)));
367367

368368
// Exhust iterator.
369-
while let Some(_) = iter.next() {}
369+
for _ in &mut iter { }
370370

371371
assert_eq!(iter.size_hint(), (0, Some(0)));
372372
}

src/types/sequence.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ mod tests {
541541
let v: Vec<i32> = vec![1, 2, 3];
542542
let ob = v.to_object(py);
543543
let seq = ob.cast_as::<PySequence>(py).unwrap();
544-
let concat_seq = seq.concat(&seq).unwrap();
544+
let concat_seq = seq.concat(seq).unwrap();
545545
assert_eq!(6, concat_seq.len().unwrap());
546546
let concat_v: Vec<i32> = vec![1, 2, 3, 1, 2, 3];
547547
for (el, cc) in concat_seq.iter().unwrap().zip(concat_v) {
@@ -556,7 +556,7 @@ mod tests {
556556
let v = "string";
557557
let ob = v.to_object(py);
558558
let seq = ob.cast_as::<PySequence>(py).unwrap();
559-
let concat_seq = seq.concat(&seq).unwrap();
559+
let concat_seq = seq.concat(seq).unwrap();
560560
assert_eq!(12, concat_seq.len().unwrap());
561561
/*let concat_v = "stringstring".to_owned();
562562
for (el, cc) in seq.iter(py).unwrap().zip(concat_v.chars()) {

tests/test_compile_error.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,9 @@ fn test_compile_errors() {
1212
t.compile_fail("tests/ui/invalid_argument_attributes.rs");
1313
t.compile_fail("tests/ui/reject_generics.rs");
1414

15-
tests_rust_1_45(&t);
1615
tests_rust_1_48(&t);
1716
tests_rust_1_49(&t);
18-
tests_rust_1_52(&t);
19-
20-
#[rustversion::since(1.45)]
21-
fn tests_rust_1_45(t: &trybuild::TestCases) {
22-
t.compile_fail("tests/ui/static_ref.rs");
23-
}
24-
#[rustversion::before(1.45)]
25-
fn tests_rust_1_45(_t: &trybuild::TestCases) {}
17+
tests_rust_1_54(&t);
2618

2719
#[rustversion::since(1.48)]
2820
fn tests_rust_1_48(t: &trybuild::TestCases) {
@@ -35,20 +27,21 @@ fn test_compile_errors() {
3527
#[rustversion::since(1.49)]
3628
fn tests_rust_1_49(t: &trybuild::TestCases) {
3729
t.compile_fail("tests/ui/deprecations.rs");
38-
t.compile_fail("tests/ui/invalid_frompy_derive.rs");
3930
t.compile_fail("tests/ui/invalid_pymethod_receiver.rs");
40-
t.compile_fail("tests/ui/pyclass_send.rs");
4131

4232
#[cfg(Py_LIMITED_API)]
4333
t.compile_fail("tests/ui/abi3_nativetype_inheritance.rs");
4434
}
4535
#[rustversion::before(1.49)]
4636
fn tests_rust_1_49(_t: &trybuild::TestCases) {}
4737

48-
#[rustversion::since(1.52)]
49-
fn tests_rust_1_52(t: &trybuild::TestCases) {
38+
#[rustversion::since(1.54)]
39+
fn tests_rust_1_54(t: &trybuild::TestCases) {
40+
t.compile_fail("tests/ui/invalid_frompy_derive.rs");
5041
t.compile_fail("tests/ui/invalid_result_conversion.rs");
42+
t.compile_fail("tests/ui/pyclass_send.rs");
43+
t.compile_fail("tests/ui/static_ref.rs");
5144
}
52-
#[rustversion::before(1.52)]
53-
fn tests_rust_1_52(_t: &trybuild::TestCases) {}
45+
#[rustversion::before(1.54)]
46+
fn tests_rust_1_54(_t: &trybuild::TestCases) {}
5447
}

tests/test_datetime.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ fn _get_subclasses<'p>(
1717

1818
let make_sub_subclass_py = "class SubSubklass(Subklass):\n pass";
1919

20-
py.run(&make_subclass_py, None, Some(&locals))?;
21-
py.run(&make_sub_subclass_py, None, Some(&locals))?;
20+
py.run(&make_subclass_py, None, Some(locals))?;
21+
py.run(make_sub_subclass_py, None, Some(locals))?;
2222

2323
// Construct an instance of the base class
24-
let obj = py.eval(&format!("{}({})", py_type, args), None, Some(&locals))?;
24+
let obj = py.eval(&format!("{}({})", py_type, args), None, Some(locals))?;
2525

2626
// Construct an instance of the subclass
27-
let sub_obj = py.eval(&format!("Subklass({})", args), None, Some(&locals))?;
27+
let sub_obj = py.eval(&format!("Subklass({})", args), None, Some(locals))?;
2828

2929
// Construct an instance of the sub-subclass
30-
let sub_sub_obj = py.eval(&format!("SubSubklass({})", args), None, Some(&locals))?;
30+
let sub_sub_obj = py.eval(&format!("SubSubklass({})", args), None, Some(locals))?;
3131

3232
Ok((obj, sub_obj, sub_sub_obj))
3333
}

tests/ui/invalid_frompy_derive.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ error: cannot derive FromPyObject for empty structs and variants
168168
151 | #[derive(FromPyObject)]
169169
| ^^^^^^^^^^^^
170170
|
171-
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
171+
= note: this error originates in the derive macro `FromPyObject` (in Nightly builds, run with -Z macro-backtrace for more info)
172172

173173
error: expected `=`
174174
--> $DIR/invalid_frompy_derive.rs:158:11

tests/ui/invalid_result_conversion.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ error[E0277]: the trait bound `Result<(), MyError>: IntoPyCallbackOutput<_>` is
1111
|
1212
= help: the following implementations were found:
1313
<Result<T, E> as IntoPyCallbackOutput<U>>
14-
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
14+
= note: this error originates in the attribute macro `pyfunction` (in Nightly builds, run with -Z macro-backtrace for more info)

tests/ui/pyclass_send.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ note: required because it appears within the type `NotThreadSafe`
1515
|
1616
5 | struct NotThreadSafe {
1717
| ^^^^^^^^^^^^^
18-
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
18+
= note: this error originates in the attribute macro `pyclass` (in Nightly builds, run with -Z macro-backtrace for more info)

tests/ui/static_ref.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ note: ...so that reference does not outlive borrowed content
2222
|
2323
4 | #[pyfunction]
2424
| ^^^^^^^^^^^^^
25-
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
25+
= note: this error originates in the attribute macro `pyfunction` (in Nightly builds, run with -Z macro-backtrace for more info)

0 commit comments

Comments
 (0)