Skip to content

Commit 6a75b8b

Browse files
Auto-format: cargo fmt --all
1 parent 8c14386 commit 6a75b8b

File tree

6 files changed

+18
-48
lines changed

6 files changed

+18
-48
lines changed

crates/compiler/src/lib.rs

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,20 @@ impl CompileError {
5454
&error.error,
5555
parser::ParseErrorType::Lexical(parser::LexicalErrorType::Eof)
5656
) {
57-
if let Some((bracket_char, bracket_offset)) =
58-
find_unclosed_bracket(source_text)
59-
{
57+
if let Some((bracket_char, bracket_offset)) = find_unclosed_bracket(source_text) {
6058
let bracket_text_size = ruff_text_size::TextSize::new(bracket_offset as u32);
61-
let loc =
62-
source_code.source_location(bracket_text_size, PositionEncoding::Utf8);
59+
let loc = source_code.source_location(bracket_text_size, PositionEncoding::Utf8);
6360
let end_loc = SourceLocation {
6461
line: loc.line,
6562
character_offset: loc.character_offset.saturating_add(1),
6663
};
6764
let msg = format!("'{}' was never closed", bracket_char);
68-
(
69-
parser::ParseErrorType::OtherError(msg),
70-
loc,
71-
end_loc,
72-
)
65+
(parser::ParseErrorType::OtherError(msg), loc, end_loc)
7366
} else {
74-
let loc = source_code
75-
.source_location(error.location.start(), PositionEncoding::Utf8);
76-
let end_loc = source_code
77-
.source_location(error.location.end(), PositionEncoding::Utf8);
67+
let loc =
68+
source_code.source_location(error.location.start(), PositionEncoding::Utf8);
69+
let end_loc =
70+
source_code.source_location(error.location.end(), PositionEncoding::Utf8);
7871
(error.error, loc, end_loc)
7972
}
8073
} else if matches!(
@@ -83,8 +76,7 @@ impl CompileError {
8376
) {
8477
// For IndentationError, point the offset to the end of the line content
8578
// (matching CPython behavior) instead of the beginning
86-
let loc =
87-
source_code.source_location(error.location.start(), PositionEncoding::Utf8);
79+
let loc = source_code.source_location(error.location.start(), PositionEncoding::Utf8);
8880
let line_idx = loc.line.to_zero_indexed();
8981
let line = source_text.split('\n').nth(line_idx).unwrap_or("");
9082
let line_end_col = line.len() + 1; // 1-indexed, past last char (the newline)
@@ -95,18 +87,15 @@ impl CompileError {
9587
};
9688
(error.error, end_loc, end_loc)
9789
} else {
98-
let loc =
99-
source_code.source_location(error.location.start(), PositionEncoding::Utf8);
90+
let loc = source_code.source_location(error.location.start(), PositionEncoding::Utf8);
10091
let mut end_loc =
10192
source_code.source_location(error.location.end(), PositionEncoding::Utf8);
10293

10394
// If the error range ends at the start of a new line (column 1),
10495
// adjust it to the end of the previous line
10596
if end_loc.character_offset.get() == 1 && end_loc.line > loc.line {
106-
let prev_line_end =
107-
error.location.end() - ruff_text_size::TextSize::from(1);
108-
end_loc =
109-
source_code.source_location(prev_line_end, PositionEncoding::Utf8);
97+
let prev_line_end = error.location.end() - ruff_text_size::TextSize::from(1);
98+
end_loc = source_code.source_location(prev_line_end, PositionEncoding::Utf8);
11099
end_loc.character_offset = end_loc.character_offset.saturating_add(1);
111100
}
112101

crates/vm/src/builtins/frame.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,9 @@ impl Py<Frame> {
149149
#[pymethod]
150150
fn clear(&self, vm: &VirtualMachine) -> PyResult<()> {
151151
// Check if the frame is currently executing
152-
let is_executing = vm
153-
.frames
154-
.borrow()
155-
.iter()
156-
.any(|f| f.is(self.as_object()));
152+
let is_executing = vm.frames.borrow().iter().any(|f| f.is(self.as_object()));
157153
if is_executing {
158-
return Err(
159-
vm.new_runtime_error("cannot clear an executing frame".to_owned())
160-
);
154+
return Err(vm.new_runtime_error("cannot clear an executing frame".to_owned()));
161155
}
162156

163157
// Clear fastlocals

crates/vm/src/builtins/traceback.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ impl PyTraceback {
8282
let value = match value {
8383
PySetterValue::Assign(v) => v,
8484
PySetterValue::Delete => {
85-
return Err(
86-
vm.new_type_error("can't delete tb_next attribute".to_owned())
87-
);
85+
return Err(vm.new_type_error("can't delete tb_next attribute".to_owned()));
8886
}
8987
};
9088
if let Some(ref new_next) = value {

crates/vm/src/frame.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2244,9 +2244,7 @@ impl ExecutingFrame<'_> {
22442244
};
22452245

22462246
// name_from = the attribute name that failed to import
2247-
let _ = err
2248-
.as_object()
2249-
.set_attr("name_from", name.to_owned(), vm);
2247+
let _ = err.as_object().set_attr("name_from", name.to_owned(), vm);
22502248

22512249
Err(err)
22522250
}
@@ -2326,9 +2324,7 @@ impl ExecutingFrame<'_> {
23262324
Err(exception)
23272325
}
23282326
}
2329-
UnwindReason::Returning { value } => {
2330-
Ok(Some(ExecutionResult::Return(value)))
2331-
}
2327+
UnwindReason::Returning { value } => Ok(Some(ExecutionResult::Return(value))),
23322328
}
23332329
}
23342330

crates/vm/src/stdlib/sys.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -702,11 +702,7 @@ mod sys {
702702
if let Ok(tb_mod) = vm.import("traceback", 0)
703703
&& let Ok(print_exc) = tb_mod.get_attr("print_exception", vm)
704704
{
705-
let exc = vm.normalize_exception(
706-
exc_type.clone(),
707-
exc_val.clone(),
708-
exc_tb.clone(),
709-
);
705+
let exc = vm.normalize_exception(exc_type.clone(), exc_val.clone(), exc_tb.clone());
710706
if let Ok(exc) = exc
711707
&& print_exc.call((exc.as_object().to_owned(),), vm).is_ok()
712708
{

crates/vm/src/suggestion.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ pub fn offer_suggestions(exc: &Py<PyBaseException>, vm: &VirtualMachine) -> Opti
7070

7171
let builtins: Vec<_> = tb.frame.builtins.try_to_value(vm).ok()?;
7272
calculate_suggestions(builtins.iter(), &name)
73-
} else if exc
74-
.class()
75-
.fast_issubclass(vm.ctx.exceptions.import_error)
76-
{
73+
} else if exc.class().fast_issubclass(vm.ctx.exceptions.import_error) {
7774
let name = exc.as_object().get_attr("name", vm).ok()?;
7875
let mod_name = exc.as_object().get_attr("name_from", vm).ok()?;
7976
let mod_name_str = mod_name.downcast_ref::<PyStr>()?;

0 commit comments

Comments
 (0)