Use Rust 1.75 toolchain (#9437)

This commit is contained in:
Micha Reiser 2024-01-08 18:03:16 +01:00 committed by GitHub
parent ba71772d93
commit 94968fedd5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 63 additions and 30 deletions

View file

@ -86,6 +86,7 @@ pub(crate) struct Cache {
changes: Mutex<Vec<Change>>, changes: Mutex<Vec<Change>>,
/// The "current" timestamp used as cache for the updates of /// The "current" timestamp used as cache for the updates of
/// [`FileCache::last_seen`] /// [`FileCache::last_seen`]
#[allow(clippy::struct_field_names)]
last_seen_cache: u64, last_seen_cache: u64,
} }

View file

@ -18,6 +18,7 @@ struct Explanation<'a> {
summary: &'a str, summary: &'a str,
message_formats: &'a [&'a str], message_formats: &'a [&'a str],
fix: String, fix: String,
#[allow(clippy::struct_field_names)]
explanation: Option<&'a str>, explanation: Option<&'a str>,
preview: bool, preview: bool,
} }

View file

@ -216,6 +216,7 @@ pub(crate) struct Args {
#[arg(long)] #[arg(long)]
pub(crate) files_with_errors: Option<u32>, pub(crate) files_with_errors: Option<u32>,
#[clap(flatten)] #[clap(flatten)]
#[allow(clippy::struct_field_names)]
pub(crate) log_level_args: LogLevelArgs, pub(crate) log_level_args: LogLevelArgs,
} }

View file

@ -367,7 +367,7 @@ pub(crate) fn fix_unnecessary_literal_dict(expr: &Expr, checker: &Checker) -> Re
comma, comma,
} = element } = element
{ {
if let Some(Element::Simple { value: key, .. }) = tuple.elements.get(0) { if let Some(Element::Simple { value: key, .. }) = tuple.elements.first() {
if let Some(Element::Simple { value, .. }) = tuple.elements.get(1) { if let Some(Element::Simple { value, .. }) = tuple.elements.get(1) {
return Ok(DictElement::Simple { return Ok(DictElement::Simple {
key: key.clone(), key: key.clone(),

View file

@ -134,7 +134,7 @@ pub(crate) fn multiple_starts_ends_with(checker: &mut Checker, expr: &Expr) {
format!("Indices should only contain `{attr_name}` calls") format!("Indices should only contain `{attr_name}` calls")
) )
}; };
args.get(0) args.first()
.unwrap_or_else(|| panic!("`{attr_name}` should have one argument")) .unwrap_or_else(|| panic!("`{attr_name}` should have one argument"))
}) })
.collect(); .collect();

View file

@ -379,7 +379,8 @@ pub(crate) fn duplicate_isinstance_call(checker: &mut Checker, expr: &Expr) {
.. ..
}) = &values[indices[0]] }) = &values[indices[0]]
{ {
args.get(0).expect("`isinstance` should have two arguments") args.first()
.expect("`isinstance` should have two arguments")
} else { } else {
unreachable!("Indices should only contain `isinstance` calls") unreachable!("Indices should only contain `isinstance` calls")
}; };

View file

