Skip to content

Commit 60fd98e

Browse files
Update Rust to v1.77 (#10510)
1 parent ac150b9 commit 60fd98e

File tree

26 files changed

+35
-84
lines changed

26 files changed

+35
-84
lines changed

crates/ruff/src/commands/check.rs

+1
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ mod test {
252252
for file in [&pyproject_toml, &python_file, &notebook] {
253253
fs::OpenOptions::new()
254254
.create(true)
255+
.truncate(true)
255256
.write(true)
256257
.mode(0o000)
257258
.open(file)?;

crates/ruff/src/panic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl std::fmt::Display for PanicError {
1616
}
1717

1818
thread_local! {
19-
static LAST_PANIC: std::cell::Cell<Option<PanicError>> = std::cell::Cell::new(None);
19+
static LAST_PANIC: std::cell::Cell<Option<PanicError>> = const { std::cell::Cell::new(None) };
2020
}
2121

2222
/// [`catch_unwind`](std::panic::catch_unwind) wrapper that sets a custom [`set_hook`](std::panic::set_hook)

crates/ruff/tests/integration_test.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1353,6 +1353,7 @@ fn unreadable_pyproject_toml() -> Result<()> {
13531353
// Create an empty file with 000 permissions
13541354
fs::OpenOptions::new()
13551355
.create(true)
1356+
.truncate(true)
13561357
.write(true)
13571358
.mode(0o000)
13581359
.open(pyproject_toml)?;

crates/ruff_linter/src/checkers/imports.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ use crate::rules::isort::block::{Block, BlockBuilder};
2020
use crate::settings::LinterSettings;
2121

2222
fn extract_import_map(path: &Path, package: Option<&Path>, blocks: &[&Block]) -> Option<ImportMap> {
23-
let Some(package) = package else {
24-
return None;
25-
};
26-
let Some(module_path) = to_module_path(package, path) else {
27-
return None;
28-
};
23+
let module_path = to_module_path(package?, path)?;
2924

3025
let num_imports = blocks.iter().map(|block| block.imports.len()).sum();
3126
let mut module_imports = Vec::with_capacity(num_imports);

crates/ruff_linter/src/fix/edits.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ pub(crate) fn delete_stmt(
4040
locator: &Locator,
4141
indexer: &Indexer,
4242
) -> Edit {
43-
if parent
44-
.map(|parent| is_lone_child(stmt, parent))
45-
.unwrap_or_default()
46-
{
43+
if parent.is_some_and(|parent| is_lone_child(stmt, parent)) {
4744
// If removing this node would lead to an invalid syntax tree, replace
4845
// it with a `pass`.
4946
Edit::range_replacement("pass".to_string(), stmt.range())

crates/ruff_linter/src/importer/insertion.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,7 @@ impl<'a> Insertion<'a> {
278278
/// Find the end of the last docstring.
279279
fn match_docstring_end(body: &[Stmt]) -> Option<TextSize> {
280280
let mut iter = body.iter();
281-
let Some(mut stmt) = iter.next() else {
282-
return None;
283-
};
281+
let mut stmt = iter.next()?;
284282
if !is_docstring_stmt(stmt) {
285283
return None;
286284
}

crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_password_string.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ pub(crate) fn compare_to_hardcoded_password_string(
8080
.diagnostics
8181
.extend(comparators.iter().filter_map(|comp| {
8282
string_literal(comp).filter(|string| !string.is_empty())?;
83-
let Some(name) = password_target(left) else {
84-
return None;
85-
};
83+
let name = password_target(left)?;
8684
Some(Diagnostic::new(
8785
HardcodedPasswordString {
8886
name: name.to_string(),

crates/ruff_linter/src/rules/flake8_django/rules/unordered_body_content_in_model.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,7 @@ fn get_element_type(element: &Stmt, semantic: &SemanticModel) -> Option<ContentT
159159
return Some(ContentType::FieldDeclaration);
160160
}
161161
}
162-
let Some(expr) = targets.first() else {
163-
return None;
164-
};
162+
let expr = targets.first()?;
165163
let Expr::Name(ast::ExprName { id, .. }) = expr else {
166164
return None;
167165
};

crates/ruff_linter/src/rules/flake8_import_conventions/rules/unconventional_import_alias.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,9 @@ pub(crate) fn unconventional_import_alias(
6161
binding: &Binding,
6262
conventions: &FxHashMap<String, String>,
6363
) -> Option<Diagnostic> {
64-
let Some(import) = binding.as_any_import() else {
65-
return None;
66-
};
67-
64+
let import = binding.as_any_import()?;
6865
let qualified_name = import.qualified_name().to_string();
69-
70-
let Some(expected_alias) = conventions.get(qualified_name.as_str()) else {
71-
return None;
72-
};
66+
let expected_alias = conventions.get(qualified_name.as_str())?;
7367

7468
let name = binding.name(checker.locator());
7569
if binding.is_alias() && name == expected_alias {

crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_literal_union.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,7 @@ fn match_builtin_type(expr: &Expr, semantic: &SemanticModel) -> Option<ExprType>
148148
/// Return the [`ExprType`] of an [`Expr`] if it is a literal (e.g., an `int`, like `1`, or a
149149
/// `bool`, like `True`).
150150
fn match_literal_type(expr: &Expr) -> Option<ExprType> {
151-
let Some(literal_expr) = expr.as_literal_expr() else {
152-
return None;
153-
};
154-
let result = match literal_expr {
151+
Some(match expr.as_literal_expr()? {
155152
LiteralExpressionRef::BooleanLiteral(_) => ExprType::Bool,
156153
LiteralExpressionRef::StringLiteral(_) => ExprType::Str,
157154
LiteralExpressionRef::BytesLiteral(_) => ExprType::Bytes,
@@ -163,6 +160,5 @@ fn match_literal_type(expr: &Expr) -> Option<ExprType> {
163160
LiteralExpressionRef::NoneLiteral(_) | LiteralExpressionRef::EllipsisLiteral(_) => {
164161
return None;
165162
}
166-
};
167-
Some(result)
163+
})
168164
}

crates/ruff_linter/src/rules/flake8_pytest_style/rules/helpers.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ pub(super) fn get_mark_decorators(
88
decorators: &[Decorator],
99
) -> impl Iterator<Item = (&Decorator, &str)> {
1010
decorators.iter().filter_map(|decorator| {
11-
let Some(name) = UnqualifiedName::from_expr(map_callable(&decorator.expression)) else {
12-
return None;
13-
};
11+
let name = UnqualifiedName::from_expr(map_callable(&decorator.expression))?;
1412
let ["pytest", "mark", marker] = name.segments() else {
1513
return None;
1614
};

crates/ruff_linter/src/rules/flake8_simplify/rules/ast_bool_op.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ pub(crate) fn compare_with_tuple(checker: &mut Checker, expr: &Expr) {
541541

542542
// Create a `x in (a, b)` expression.
543543
let node = ast::ExprTuple {
544-
elts: comparators.into_iter().map(Clone::clone).collect(),
544+
elts: comparators.into_iter().cloned().collect(),
545545
ctx: ExprContext::Load,
546546
range: TextRange::default(),
547547
parenthesized: true,

crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,11 @@ fn match_loop(stmt: &Stmt) -> Option<Loop> {
274274
if !nested_elif_else_clauses.is_empty() {
275275
return None;
276276
}
277-
let [Stmt::Return(ast::StmtReturn { value, range: _ })] = nested_body.as_slice() else {
278-
return None;
279-
};
280-
let Some(value) = value else {
277+
let [Stmt::Return(ast::StmtReturn {
278+
value: Some(value),
279+
range: _,
280+
})] = nested_body.as_slice()
281+
else {
281282
return None;
282283
};
283284
let Expr::BooleanLiteral(ast::ExprBooleanLiteral { value, .. }) = value.as_ref() else {

crates/ruff_linter/src/rules/flake8_tidy_imports/rules/relative_imports.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ fn fix_banned_relative_import(
8282
generator: Generator,
8383
) -> Option<Fix> {
8484
// Only fix is the module path is known.
85-
let Some(module_path) = resolve_imported_module_path(level, module, module_path) else {
86-
return None;
87-
};
85+
let module_path = resolve_imported_module_path(level, module, module_path)?;
8886

8987
// Require import to be a valid module:
9088
// https://python.org/dev/peps/pep-0008/#package-and-module-names

crates/ruff_linter/src/rules/isort/categorize.rs

+2
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,12 @@ enum Reason<'a> {
8080
Future,
8181
KnownStandardLibrary,
8282
SamePackage,
83+
#[allow(dead_code)]
8384
SourceMatch(&'a Path),
8485
NoMatch,
8586
UserDefinedSection,
8687
NoSections,
88+
#[allow(dead_code)]
8789
DisabledSection(&'a ImportSection),
8890
}
8991

crates/ruff_linter/src/rules/isort/sorting.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ impl<'a> ModuleKey<'a> {
103103
) -> Self {
104104
let level = level.unwrap_or_default();
105105

106-
let force_to_top = !name
107-
.map(|name| settings.force_to_top.contains(name))
108-
.unwrap_or_default(); // `false` < `true` so we get forced to top first
106+
let force_to_top = !name.is_some_and(|name| settings.force_to_top.contains(name)); // `false` < `true` so we get forced to top first
109107

110108
let maybe_length = (settings.length_sort
111109
|| (settings.length_sort_straight && style == ImportStyle::Straight))

crates/ruff_linter/src/rules/pycodestyle/rules/doc_line_too_long.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,7 @@ pub(crate) fn doc_line_too_long(
8787
indexer: &Indexer,
8888
settings: &LinterSettings,
8989
) -> Option<Diagnostic> {
90-
let Some(limit) = settings.pycodestyle.max_doc_length else {
91-
return None;
92-
};
93-
90+
let limit = settings.pycodestyle.max_doc_length?;
9491
Overlong::try_from_line(
9592
line,
9693
indexer,

crates/ruff_linter/src/rules/pylint/rules/import_self.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ impl Violation for ImportSelf {
3535

3636
/// PLW0406
3737
pub(crate) fn import_self(alias: &Alias, module_path: Option<&[String]>) -> Option<Diagnostic> {
38-
let Some(module_path) = module_path else {
39-
return None;
40-
};
38+
let module_path = module_path?;
4139

4240
if alias.name.split('.').eq(module_path) {
4341
return Some(Diagnostic::new(
@@ -58,13 +56,8 @@ pub(crate) fn import_from_self(
5856
names: &[Alias],
5957
module_path: Option<&[String]>,
6058
) -> Option<Diagnostic> {
61-
let Some(module_path) = module_path else {
62-
return None;
63-
};
64-
let Some(imported_module_path) = resolve_imported_module_path(level, module, Some(module_path))
65-
else {
66-
return None;
67-
};
59+
let module_path = module_path?;
60+
let imported_module_path = resolve_imported_module_path(level, module, Some(module_path))?;
6861

6962
if imported_module_path
7063
.split('.')

crates/ruff_linter/src/rules/pyupgrade/rules/f_strings.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,7 @@ impl<'a> FormatSummaryValues<'a> {
8686
value,
8787
range: _,
8888
} = keyword;
89-
let Some(key) = arg else {
90-
return None;
91-
};
89+
let key = arg.as_ref()?;
9290
if contains_quotes(locator.slice(value)) || locator.contains_line_break(value.range()) {
9391
return None;
9492
}

crates/ruff_linter/src/rules/pyupgrade/rules/printf_string_formatting.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,7 @@ fn clean_params_dictionary(right: &Expr, locator: &Locator, stylist: &Stylist) -
260260
}
261261
contents.push('(');
262262
if is_multi_line {
263-
let Some(indent) = indent else {
264-
return None;
265-
};
263+
let indent = indent?;
266264

267265
for item in &arguments {
268266
contents.push_str(stylist.line_ending().as_str());

crates/ruff_linter/src/rules/ruff/rules/invalid_formatter_suppression_comment.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ impl<'src, 'loc> UselessSuppressionComments<'src, 'loc> {
127127
// check if the comment is inside of an expression.
128128
if comment
129129
.enclosing
130-
.map(|n| !is_valid_enclosing_node(n))
131-
.unwrap_or_default()
130+
.is_some_and(|n| !is_valid_enclosing_node(n))
132131
{
133132
return Err(IgnoredReason::InNonStatement);
134133
}

crates/ruff_linter/src/rules/ruff/rules/pairwise_over_zipped.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,7 @@ fn match_slice_info(expr: &Expr) -> Option<SliceInfo> {
8383
else {
8484
return None;
8585
};
86-
87-
let Some(slice_start) = int.as_i32() else {
88-
return None;
89-
};
90-
91-
Some(slice_start)
86+
Some(int.as_i32()?)
9287
} else {
9388
None
9489
};

crates/ruff_linter/src/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub fn test_snippet(contents: &str, settings: &LinterSettings) -> Vec<Message> {
9292
}
9393

9494
thread_local! {
95-
static MAX_ITERATIONS: std::cell::Cell<usize> = std::cell::Cell::new(8);
95+
static MAX_ITERATIONS: std::cell::Cell<usize> = const { std::cell::Cell::new(8) };
9696
}
9797

9898
pub fn set_max_iterations(max: usize) {

crates/ruff_python_ast/src/helpers.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -878,9 +878,7 @@ pub fn resolve_imported_module_path<'a>(
878878
return Some(Cow::Borrowed(module.unwrap_or("")));
879879
}
880880

881-
let Some(module_path) = module_path else {
882-
return None;
883-
};
881+
let module_path = module_path?;
884882

885883
if level as usize >= module_path.len() {
886884
return None;

crates/ruff_python_formatter/src/pattern/pattern_match_mapping.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,7 @@ fn find_double_star(pattern: &PatternMatchMapping, source: &str) -> Option<(Text
175175
} = pattern;
176176

177177
// If there's no `rest` element, there's no `**`.
178-
let Some(rest) = rest else {
179-
return None;
180-
};
178+
let rest = rest.as_ref()?;
181179

182180
let mut tokenizer =
183181
SimpleTokenizer::starts_at(patterns.last().map_or(pattern.start(), Ranged::end), source);

rust-toolchain.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[toolchain]
2-
channel = "1.76"
2+
channel = "1.77"

0 commit comments

Comments
 (0)