Fix clippy lints for Rust 1.49

This commit is contained in:
Noah committed 2021-01-02 19:30:57 -06:00
1 parent 8b31efb862
commit be40a5d7b9
13 files changed
+69 -87

No files matched your search

+1 -1
View File
@@ -657,7 +657,7 @@ impl<C: Constant> CodeObject<C> {
Ok(())
}
pub fn display_expand_codeobjects<'a>(&'a self) -> impl fmt::Display + 'a {
pub fn display_expand_codeobjects(&self) -> impl fmt::Display + '_ {
struct Display<'a, C: Constant>(&'a CodeObject<C>);
impl<C: Constant> fmt::Display for Display<'_, C> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+1 -1
View File
@@ -116,7 +116,7 @@ pub fn get_keywords() -> HashMap<String, Tok> {
pub type Spanned = (Location, Tok, Location);
pub type LexResult = Result<Spanned, LexicalError>;
pub fn make_tokenizer<'a>(source: &'a str) -> impl Iterator<Item = LexResult> + 'a {
pub fn make_tokenizer(source: &str) -> impl Iterator<Item = LexResult> + '_ {
let nlh = NewlineHandler::new(source.chars());
Lexer::new(nlh)
}
+10 -11
View File
@@ -297,15 +297,18 @@ fn parse_arguments<'a>(app: App<'a, '_>) -> ArgMatches<'a> {
/// Create settings by examining command line arguments and environment
/// variables.
fn create_settings(matches: &ArgMatches) -> PySettings {
let mut settings = PySettings::default();
settings.isolated = matches.is_present("isolate");
settings.ignore_environment = matches.is_present("ignore-environment");
let mut settings = PySettings {
isolated: matches.is_present("isolate"),
ignore_environment: matches.is_present("ignore-environment"),
interactive: !matches.is_present("c")
&& !matches.is_present("m")
&& (!matches.is_present("script") || matches.is_present("inspect")),
bytes_warning: matches.occurrences_of("bytes-warning"),
no_site: matches.is_present("no-site"),
..Default::default()
};
let ignore_environment = settings.ignore_environment || settings.isolated;
settings.interactive = !matches.is_present("c")
&& !matches.is_present("m")
&& (!matches.is_present("script") || matches.is_present("inspect"));
// add the current directory to sys.path
settings.path_list.push("".to_owned());
@@ -352,10 +355,6 @@ fn create_settings(matches: &ArgMatches) -> PySettings {
}
}
settings.bytes_warning = matches.occurrences_of("bytes-warning");
settings.no_site = matches.is_present("no-site");
if matches.is_present("no-user-site")
|| matches.is_present("isolate")
|| (!ignore_environment && env::var_os("PYTHONNOUSERSITE").is_some())
+23 -41
View File
@@ -9,26 +9,15 @@ use num_traits::{cast::ToPrimitive, sign::Signed};
use std::str::FromStr;
#[derive(FromArgs)]
pub struct SplitArgs<'a, T, S, E>
where
T: TryFromObject + AnyStrWrapper<S>,
S: ?Sized + AnyStr<'a, E>,
E: Copy,
{
pub struct SplitArgs<'s, T: TryFromObject + AnyStrWrapper<'s>> {
#[pyarg(any, default)]
sep: Option<T>,
#[pyarg(any, default = "-1")]
maxsplit: isize,
_phantom1: std::marker::PhantomData<&'a S>,
_phantom2: std::marker::PhantomData<E>,
_phantom: std::marker::PhantomData<&'s ()>,
}
impl<'a, T, S, E> SplitArgs<'a, T, S, E>
where
T: TryFromObject + AnyStrWrapper<S>,
S: ?Sized + AnyStr<'a, E>,
E: Copy,
{
impl<'s, T: TryFromObject + AnyStrWrapper<'s>> SplitArgs<'s, T> {
pub fn get_value(self, vm: &VirtualMachine) -> PyResult<(Option<T>, isize)> {
let sep = if let Some(s) = self.sep {
let sep = s.as_ref();
@@ -124,11 +113,9 @@ impl StringRange for std::ops::Range<usize> {
}
}
pub trait AnyStrWrapper<S>
where
S: ?Sized,
{
fn as_ref(&self) -> &S;
pub trait AnyStrWrapper<'s> {
type Str: ?Sized + AnyStr<'s>;
fn as_ref(&self) -> &Self::Str;
}
pub trait AnyStrContainer<S>
@@ -140,28 +127,23 @@ where
fn push_str(&mut self, s: &S);
}
pub trait AnyStr<'s, E>
where
E: Copy,
Self: 's,
Self::Container: AnyStrContainer<Self> + std::iter::Extend<E>,
Self::CharIter: 's + std::iter::Iterator<Item = char>,
Self::ElementIter: 's + std::iter::Iterator<Item = E>,
{
type Container;
type CharIter;
type ElementIter;
// TODO: GATs for `'s` once stabilized
pub trait AnyStr<'s>: 's {
type Char: Copy;
type Container: AnyStrContainer<Self> + Extend<Self::Char>;
type CharIter: Iterator<Item = char> + 's;
type ElementIter: Iterator<Item = Self::Char> + 's;
fn element_bytes_len(c: E) -> usize;
fn element_bytes_len(c: Self::Char) -> usize;
fn to_container(&self) -> Self::Container;
fn as_bytes(&self) -> &[u8];
fn as_utf8_str(&self) -> Result<&str, std::str::Utf8Error>;
fn chars(&'s self) -> Self::CharIter;
fn elements(&'s self) -> Self::ElementIter;
fn get_bytes<'a>(&'a self, range: std::ops::Range<usize>) -> &'a Self;
fn get_bytes(&self, range: std::ops::Range<usize>) -> &Self;
// FIXME: get_chars is expensive for str
fn get_chars<'a>(&'a self, range: std::ops::Range<usize>) -> &'a Self;
fn get_chars(&self, range: std::ops::Range<usize>) -> &Self;
fn bytes_len(&self) -> usize;
// fn chars_len(&self) -> usize; // cannot access to cache here
fn is_empty(&self) -> bool;
@@ -175,14 +157,14 @@ where
fn py_split<T, SP, SN, SW, R>(
&self,
args: SplitArgs<'s, T, Self, E>,
args: SplitArgs<'s, T>,
vm: &VirtualMachine,
split: SP,
splitn: SN,
splitw: SW,
) -> PyResult<Vec<R>>
where
T: TryFromObject + AnyStrWrapper<Self>,
T: TryFromObject + AnyStrWrapper<'s, Str = Self>,
SP: Fn(&Self, &Self, &VirtualMachine) -> Vec<R>,
SN: Fn(&Self, &Self, usize, &VirtualMachine) -> Vec<R>,
SW: Fn(&Self, isize, &VirtualMachine) -> Vec<R>,
@@ -249,7 +231,7 @@ where
func_default: FD,
) -> &'a Self
where
S: AnyStrWrapper<Self>,
S: AnyStrWrapper<'s, Str = Self>,
FC: Fn(&'a Self, &Self) -> &'a Self,
FD: Fn(&'a Self) -> &'a Self,
{
@@ -286,7 +268,7 @@ where
}
}
fn py_pad(&self, left: usize, right: usize, fillchar: E) -> Self::Container {
fn py_pad(&self, left: usize, right: usize, fillchar: Self::Char) -> Self::Container {
let mut u = Self::Container::with_capacity(
(left + right) * Self::element_bytes_len(fillchar) + self.bytes_len(),
);
@@ -296,23 +278,23 @@ where
u
}
fn py_center(&self, width: usize, fillchar: E, len: usize) -> Self::Container {
fn py_center(&self, width: usize, fillchar: Self::Char, len: usize) -> Self::Container {
let marg = width - len;
let left = marg / 2 + (marg & width & 1);
self.py_pad(left, marg - left, fillchar)
}
fn py_ljust(&self, width: usize, fillchar: E, len: usize) -> Self::Container {
fn py_ljust(&self, width: usize, fillchar: Self::Char, len: usize) -> Self::Container {
self.py_pad(0, width - len, fillchar)
}
fn py_rjust(&self, width: usize, fillchar: E, len: usize) -> Self::Container {
fn py_rjust(&self, width: usize, fillchar: Self::Char, len: usize) -> Self::Container {
self.py_pad(width - len, 0, fillchar)
}
fn py_join<'a>(
&self,
mut iter: PyIterator<'a, impl AnyStrWrapper<Self> + TryFromObject>,
mut iter: PyIterator<'a, impl AnyStrWrapper<'s, Str = Self> + TryFromObject>,
) -> PyResult<Self::Container> {
let mut joined = if let Some(elem) = iter.next() {
elem?.as_ref().to_container()
+11 -9
View File
@@ -876,7 +876,7 @@ impl PyStr {
fillchar: OptionalArg<PyStrRef>,
vm: &VirtualMachine,
) -> PyResult<String> {
self._pad(width, fillchar, AnyStr::<char>::py_center, vm)
self._pad(width, fillchar, AnyStr::py_center, vm)
}
#[pymethod]
@@ -886,7 +886,7 @@ impl PyStr {
fillchar: OptionalArg<PyStrRef>,
vm: &VirtualMachine,
) -> PyResult<String> {
self._pad(width, fillchar, AnyStr::<char>::py_ljust, vm)
self._pad(width, fillchar, AnyStr::py_ljust, vm)
}
#[pymethod]
@@ -896,7 +896,7 @@ impl PyStr {
fillchar: OptionalArg<PyStrRef>,
vm: &VirtualMachine,
) -> PyResult<String> {
self._pad(width, fillchar, AnyStr::<char>::py_rjust, vm)
self._pad(width, fillchar, AnyStr::py_rjust, vm)
}
#[pymethod]
@@ -904,7 +904,7 @@ impl PyStr {
let tab_stop = args.tabsize();
let mut expanded_str = String::with_capacity(self.value.len());
let mut tab_size = tab_stop;
let mut col_count = 0 as usize;
let mut col_count = 0usize;
for ch in self.value.chars() {
match ch {
'\t' => {
@@ -1157,7 +1157,7 @@ impl TryFromObject for std::ffi::OsString {
}
}
type SplitArgs<'a> = anystr::SplitArgs<'a, PyStrRef, str, char>;
type SplitArgs<'a> = anystr::SplitArgs<'a, PyStrRef>;
#[derive(FromArgs)]
pub struct FindArgs {
@@ -1338,7 +1338,8 @@ mod tests {
}
}
impl AnyStrWrapper<str> for PyStrRef {
impl<'s> AnyStrWrapper<'s> for PyStrRef {
type Str = str;
fn as_ref(&self) -> &str {
&*self.value
}
@@ -1358,7 +1359,8 @@ impl AnyStrContainer<str> for String {
}
}
impl<'s> AnyStr<'s, char> for str {
impl<'s> AnyStr<'s> for str {
type Char = char;
type Container = String;
type CharIter = std::str::Chars<'s>;
type ElementIter = std::str::Chars<'s>;
@@ -1387,11 +1389,11 @@ impl<'s> AnyStr<'s, char> for str {
str::chars(self)
}
fn get_bytes<'a>(&'a self, range: std::ops::Range<usize>) -> &'a Self {
fn get_bytes(&self, range: std::ops::Range<usize>) -> &Self {
&self[range]
}
fn get_chars<'a>(&'a self, range: std::ops::Range<usize>) -> &'a Self {
fn get_chars(&self, range: std::ops::Range<usize>) -> &Self {
rustpython_common::str::get_chars(self, range)
}
+1 -1
View File
@@ -864,7 +864,7 @@ fn calculate_meta_class(
Ok(winner)
}
fn best_base<'a>(bases: &'a [PyTypeRef], vm: &VirtualMachine) -> PyResult<PyTypeRef> {
fn best_base(bases: &[PyTypeRef], vm: &VirtualMachine) -> PyResult<PyTypeRef> {
// let mut base = None;
// let mut winner = None;
+1 -1
View File
@@ -53,7 +53,7 @@ impl PyTraceback {
}
impl PyTracebackRef {
pub fn iter<'a>(&'a self) -> impl Iterator<Item = PyTracebackRef> + 'a {
pub fn iter(&self) -> impl Iterator<Item = PyTracebackRef> {
std::iter::successors(Some(self.clone()), |tb| tb.next.clone())
}
}
+10 -8
View File
@@ -227,7 +227,7 @@ impl ByteInnerTranslateOptions {
}
}
pub type ByteInnerSplitOptions<'a> = anystr::SplitArgs<'a, PyBytesInner, [u8], u8>;
pub type ByteInnerSplitOptions<'a> = anystr::SplitArgs<'a, PyBytesInner>;
#[allow(clippy::len_without_is_empty)]
impl PyBytesInner {
@@ -468,7 +468,7 @@ impl PyBytesInner {
options: ByteInnerPaddingOptions,
vm: &VirtualMachine,
) -> PyResult<Vec<u8>> {
self._pad(options, AnyStr::<u8>::py_center, vm)
self._pad(options, AnyStr::py_center, vm)
}
pub fn ljust(
@@ -476,7 +476,7 @@ impl PyBytesInner {
options: ByteInnerPaddingOptions,
vm: &VirtualMachine,
) -> PyResult<Vec<u8>> {
self._pad(options, AnyStr::<u8>::py_ljust, vm)
self._pad(options, AnyStr::py_ljust, vm)
}
pub fn rjust(
@@ -484,7 +484,7 @@ impl PyBytesInner {
options: ByteInnerPaddingOptions,
vm: &VirtualMachine,
) -> PyResult<Vec<u8>> {
self._pad(options, AnyStr::<u8>::py_rjust, vm)
self._pad(options, AnyStr::py_rjust, vm)
}
pub fn count(&self, options: ByteInnerFindOptions, vm: &VirtualMachine) -> PyResult<usize> {
@@ -938,7 +938,8 @@ pub trait ByteOr: ToPrimitive {
impl ByteOr for BigInt {}
impl AnyStrWrapper<[u8]> for PyBytesInner {
impl<'s> AnyStrWrapper<'s> for PyBytesInner {
type Str = [u8];
fn as_ref(&self) -> &[u8] {
&self.elements
}
@@ -960,7 +961,8 @@ impl AnyStrContainer<[u8]> for Vec<u8> {
const ASCII_WHITESPACES: [u8; 6] = [0x20, 0x09, 0x0a, 0x0c, 0x0d, 0x0b];
impl<'s> AnyStr<'s, u8> for [u8] {
impl<'s> AnyStr<'s> for [u8] {
type Char = u8;
type Container = Vec<u8>;
type CharIter = bstr::Chars<'s>;
type ElementIter = std::iter::Copied<std::slice::Iter<'s, u8>>;
@@ -989,11 +991,11 @@ impl<'s> AnyStr<'s, u8> for [u8] {
self.iter().copied()
}
fn get_bytes<'a>(&'a self, range: std::ops::Range<usize>) -> &'a Self {
fn get_bytes(&self, range: std::ops::Range<usize>) -> &Self {
&self[range]
}
fn get_chars<'a>(&'a self, range: std::ops::Range<usize>) -> &'a Self {
fn get_chars(&self, range: std::ops::Range<usize>) -> &Self {
&self[range]
}
+1 -3
View File
@@ -178,9 +178,7 @@ impl FuncArgs {
self.kwargs.swap_remove(name)
}
pub fn remaining_keywords<'a>(
&'a mut self,
) -> impl Iterator<Item = (String, PyObjectRef)> + 'a {
pub fn remaining_keywords(&mut self) -> impl Iterator<Item = (String, PyObjectRef)> + '_ {
self.kwargs.drain(..)
}
+5 -3
View File
@@ -1104,9 +1104,11 @@ pub trait PyClassImpl: PyClassDef {
fn extend_slots(slots: &mut PyTypeSlots);
fn make_slots() -> PyTypeSlots {
let mut slots = PyTypeSlots::default();
slots.flags = Self::TP_FLAGS;
slots.name = PyRwLock::new(Some(Self::TP_NAME.to_owned()));
let mut slots = PyTypeSlots {
flags: Self::TP_FLAGS,
name: PyRwLock::new(Some(Self::TP_NAME.to_owned())),
..Default::default()
};
Self::extend_slots(&mut slots);
slots
}
+1 -4
View File
@@ -984,10 +984,7 @@ mod decl {
args: ProductArgs,
vm: &VirtualMachine,
) -> PyResult<PyRef<Self>> {
let repeat = match args.repeat.into_option() {
Some(i) => i,
None => 1,
};
let repeat = args.repeat.unwrap_or(1);
let mut pools = Vec::new();
for arg in iterables.into_iter() {
+1
View File
@@ -39,6 +39,7 @@ static ESCAPE_CHARS: [&str; 0x20] = [
// And which one need to be escaped (1)
// The characters that need escaping are 0x00 to 0x1F, 0x22 ("), 0x5C (\), 0x7F (DEL)
// Non-ASCII unicode characters can be safely included in a JSON string
#[allow(clippy::unusual_byte_groupings)] // it's groups of 16, come on clippy
static NEEDS_ESCAPING_BITSET: [u64; 4] = [
//fedcba9876543210_fedcba9876543210_fedcba9876543210_fedcba9876543210
0b0000000000000000_0000000000000100_1111111111111111_1111111111111111, // 3_2_1_0
+3 -4
View File
@@ -6,8 +6,6 @@ pub(crate) use decl::make_module;
// TODO: create main function when called with -m
#[pymodule(name = "tokenize")]
mod decl {
use std::iter::FromIterator;
use crate::builtins::pystr::PyStrRef;
use crate::pyobject::{BorrowValue, PyResult};
use crate::vm::VirtualMachine;
@@ -20,8 +18,9 @@ mod decl {
// TODO: implement generator when the time has come.
let lexer1 = lexer::make_tokenizer(source);
let tokens = lexer1.map(|st| vm.ctx.new_str(format!("{:?}", st.unwrap().1)));
let tokens = Vec::from_iter(tokens);
let tokens = lexer1
.map(|st| vm.ctx.new_str(format!("{:?}", st.unwrap().1)))
.collect();
Ok(vm.ctx.new_list(tokens))
}
}