Skip to content

Commit ffa1caf

Browse files
authored
just_underscores_and_digits: fix false positive in error recovery scenario (rust-lang#14168)
Fixes rust-lang#12302 changelog: [`just_underscores_and_digits`]: fix false positive in error recovery scenario
2 parents c40898e + ac15a10 commit ffa1caf

File tree

5 files changed

+38
-3
lines changed

5 files changed

+38
-3
lines changed

clippy_dev/src/fmt.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,13 @@ fn run_rustfmt(context: &FmtContext) -> Result<(), Error> {
290290
.filter_map(|entry| {
291291
let entry = entry.expect("failed to find tests");
292292
let path = entry.path();
293-
294-
if path.extension() != Some("rs".as_ref()) || entry.file_name() == "ice-3891.rs" {
293+
if path.extension() != Some("rs".as_ref())
294+
|| path
295+
.components()
296+
.nth_back(1)
297+
.is_some_and(|c| c.as_os_str() == "syntax-error-recovery")
298+
|| entry.file_name() == "ice-3891.rs"
299+
{
295300
None
296301
} else {
297302
Some(entry.into_path().into_os_string())

clippy_lints/src/non_expressive_names.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ impl SimilarNamesNameVisitor<'_, '_, '_> {
208208

209209
fn check_ident(&mut self, ident: Ident) {
210210
let interned_name = ident.name.as_str();
211-
if interned_name.chars().any(char::is_uppercase) {
211+
// name can be empty if it comes from recovery
212+
if interned_name.chars().any(char::is_uppercase) || interned_name.is_empty() {
212213
return;
213214
}
214215
if interned_name.chars().all(|c| c.is_ascii_digit() || c == '_') {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// https://github.com/rust-lang/rust-clippy/issues/12302
2+
use std::marker::PhantomData;
3+
4+
pub struct Aa<T>(PhantomData<T>);
5+
6+
fn aa(a: Aa<String>) {
7+
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// https://github.com/rust-lang/rust-clippy/issues/12302
2+
use std::marker::PhantomData;
3+
4+
pub struct Aa<T>(PhantomData<T>);
5+
6+
fn aa(a: Aa<String) {
7+
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error: expected one of `!`, `(`, `+`, `,`, `::`, `<`, or `>`, found `)`
2+
--> tests/ui/syntax-error-recovery/non_expressive_names_error_recovery.rs:6:19
3+
|
4+
LL | fn aa(a: Aa<String) {
5+
| ^ expected one of 7 possible tokens
6+
|
7+
help: you might have meant to end the type parameters here
8+
|
9+
LL | fn aa(a: Aa<String>) {
10+
| +
11+
12+
error: aborting due to 1 previous error
13+

0 commit comments

Comments
 (0)