@ -142,7 +142,7 @@ pub(crate) fn use_capital_environment_variables(checker: &mut Checker, expr: &Ex
else { else {
return; return;
}; };
let Some(arg) = args.get(0) else { let Some(arg) = args.first() else {
return; return;
}; };
let Expr::StringLiteral(ast::ExprStringLiteral { value: env_var, .. }) = arg else { let Expr::StringLiteral(ast::ExprStringLiteral { value: env_var, .. }) = arg else {
@ -249,7 +249,7 @@ pub(crate) fn dict_get_with_none_default(checker: &mut Checker, expr: &Expr) {
if attr != "get" { if attr != "get" {
return; return;
} }
let Some(key) = args.get(0) else { let Some(key) = args.first() else {
return; return;
}; };
if !(key.is_literal_expr() || key.is_name_expr()) { if !(key.is_literal_expr() || key.is_name_expr()) {

View file

@ -149,7 +149,7 @@ pub(crate) fn bad_str_strip_call(checker: &mut Checker, func: &Expr, args: &[Exp
Expr::StringLiteral(_) | Expr::BytesLiteral(_) Expr::StringLiteral(_) | Expr::BytesLiteral(_)
) { ) {
if let Some(strip) = StripKind::from_str(attr.as_str()) { if let Some(strip) = StripKind::from_str(attr.as_str()) {
if let Some(arg) = args.get(0) { if let Some(arg) = args.first() {
if let Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) = &arg { if let Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) = &arg {
if has_duplicates(value) { if has_duplicates(value) {
let removal = if checker.settings.target_version >= PythonVersion::Py39 let removal = if checker.settings.target_version >= PythonVersion::Py39

View file

@ -179,7 +179,7 @@ pub(crate) fn native_literals(
} }
} }
match args.get(0) { match args.first() {
None => { None => {
let mut diagnostic = Diagnostic::new(NativeLiterals { literal_type }, call.range()); let mut diagnostic = Diagnostic::new(NativeLiterals { literal_type }, call.range());

View file

@ -44,7 +44,7 @@ impl AlwaysFixableViolation for UnpackedListComprehension {
/// UP027 /// UP027
pub(crate) fn unpacked_list_comprehension(checker: &mut Checker, targets: &[Expr], value: &Expr) { pub(crate) fn unpacked_list_comprehension(checker: &mut Checker, targets: &[Expr], value: &Expr) {
let Some(target) = targets.get(0) else { let Some(target) = targets.first() else {
return; return;
}; };

View file

@ -95,7 +95,7 @@ fn is_none(expr: &Expr) -> bool {
}) if arguments.len() == 1 => { }) if arguments.len() == 1 => {
if let Expr::Name(ast::ExprName { id, .. }) = func.as_ref() { if let Expr::Name(ast::ExprName { id, .. }) = func.as_ref() {
if id.as_str() == "type" { if id.as_str() == "type" {
return matches!(arguments.args.get(0), Some(Expr::NoneLiteral(_))); return matches!(arguments.args.first(), Some(Expr::NoneLiteral(_)));
} }
} }
false false

View file

@ -160,6 +160,10 @@ impl ImportMap {
pub fn extend(&mut self, other: Self) { pub fn extend(&mut self, other: Self) {
self.module_to_imports.extend(other.module_to_imports); self.module_to_imports.extend(other.module_to_imports);
} }
pub fn iter(&self) -> std::collections::hash_map::Iter<String, Vec<ModuleImport>> {
self.module_to_imports.iter()
}
} }
impl<'a> IntoIterator for &'a ImportMap { impl<'a> IntoIterator for &'a ImportMap {
@ -167,6 +171,6 @@ impl<'a> IntoIterator for &'a ImportMap {
type Item = (&'a String, &'a Vec<ModuleImport>); type Item = (&'a String, &'a Vec<ModuleImport>);
fn into_iter(self) -> Self::IntoIter { fn into_iter(self) -> Self::IntoIter {
self.module_to_imports.iter() self.iter()
} }
} }

View file

@ -1129,6 +1129,14 @@ impl<'a> IntoIterator for &'a FStringValue {
} }
} }
impl<'a> IntoIterator for &'a mut FStringValue {
type Item = &'a mut FStringPart;
type IntoIter = IterMut<'a, FStringPart>;
fn into_iter(self) -> Self::IntoIter {
self.iter_mut()
}
}
/// An internal representation of [`FStringValue`]. /// An internal representation of [`FStringValue`].
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
enum FStringValueInner { enum FStringValueInner {
@ -1324,6 +1332,14 @@ impl<'a> IntoIterator for &'a StringLiteralValue {
} }
} }
impl<'a> IntoIterator for &'a mut StringLiteralValue {
type Item = &'a mut StringLiteral;
type IntoIter = IterMut<'a, StringLiteral>;
fn into_iter(self) -> Self::IntoIter {
self.iter_mut()
}
}
impl PartialEq<str> for StringLiteralValue { impl PartialEq<str> for StringLiteralValue {
fn eq(&self, other: &str) -> bool { fn eq(&self, other: &str) -> bool {
if self.len() != other.len() { if self.len() != other.len() {
@ -1547,6 +1563,14 @@ impl<'a> IntoIterator for &'a BytesLiteralValue {
} }
} }
impl<'a> IntoIterator for &'a mut BytesLiteralValue {
type Item = &'a mut BytesLiteral;
type IntoIter = IterMut<'a, BytesLiteral>;
fn into_iter(self) -> Self::IntoIter {
self.iter_mut()
}
}
impl PartialEq<[u8]> for BytesLiteralValue { impl PartialEq<[u8]> for BytesLiteralValue {
fn eq(&self, other: &[u8]) -> bool { fn eq(&self, other: &[u8]) -> bool {
if self.len() != other.len() { if self.len() != other.len() {

View file

@ -260,24 +260,6 @@ impl<'a> Escape for UnicodeEscape<'a> {
} }
} }
#[cfg(test)]
mod unicode_escape_tests {
use super::*;
#[test]
fn changed() {
fn test(s: &str) -> bool {
UnicodeEscape::new_repr(s).changed()
}
assert!(!test("hello"));
assert!(!test("'hello'"));
assert!(!test("\"hello\""));
assert!(test("'\"hello"));
assert!(test("hello\n"));
}
}
pub struct AsciiEscape<'a> { pub struct AsciiEscape<'a> {
source: &'a [u8], source: &'a [u8],
layout: EscapeLayout, layout: EscapeLayout,
@ -453,3 +435,21 @@ impl std::fmt::Display for BytesRepr<'_, '_> {
self.write(formatter) self.write(formatter)
} }
} }
#[cfg(test)]
mod unicode_escape_tests {
use super::*;
#[test]
fn changed() {
fn test(s: &str) -> bool {
UnicodeEscape::new_repr(s).changed()
}
assert!(!test("hello"));
assert!(!test("'hello'"));
assert!(!test("\"hello\""));
assert!(test("'\"hello"));
assert!(test("hello\n"));
}
}

View file

@ -1476,7 +1476,7 @@ impl Radix {
Radix::Binary => matches!(c, '0'..='1'), Radix::Binary => matches!(c, '0'..='1'),
Radix::Octal => matches!(c, '0'..='7'), Radix::Octal => matches!(c, '0'..='7'),
Radix::Decimal => c.is_ascii_digit(), Radix::Decimal => c.is_ascii_digit(),
Radix::Hex => matches!(c, '0'..='9' | 'a'..='f' | 'A'..='F'), Radix::Hex => c.is_ascii_hexdigit(),
} }
} }
} }

View file

@ -76,6 +76,7 @@ pub(crate) struct ImportResult {
/// If the import resolved to a type hint (i.e., a `.pyi` file), then /// If the import resolved to a type hint (i.e., a `.pyi` file), then
/// a non-type-hint resolution will be stored here. /// a non-type-hint resolution will be stored here.
#[allow(clippy::struct_field_names)]
pub(crate) non_stub_import_result: Option<Box<ImportResult>>, pub(crate) non_stub_import_result: Option<Box<ImportResult>>,
/// Information extracted from the `py.typed` in the package used to /// Information extracted from the `py.typed` in the package used to

View file

@ -1,2 +1,2 @@
[toolchain] [toolchain]
channel = "1.74" channel = "1.75"