Skip to content

Commit

Permalink
Use Rust 1.75 toolchain (#9437)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser authored Jan 8, 2024
1 parent ba71772 commit 94968fe
Show file tree
Hide file tree
Showing 17 changed files with 63 additions and 30 deletions.
1 change: 1 addition & 0 deletions crates/ruff_cli/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ pub(crate) struct Cache {
changes: Mutex<Vec<Change>>,
/// The "current" timestamp used as cache for the updates of
/// [`FileCache::last_seen`]
#[allow(clippy::struct_field_names)]
last_seen_cache: u64,
}

Expand Down
1 change: 1 addition & 0 deletions crates/ruff_cli/src/commands/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct Explanation<'a> {
summary: &'a str,
message_formats: &'a [&'a str],
fix: String,
#[allow(clippy::struct_field_names)]
explanation: Option<&'a str>,
preview: bool,
}
Expand Down
1 change: 1 addition & 0 deletions crates/ruff_dev/src/format_dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ pub(crate) struct Args {
#[arg(long)]
pub(crate) files_with_errors: Option<u32>,
#[clap(flatten)]
#[allow(clippy::struct_field_names)]
pub(crate) log_level_args: LogLevelArgs,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ pub(crate) fn fix_unnecessary_literal_dict(expr: &Expr, checker: &Checker) -> Re
comma,
} = 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) {
return Ok(DictElement::Simple {
key: key.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub(crate) fn multiple_starts_ends_with(checker: &mut Checker, expr: &Expr) {
format!("Indices should only contain `{attr_name}` calls")
)
};
args.get(0)
args.first()
.unwrap_or_else(|| panic!("`{attr_name}` should have one argument"))
})
.collect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,8 @@ pub(crate) fn duplicate_isinstance_call(checker: &mut Checker, expr: &Expr) {
..
}) = &values[indices[0]]
{
args.get(0).expect("`isinstance` should have two arguments")
args.first()
.expect("`isinstance` should have two arguments")
} else {
unreachable!("Indices should only contain `isinstance` calls")
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ pub(crate) fn use_capital_environment_variables(checker: &mut Checker, expr: &Ex
else {
return;
};
let Some(arg) = args.get(0) else {
let Some(arg) = args.first() else {
return;
};
let Expr::StringLiteral(ast::ExprStringLiteral { value: env_var, .. }) = arg else {
Expand Down Expand Up @@ -249,7 +249,7 @@ pub(crate) fn dict_get_with_none_default(checker: &mut Checker, expr: &Expr) {
if attr != "get" {
return;
}
let Some(key) = args.get(0) else {
let Some(key) = args.first() else {
return;
};
if !(key.is_literal_expr() || key.is_name_expr()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pub(crate) fn bad_str_strip_call(checker: &mut Checker, func: &Expr, args: &[Exp
Expr::StringLiteral(_) | Expr::BytesLiteral(_)
) {
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 has_duplicates(value) {
let removal = if checker.settings.target_version >= PythonVersion::Py39
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pub(crate) fn native_literals(
}
}

match args.get(0) {
match args.first() {
None => {
let mut diagnostic = Diagnostic::new(NativeLiterals { literal_type }, call.range());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl AlwaysFixableViolation for UnpackedListComprehension {

/// UP027
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;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fn is_none(expr: &Expr) -> bool {
}) if arguments.len() == 1 => {
if let Expr::Name(ast::ExprName { id, .. }) = func.as_ref() {
if id.as_str() == "type" {
return matches!(arguments.args.get(0), Some(Expr::NoneLiteral(_)));
return matches!(arguments.args.first(), Some(Expr::NoneLiteral(_)));
}
}
false
Expand Down
6 changes: 5 additions & 1 deletion crates/ruff_python_ast/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,17 @@ impl ImportMap {
pub fn extend(&mut self, other: Self) {
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 {
type IntoIter = std::collections::hash_map::Iter<'a, String, Vec<ModuleImport>>;
type Item = (&'a String, &'a Vec<ModuleImport>);

fn into_iter(self) -> Self::IntoIter {
self.module_to_imports.iter()
self.iter()
}
}
24 changes: 24 additions & 0 deletions crates/ruff_python_ast/src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`].
#[derive(Clone, Debug, PartialEq)]
enum FStringValueInner {
Expand Down Expand Up @@ -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 {
fn eq(&self, other: &str) -> bool {
if self.len() != other.len() {
Expand Down Expand Up @@ -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 {
fn eq(&self, other: &[u8]) -> bool {
if self.len() != other.len() {
Expand Down
36 changes: 18 additions & 18 deletions crates/ruff_python_literal/src/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
source: &'a [u8],
layout: EscapeLayout,
Expand Down Expand Up @@ -453,3 +435,21 @@ impl std::fmt::Display for BytesRepr<'_, '_> {
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"));
}
}
2 changes: 1 addition & 1 deletion crates/ruff_python_parser/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,7 @@ impl Radix {
Radix::Binary => matches!(c, '0'..='1'),
Radix::Octal => matches!(c, '0'..='7'),
Radix::Decimal => c.is_ascii_digit(),
Radix::Hex => matches!(c, '0'..='9' | 'a'..='f' | 'A'..='F'),
Radix::Hex => c.is_ascii_hexdigit(),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/ruff_python_resolver/src/import_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub(crate) struct ImportResult {

/// If the import resolved to a type hint (i.e., a `.pyi` file), then
/// a non-type-hint resolution will be stored here.
#[allow(clippy::struct_field_names)]
pub(crate) non_stub_import_result: Option<Box<ImportResult>>,

/// Information extracted from the `py.typed` in the package used to
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "1.74"
channel = "1.75"

0 comments on commit 94968fe

Please sign in to comment.