Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/tools/tidy/src/alphabetical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,11 @@ fn check_lines<'a>(path: &Path, content: &'a str, tidy_ctx: &TidyCtx, check: &mu
// oh nyooo :(
if sorted != section {
if !tidy_ctx.is_bless_enabled() {
let base_line_number = content[..offset + start_nl_end].lines().count();
let pre = &content[..offset + start_nl_end];
assert_eq!(pre.chars().rev().next(), Some('\n'));
// start_nl_end spans right after the ␤, so it gets ignored by `lines()`,
// but we do want to count it! so we add 1 to the result.
let base_line_number = pre.lines().count() + 1;
let line_offset = sorted
.lines()
.zip(section.lines())
Expand Down
20 changes: 10 additions & 10 deletions src/tools/tidy/src/alphabetical/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fn test_rust_bad() {
def
// tidy-alphabetical-end
";
bad(lines, "bad:2: line not in alphabetical order (tip: use --bless to sort this list)");
bad(lines, "bad:3: line not in alphabetical order (tip: use --bless to sort this list)");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lines are typically 1-indexed, so shouldn't this actually point to 4?

Copy link
Copy Markdown
Contributor Author

@scrabsha scrabsha Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mhm, the first line of lines is // tidy-alphabetical-start1 and this lint points at the first line that needs changes, which is xyz, aka the third line

that's how i understand it, but maybe i'm wrong?

Footnotes

  1. i wasn't sure so i wrote a cute lill test for it: playground

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

M, no, you are right. For some reason I thought that in a c b the problem is in b which needs to be between a/c, but it is just as meaningful to say that the problem is c which needs to be after b.

}

#[test]
Expand All @@ -127,7 +127,7 @@ fn test_toml_bad() {
def
# tidy-alphabetical-end
";
bad(lines, "bad:2: line not in alphabetical order (tip: use --bless to sort this list)");
bad(lines, "bad:3: line not in alphabetical order (tip: use --bless to sort this list)");
}

#[test]
Expand All @@ -141,7 +141,7 @@ fn test_features_bad() {
#![feature(def)]
tidy-alphabetical-end
";
bad(lines, "bad:2: line not in alphabetical order (tip: use --bless to sort this list)");
bad(lines, "bad:3: line not in alphabetical order (tip: use --bless to sort this list)");
}

#[test]
Expand All @@ -154,7 +154,7 @@ fn test_indent_bad() {
def
$ tidy-alphabetical-end
";
bad(lines, "bad:2: line not in alphabetical order (tip: use --bless to sort this list)");
bad(lines, "bad:3: line not in alphabetical order (tip: use --bless to sort this list)");
}

#[test]
Expand All @@ -170,7 +170,7 @@ fn test_split_bad() {
)
&& tidy-alphabetical-end
";
bad(lines, "bad:3: line not in alphabetical order (tip: use --bless to sort this list)");
bad(lines, "bad:4: line not in alphabetical order (tip: use --bless to sort this list)");
}

#[test]
Expand Down Expand Up @@ -339,23 +339,23 @@ fn test_numeric_bad() {
item2
# tidy-alphabetical-end
";
bad(lines, "bad:2: line not in alphabetical order (tip: use --bless to sort this list)");
bad(lines, "bad:3: line not in alphabetical order (tip: use --bless to sort this list)");

let lines = "\
# tidy-alphabetical-start
zve64f
zve64d
# tidy-alphabetical-end
";
bad(lines, "bad:1: line not in alphabetical order (tip: use --bless to sort this list)");
bad(lines, "bad:2: line not in alphabetical order (tip: use --bless to sort this list)");

let lines = "\
# tidy-alphabetical-start
000
00
# tidy-alphabetical-end
";
bad(lines, "bad:1: line not in alphabetical order (tip: use --bless to sort this list)");
bad(lines, "bad:2: line not in alphabetical order (tip: use --bless to sort this list)");
}

#[test]
Expand Down Expand Up @@ -394,7 +394,7 @@ fn multiline() {
);
tidy-alphabetical-end
";
bad(lines, "bad:1: line not in alphabetical order (tip: use --bless to sort this list)");
bad(lines, "bad:2: line not in alphabetical order (tip: use --bless to sort this list)");

let lines = "\
tidy-alphabetical-start
Expand All @@ -406,7 +406,7 @@ fn multiline() {
a);
tidy-alphabetical-end
";
bad(lines, "bad:1: line not in alphabetical order (tip: use --bless to sort this list)");
bad(lines, "bad:2: line not in alphabetical order (tip: use --bless to sort this list)");

let lines = "\
force_unwind_tables: Option<bool> = (None, parse_opt_bool, [TRACKED],
Expand Down
Loading