Remove unnecessary Comment#slice calls (#6997)

This commit is contained in:
Charlie Marsh 2023-08-29 20:44:11 -04:00 committed by GitHub
parent 34e8de738e
commit b404e54f33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 23 additions and 39 deletions

View file

@ -42,7 +42,7 @@ impl FormatNodeRule<StmtFor> for FormatStmtFor {
let dangling_comments = comments.dangling(item);
let body_start = body.first().map_or(iter.end(), Stmt::start);
let or_else_comments_start =
dangling_comments.partition_point(|comment| comment.slice().end() < body_start);
dangling_comments.partition_point(|comment| comment.end() < body_start);
let (trailing_condition_comments, or_else_comments) =
dangling_comments.split_at(or_else_comments_start);

View file

@ -119,7 +119,7 @@ fn format_case<'a>(
Ok(if let Some(last) = body.last() {
let case_comments_start =
dangling_comments.partition_point(|comment| comment.slice().end() <= last.end());
dangling_comments.partition_point(|comment| comment.end() <= last.end());
let (case_comments, rest) = dangling_comments.split_at(case_comments_start);
let partition_point =
case_comments.partition_point(|comment| comment.line_position().is_own_line());

View file

@ -26,7 +26,7 @@ impl FormatNodeRule<StmtWhile> for FormatStmtWhile {
let body_start = body.first().map_or(test.end(), Stmt::start);
let or_else_comments_start =
dangling_comments.partition_point(|comment| comment.slice().end() < body_start);
dangling_comments.partition_point(|comment| comment.end() < body_start);
let (trailing_condition_comments, or_else_comments) =
dangling_comments.split_at(or_else_comments_start);

View file

@ -223,7 +223,7 @@ impl FormatRule<Suite, PyFormatContext<'_>> for FormatSuite {
// the leading comment. This is why the suite handling counts the lines before the
// start of the next statement or before the first leading comments for compound statements.
let start = if let Some(first_leading) = comments.leading(following).first() {
first_leading.slice().start()
first_leading.start()
} else {
following.start()
};