Skip to content

Commit 1c12a80

Browse files
authored
Merge pull request RustPython#2392 from RustPython/fix-clippy-1.49
Fix clippy lints for Rust 1.49
2 parents 3dbe94c + be40a5d commit 1c12a80

File tree

13 files changed

+69
-87
lines changed

13 files changed

+69
-87
lines changed

bytecode/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ impl<C: Constant> CodeObject<C> {
657657
Ok(())
658658
}
659659

660-
pub fn display_expand_codeobjects<'a>(&'a self) -> impl fmt::Display + 'a {
660+
pub fn display_expand_codeobjects(&self) -> impl fmt::Display + '_ {
661661
struct Display<'a, C: Constant>(&'a CodeObject<C>);
662662
impl<C: Constant> fmt::Display for Display<'_, C> {
663663
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {

parser/src/lexer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub fn get_keywords() -> HashMap<String, Tok> {
116116
pub type Spanned = (Location, Tok, Location);
117117
pub type LexResult = Result<Spanned, LexicalError>;
118118

119-
pub fn make_tokenizer<'a>(source: &'a str) -> impl Iterator<Item = LexResult> + 'a {
119+
pub fn make_tokenizer(source: &str) -> impl Iterator<Item = LexResult> + '_ {
120120
let nlh = NewlineHandler::new(source.chars());
121121
Lexer::new(nlh)
122122
}

