Rollup merge of #114472 - estebank:issue-76140, r=compiler-errors

Reword `confusable_idents` lint

Fix #76140.
This commit is contained in:
Matthias Krüger 2023-08-04 21:31:59 +02:00 committed by GitHub
commit cd5317a000
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 11 deletions

View File

@ -167,8 +167,9 @@ lint_check_name_warning = {$msg}
lint_command_line_source = `forbid` lint level was set on command line
lint_confusable_identifier_pair = identifier pair considered confusable between `{$existing_sym}` and `{$sym}`
.label = this is where the previous identifier occurred
lint_confusable_identifier_pair = found both `{$existing_sym}` and `{$sym}` as identifiers, which look alike
.current_use = this identifier can be confused with `{$existing_sym}`
.other_use = other identifier used here
lint_cstring_ptr = getting the inner pointer of a temporary `CString`
.as_ptr_label = this pointer will be invalid

View File

@ -1083,8 +1083,10 @@ pub struct IdentifierUncommonCodepoints;
pub struct ConfusableIdentifierPair {
pub existing_sym: Symbol,
pub sym: Symbol,
#[label]
#[label(lint_other_use)]
pub label: Span,
#[label(lint_current_use)]
pub main_label: Span,
}
#[derive(LintDiagnostic)]

View File

@ -222,6 +222,7 @@ impl EarlyLintPass for NonAsciiIdents {
existing_sym: *existing_symbol,
sym: symbol,
label: *existing_span,
main_label: sp,
},
);
}

View File

@ -5,8 +5,8 @@ const : usize = 42;
const s_s: usize = 42;
fn main() {
let s = "rust"; //~ ERROR identifier pair considered confusable
let _ = "rust2"; //~ ERROR identifier pair considered confusable
let s = "rust"; //~ ERROR found both
let _ = "rust2"; //~ ERROR found both
not_affected();
}

View File

@ -1,11 +1,11 @@
error: identifier pair considered confusable between `` and `s`
error: found both `` and `s` as identifiers, which look alike
--> $DIR/lint-confusable-idents.rs:8:9
|
LL | const : usize = 42;
| -- this is where the previous identifier occurred
| -- other identifier used here
...
LL | let s = "rust";
| ^
| ^ this identifier can be confused with ``
|
note: the lint level is defined here
--> $DIR/lint-confusable-idents.rs:1:9
@ -13,14 +13,14 @@ note: the lint level is defined here
LL | #![deny(confusable_idents)]
| ^^^^^^^^^^^^^^^^^
error: identifier pair considered confusable between `s_s` and `_`
error: found both `s_s` and `_` as identifiers, which look alike
--> $DIR/lint-confusable-idents.rs:9:9
|
LL | const s_s: usize = 42;
| --- this is where the previous identifier occurred
| --- other identifier used here
...
LL | let _ = "rust2";
| ^^^^^
| ^^^^^ this identifier can be confused with `s_s`
error: aborting due to 2 previous errors