@@ -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
0 commit comments