Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ebf9eb3

Browse files
authoredJul 4, 2024
Unrolled build for rust-lang#127287
Rollup merge of rust-lang#127287 - aDotInTheVoid:jsondocck-index, r=GuillaumeGomez jsondocck: Use correct index for error message. If you misused a count command like ``@count` $some.selector '"T'"`, you would panic with OOB: ``` thread 'main' panicked at src/tools/jsondocck/src/main.rs:76:92: index out of bounds: the len is 2 but the index is 2 ``` This is because 57c85bd removed the file param, but didn't update the error case. We now error with: ``` Invalid command: Second argument to `@count` must be a valid usize (got `"T"`) on line 20 ``` As some point I want to rewrite this code to avoid indexing in general, but this is a nice small fix. r? `@GuillaumeGomez`
2 parents 486bc27 + ccc8baf commit ebf9eb3

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed
 

‎src/tools/jsondocck/src/main.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ pub enum CommandKind {
5656

5757
impl CommandKind {
5858
fn validate(&self, args: &[String], lineno: usize) -> bool {
59+
// FIXME(adotinthevoid): We should "parse, don't validate" here, so we avoid ad-hoc
60+
// indexing in check_command.
5961
let count = match self {
6062
CommandKind::Has => (1..=2).contains(&args.len()),
6163
CommandKind::IsMany => args.len() >= 2,
@@ -71,7 +73,7 @@ impl CommandKind {
7173
if let CommandKind::Count = self {
7274
if args[1].parse::<usize>().is_err() {
7375
print_err(
74-
&format!("Second argument to @count must be a valid usize (got `{}`)", args[2]),
76+
&format!("Second argument to @count must be a valid usize (got `{}`)", args[1]),
7577
lineno,
7678
);
7779
return false;

0 commit comments

Comments
 (0)
Failed to load comments.