tidy: Replace custom panic/unwrap lint with clippy lint (#38593)

This change replaces our custom `panic` / `unwrap` lint with the one
from clippy. This rule as not properly applied in servoshell, so this
change fixes some clippy errors raised by the new configuration.

Testing: This change removes the tidy tests for the custom lints, but
otherwise the behavior is tested as part of clippy itself.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2025-08-11 13:04:11 +02:00 committed by GitHub
parent 005164df4a
commit be7625fc1e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 29 additions and 28 deletions

View file

@ -124,8 +124,6 @@ class CheckTidiness(unittest.TestCase):
self.assertEqual("use &T instead of &DomRoot<T>", next(errors)[2])
self.assertEqual("encountered function signature with -> ()", next(errors)[2])
self.assertEqual("operators should go at the end of the first line", next(errors)[2])
self.assertEqual("unwrap() or panic!() found in code which should not panic.", next(errors)[2])
self.assertEqual("unwrap() or panic!() found in code which should not panic.", next(errors)[2])
self.assertNoMoreErrors(errors)
feature_errors = tidy.collect_errors_for_files(iterFile("lib.rs"), [], [tidy.check_rust], print_text=False)

View file

@ -78,8 +78,4 @@ impl test {
} else {
let xif = 42 in { xif } // Should not trigger
}
let option = Some(3);
println!("{}", option.unwrap());
panic!("What a way to end.");
}

View file

@ -557,21 +557,9 @@ def check_rust(file_name: str, lines: list[bytes]) -> Iterator[tuple[int, str]]:
import_block = False
whitespace = False
PANIC_NOT_ALLOWED_PATHS = [
os.path.join("*", "components", "compositing", "compositor.rs"),
os.path.join("*", "components", "constellation", "*"),
os.path.join("*", "ports", "servoshell", "headed_window.rs"),
os.path.join("*", "ports", "servoshell", "headless_window.rs"),
os.path.join("*", "ports", "servoshell", "embedder.rs"),
os.path.join("*", "rust_tidy.rs"), # This is for the tests.
]
is_panic_not_allowed_rs_file = any([fnmatch.fnmatch(file_name, path) for path in PANIC_NOT_ALLOWED_PATHS])
prev_open_brace = False
multi_line_string = False
panic_message = "unwrap() or panic!() found in code which should not panic."
for idx, original_line in enumerate(map(lambda line: line.decode("utf-8"), lines)):
# simplify the analysis
line = original_line.strip()
@ -660,11 +648,6 @@ def check_rust(file_name: str, lines: list[bytes]) -> Iterator[tuple[int, str]]:
yield (idx + 1, "found an empty line following a {")
prev_open_brace = line.endswith("{")
if is_panic_not_allowed_rs_file:
match = re.search(r"unwrap\(|panic!\(", line)
if match:
yield (idx + 1, panic_message)
# Avoid flagging <Item=Foo> constructs
def is_associated_type(match, line):