From 8cea13d8a4474519be0ad2cf181f3d442fa52bd1 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 2 Dec 2026 11:57:17 -0800 Subject: [PATCH] xtask: test-lint census rule reads a loop label with a space before its colon Rust allows whitespace between a loop label and its colon ('inner : for), so the label is stripped from the loop head in that form too. --- xtask/src/test_lint.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/xtask/src/test_lint.rs b/xtask/src/test_lint.rs index 1c69802987..423b919d88 100644 --- a/xtask/src/test_lint.rs +++ b/xtask/src/test_lint.rs @@ -2582,7 +2582,7 @@ fn runs_with_assertion_within(b: &[u8], from: usize, to: usize, start: usize, ac let prefix = prefix .strip_prefix(b"'") .map(|rest| rest.split_at(rest.iter().take_while(|&&c| is_ident(c)).count())) - .and_then(|(label, rest)| rest.strip_prefix(b":").filter(|r| !label.is_empty() && r.first() != Some(&b':'))) + .and_then(|(label, rest)| rest.trim_ascii_start().strip_prefix(b":").filter(|r| !label.is_empty() && r.first() != Some(&b':'))) .map_or(prefix, <[u8]>::trim_ascii_start); let nested_for = prefix.starts_with(b"for") && prefix.get(3).is_some_and(u8::is_ascii_whitespace); if prefix.ends_with(b"||") || prefix.ends_with(b"&&") { @@ -10360,6 +10360,11 @@ mod tests { [(2, "census")], "a labeled empty loop does not run its body" ); + assert_eq!( + census("'inner : for _ in 0..0 { app.run(c); } assert!(menu(c).is_some());"), + [(2, "census")], + "a label with a space before its colon" + ); assert_eq!( census("let run = || app.run(c); other::run(); assert!(menu(c).is_some());"), [(2, "census")],