src/lib.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -297,15 +297,18 @@ fn parse_arguments<'a>(app: App<'a, '_>) -> ArgMatches<'a> {
297297
/// Create settings by examining command line arguments and environment
298298
/// variables.
299299
fn create_settings(matches: &ArgMatches) -> PySettings {
300-
let mut settings = PySettings::default();
301-
settings.isolated = matches.is_present("isolate");
302-
settings.ignore_environment = matches.is_present("ignore-environment");
300+
let mut settings = PySettings {
301+
isolated: matches.is_present("isolate"),
302+
ignore_environment: matches.is_present("ignore-environment"),
303+
interactive: !matches.is_present("c")
304+
&& !matches.is_present("m")
305+
&& (!matches.is_present("script") || matches.is_present("inspect")),
306+
bytes_warning: matches.occurrences_of("bytes-warning"),
307+
no_site: matches.is_present("no-site"),
308+
..Default::default()
309+
};
303310
let ignore_environment = settings.ignore_environment || settings.isolated;
304311

305-
settings.interactive = !matches.is_present("c")
306-
&& !matches.is_present("m")
307-
&& (!matches.is_present("script") || matches.is_present("inspect"));
308-
309312
// add the current directory to sys.path
310313
settings.path_list.push("".to_owned());
311314

@@ -352,10 +355,6 @@ fn create_settings(matches: &ArgMatches) -> PySettings {
352355
}
353356
}
354357

355-
settings.bytes_warning = matches.occurrences_of("bytes-warning");
356-
357-
settings.no_site = matches.is_present("no-site");
358-
359358
if matches.is_present("no-user-site")
360359
|| matches.is_present("isolate")
361360
|| (!ignore_environment && env::var_os("PYTHONNOUSERSITE").is_some())

vm/src/anystr.rs

+23-41
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,15 @@ use num_traits::{cast::ToPrimitive, sign::Signed};
99
use std::str::FromStr;
1010

1111
#[derive(FromArgs)]
12-
pub struct SplitArgs<'a, T, S, E>
13-
where
14-
T: TryFromObject + AnyStrWrapper<S>,
15-
S: ?Sized + AnyStr<'a, E>,
16-
E: Copy,
17-
{
12+
pub struct SplitArgs<'s, T: TryFromObject + AnyStrWrapper<'s>> {
1813
#[pyarg(any, default)]
1914
sep: Option<T>,
2015
#[pyarg(any, default = "-1")]
2116
maxsplit: isize,
22-
_phantom1: std::marker::PhantomData<&'a S>,
23-
_phantom2: std::marker::PhantomData<E>,
17+
_phantom: std::marker::PhantomData<&'s ()>,
2418
}
2519

26-
impl<'a, T, S, E> SplitArgs<'a, T, S, E>
27-
where
28-
T: TryFromObject + AnyStrWrapper<S>,
29-
S: ?Sized + AnyStr<'a, E>,
30-
E: Copy,
31-
{
20+
impl<'s, T: TryFromObject + AnyStrWrapper<'s>> SplitArgs<'s, T> {
3221
pub fn get_value(self, vm: &VirtualMachine) -> PyResult<(Option<T>, isize)> {
3322
let sep = if let Some(s) = self.sep {
3423
let sep = s.as_ref();
@@ -124,11 +113,9 @@ impl StringRange for std::ops::Range<usize> {
124113
}
125114
}
126115

127-
pub trait AnyStrWrapper<S>
128-
where
129-
S: ?Sized,
130-
{
131-
fn as_ref(&self) -> &S;
116+
pub trait AnyStrWrapper<'s> {
117+
type Str: ?Sized + AnyStr<'s>;
118+
fn as_ref(&self) -> &Self::Str;
132119
}
133120

134121
pub trait AnyStrContainer<S>
@@ -140,28 +127,23 @@ where
140127
fn push_str(&mut self, s: &S);
141128
}
142129

143-
pub trait AnyStr<'s, E>
144-
where
145-
E: Copy,
146-
Self: 's,
147-
Self::Container: AnyStrContainer<Self> + std::iter::Extend<E>,
148-
Self::CharIter: 's + std::iter::Iterator<Item = char>,
149-
Self::ElementIter: 's + std::iter::Iterator<Item = E>,
150-
{
151-
type Container;
152-
type CharIter;
153-
type ElementIter;
130+
// TODO: GATs for `'s` once stabilized
131+
pub trait AnyStr<'s>: 's {
132+
type Char: Copy;
133+
type Container: AnyStrContainer<Self> + Extend<Self::Char>;
134+
type CharIter: Iterator<Item = char> + 's;
135+
type ElementIter: Iterator<Item = Self::Char> + 's;
154136

155-
fn element_bytes_len(c: E) -> usize;
137+
fn element_bytes_len(c: Self::Char) -> usize;
156138

157139
fn to_container(&self) -> Self::Container;
158140
fn as_bytes(&self) -> &[u8];
159141
fn as_utf8_str(&self) -> Result<&str, std::str::Utf8Error>;
160142
fn chars(&'s self) -> Self::CharIter;
161143
fn elements(&'s self) -> Self::ElementIter;
162-
fn get_bytes<'a>(&'a self, range: std::ops::Range<usize>) -> &'a Self;
144+
fn get_bytes(&self, range: std::ops::Range<usize>) -> &Self;
163145
// FIXME: get_chars is expensive for str
164-
fn get_chars<'a>(&'a self, range: std::ops::Range<usize>) -> &'a Self;
146+
fn get_chars(&self, range: std::ops::Range<usize>) -> &Self;
165147
fn bytes_len(&self) -> usize;
166148
// fn chars_len(&self) -> usize; // cannot access to cache here
167149
fn is_empty(&self) -> bool;
@@ -175,14 +157,14 @@ where
175157

176158
fn py_split<T, SP, SN, SW, R>(
177159
&self,
178-
args: SplitArgs<'s, T, Self, E>,
160+
args: SplitArgs<'s, T>,
179161
vm: &VirtualMachine,
180162
split: SP,
181163
splitn: SN,
182164
splitw: SW,
183165
) -> PyResult<Vec<R>>
184166
where
185-
T: TryFromObject + AnyStrWrapper<Self>,
167+
T: TryFromObject + AnyStrWrapper<'s, Str = Self>,
186168
SP: Fn(&Self, &Self, &VirtualMachine) -> Vec<R>,
187169
SN: Fn(&Self, &Self, usize, &VirtualMachine) -> Vec<R>,
188170
SW: Fn(&Self, isize, &VirtualMachine) -> Vec<R>,
@@ -249,7 +231,7 @@ where
249231
func_default: FD,
250232
) -> &'a Self
251233
where
252-
S: AnyStrWrapper<Self>,
234+
S: AnyStrWrapper<'s, Str = Self>,
253235
FC: Fn(&'a Self, &Self) -> &'a Self,
254236
FD: Fn(&'a Self) -> &'a Self,
255237
{
@@ -286,7 +268,7 @@ where
286268
}
287269
}
288270

289-
fn py_pad(&self, left: usize, right: usize, fillchar: E) -> Self::Container {
271+
fn py_pad(&self, left: usize, right: usize, fillchar: Self::Char) -> Self::Container {
290272
let mut u = Self::Container::with_capacity(
291273
(left + right) * Self::element_bytes_len(fillchar) + self.bytes_len(),
292274
);
@@ -296,23 +278,23 @@ where
296278
u
297279
}
298280

299-
fn py_center(&self, width: usize, fillchar: E, len: usize) -> Self::Container {
281+
fn py_center(&self, width: usize, fillchar: Self::Char, len: usize) -> Self::Container {
300282
let marg = width - len;
301283
let left = marg / 2 + (marg & width & 1);
302284
self.py_pad(left, marg - left, fillchar)
303285
}
304286

305-
fn py_ljust(&self, width: usize, fillchar: E, len: usize) -> Self::Container {
287+
fn py_ljust(&self, width: usize, fillchar: Self::Char, len: usize) -> Self::Container {
306288
self.py_pad(0, width - len, fillchar)
307289
}
308290

309-
fn py_rjust(&self, width: usize, fillchar: E, len: usize) -> Self::Container {
291+
fn py_rjust(&self, width: usize, fillchar: Self::Char, len: usize) -> Self::Container {
310292
self.py_pad(width - len, 0, fillchar)
311293
}
312294

313295
fn py_join<'a>(
314296
&self,
315-
mut iter: PyIterator<'a, impl AnyStrWrapper<Self> + TryFromObject>,
297+
mut iter: PyIterator<'a, impl AnyStrWrapper<'s, Str = Self> + TryFromObject>,
316298
) -> PyResult<Self::Container> {
317299
let mut joined = if let Some(elem) = iter.next() {
318300
elem?.as_ref().to_container()

vm/src/builtins/pystr.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ impl PyStr {
876876
fillchar: OptionalArg<PyStrRef>,
877877
vm: &VirtualMachine,
878878
) -> PyResult<String> {
879-
self._pad(width, fillchar, AnyStr::<char>::py_center, vm)
879+
self._pad(width, fillchar, AnyStr::py_center, vm)
880880
}
881881

882882
#[pymethod]
@@ -886,7 +886,7 @@ impl PyStr {
886886
fillchar: OptionalArg<PyStrRef>,
887887
vm: &VirtualMachine,
888888
) -> PyResult<String> {
889-
self._pad(width, fillchar, AnyStr::<char>::py_ljust, vm)
889+
self._pad(width, fillchar, AnyStr::py_ljust, vm)
890890
}
891891

892892
#[pymethod]
@@ -896,15 +896,15 @@ impl PyStr {
896896
fillchar: OptionalArg<PyStrRef>,
897897
vm: &VirtualMachine,
898898
) -> PyResult<String> {
899-
self._pad(width, fillchar, AnyStr::<char>::py_rjust, vm)
899+
self._pad(width, fillchar, AnyStr::py_rjust, vm)
900900
}
901901

902902
#[pymethod]
903903
fn expandtabs(&self, args: anystr::ExpandTabsArgs) -> String {
904904
let tab_stop = args.tabsize();
905905
let mut expanded_str = String::with_capacity(self.value.len());
906906
let mut tab_size = tab_stop;
907-
let mut col_count = 0 as usize;
907+
let mut col_count = 0usize;
908908
for ch in self.value.chars() {
909909
match ch {
910910
'\t' => {
@@ -1157,7 +1157,7 @@ impl TryFromObject for std::ffi::OsString {
11571157
}
11581158
}
11591159

1160-
type SplitArgs<'a> = anystr::SplitArgs<'a, PyStrRef, str, char>;
1160+
type SplitArgs<'a> = anystr::SplitArgs<'a, PyStrRef>;
11611161

11621162
#[derive(FromArgs)]
11631163
pub struct FindArgs {
@@ -1338,7 +1338,8 @@ mod tests {
13381338
}
13391339
}
13401340

1341-
impl AnyStrWrapper<str> for PyStrRef {
1341+
impl<'s> AnyStrWrapper<'s> for PyStrRef {
1342+
type Str = str;
13421343
fn as_ref(&self) -> &str {
13431344
&*self.value
13441345
}
@@ -1358,7 +1359,8 @@ impl AnyStrContainer<str> for String {
13581359
}
13591360
}
13601361

1361-
impl<'s> AnyStr<'s, char> for str {
1362+
impl<'s> AnyStr<'s> for str {
1363+
type Char = char;
13621364
type Container = String;
13631365
type CharIter = std::str::Chars<'s>;
13641366
type ElementIter = std::str::Chars<'s>;
@@ -1387,11 +1389,11 @@ impl<'s> AnyStr<'s, char> for str {
13871389
str::chars(self)
13881390
}
13891391

1390-
fn get_bytes<'a>(&'a self, range: std::ops::Range<usize>) -> &'a Self {
1392+
fn get_bytes(&self, range: std::ops::Range<usize>) -> &Self {
13911393
&self[range]
13921394
}
13931395

1394-
fn get_chars<'a>(&'a self, range: std::ops::Range<usize>) -> &'a Self {
1396+
fn get_chars(&self, range: std::ops::Range<usize>) -> &Self {
13951397
rustpython_common::str::get_chars(self, range)
13961398
}
13971399

vm/src/builtins/pytype.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ fn calculate_meta_class(
864864
Ok(winner)
865865
}
866866

867-
fn best_base<'a>(bases: &'a [PyTypeRef], vm: &VirtualMachine) -> PyResult<PyTypeRef> {
867+
fn best_base(bases: &[PyTypeRef], vm: &VirtualMachine) -> PyResult<PyTypeRef> {
868868
// let mut base = None;
869869
// let mut winner = None;
870870

vm/src/builtins/traceback.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl PyTraceback {
5353
}
5454

5555
impl PyTracebackRef {
56-
pub fn iter<'a>(&'a self) -> impl Iterator<Item = PyTracebackRef> + 'a {
56+
pub fn iter(&self) -> impl Iterator<Item = PyTracebackRef> {
5757
std::iter::successors(Some(self.clone()), |tb| tb.next.clone())
5858
}
5959
}

vm/src/bytesinner.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl ByteInnerTranslateOptions {
227227
}
228228
}
229229

230-
pub type ByteInnerSplitOptions<'a> = anystr::SplitArgs<'a, PyBytesInner, [u8], u8>;
230+
pub type ByteInnerSplitOptions<'a> = anystr::SplitArgs<'a, PyBytesInner>;
231231

232232
#[allow(clippy::len_without_is_empty)]
233233
impl PyBytesInner {
@@ -468,23 +468,23 @@ impl PyBytesInner {
468468
options: ByteInnerPaddingOptions,
469469
vm: &VirtualMachine,
470470
) -> PyResult<Vec<u8>> {
471-
self._pad(options, AnyStr::<u8>::py_center, vm)
471+
self._pad(options, AnyStr::py_center, vm)
472472
}
473473

474474
pub fn ljust(
475475
&self,
476476
options: ByteInnerPaddingOptions,
477477
vm: &VirtualMachine,
478478
) -> PyResult<Vec<u8>> {
479-
self._pad(options, AnyStr::<u8>::py_ljust, vm)
479+
self._pad(options, AnyStr::py_ljust, vm)
480480
}
481481

482482
pub fn rjust(
483483
&self,
484484
options: ByteInnerPaddingOptions,
485485
vm: &VirtualMachine,
486486
) -> PyResult<Vec<u8>> {
487-
self._pad(options, AnyStr::<u8>::py_rjust, vm)
487+
self._pad(options, AnyStr::py_rjust, vm)
488488
}
489489

490490
pub fn count(&self, options: ByteInnerFindOptions, vm: &VirtualMachine) -> PyResult<usize> {
@@ -938,7 +938,8 @@ pub trait ByteOr: ToPrimitive {
938938

939939
impl ByteOr for BigInt {}
940940

941-
impl AnyStrWrapper<[u8]> for PyBytesInner {
941+
impl<'s> AnyStrWrapper<'s> for PyBytesInner {
942+
type Str = [u8];
942943
fn as_ref(&self) -> &[u8] {
943944
&self.elements
944945
}
@@ -960,7 +961,8 @@ impl AnyStrContainer<[u8]> for Vec<u8> {
960961

961962
const ASCII_WHITESPACES: [u8; 6] = [0x20, 0x09, 0x0a, 0x0c, 0x0d, 0x0b];
962963

963-
impl<'s> AnyStr<'s, u8> for [u8] {
964+
impl<'s> AnyStr<'s> for [u8] {
965+
type Char = u8;
964966
type Container = Vec<u8>;
965967
type CharIter = bstr::Chars<'s>;
966968
type ElementIter = std::iter::Copied<std::slice::Iter<'s, u8>>;
@@ -989,11 +991,11 @@ impl<'s> AnyStr<'s, u8> for [u8] {
989991
self.iter().copied()
990992
}
991993

992-
fn get_bytes<'a>(&'a self, range: std::ops::Range<usize>) -> &'a Self {
994+
fn get_bytes(&self, range: std::ops::Range<usize>) -> &Self {
993995
&self[range]
994996
}
995997

996-
fn get_chars<'a>(&'a self, range: std::ops::Range<usize>) -> &'a Self {
998+
fn get_chars(&self, range: std::ops::Range<usize>) -> &Self {
997999
&self[range]
9981000
}
9991001

vm/src/function.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,7 @@ impl FuncArgs {
178178
self.kwargs.swap_remove(name)
179179
}
180180

181-
pub fn remaining_keywords<'a>(
182-
&'a mut self,
183-
) -> impl Iterator<Item = (String, PyObjectRef)> + 'a {
181+
pub fn remaining_keywords(&mut self) -> impl Iterator<Item = (String, PyObjectRef)> + '_ {
184182
self.kwargs.drain(..)
185183
}
186184

vm/src/pyobject.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1104,9 +1104,11 @@ pub trait PyClassImpl: PyClassDef {
11041104
fn extend_slots(slots: &mut PyTypeSlots);
11051105

11061106
fn make_slots() -> PyTypeSlots {
1107-
let mut slots = PyTypeSlots::default();
1108-
slots.flags = Self::TP_FLAGS;
1109-
slots.name = PyRwLock::new(Some(Self::TP_NAME.to_owned()));
1107+
let mut slots = PyTypeSlots {
1108+
flags: Self::TP_FLAGS,
1109+
name: PyRwLock::new(Some(Self::TP_NAME.to_owned())),
1110+
..Default::default()
1111+
};
11101112
Self::extend_slots(&mut slots);
11111113
slots
11121114
}

0 commit comments

Comments
 (0)