Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reword confusable_idents lint #114472

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,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
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1056,8 +1056,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)]
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_lint/src/non_ascii_idents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ impl EarlyLintPass for NonAsciiIdents {
existing_sym: *existing_symbol,
sym: symbol,
label: *existing_span,
main_label: sp,
},
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const s: usize = 42;
const s_s: usize = 42;

fn main() {
let s = "rust"; //~ ERROR identifier pair considered confusable
let s_s = "rust2"; //~ ERROR identifier pair considered confusable
let s = "rust"; //~ ERROR found both
let s_s = "rust2"; //~ ERROR found both
not_affected();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
error: identifier pair considered confusable between `s` and `s`
error: found both `s` and `s` as identifiers, which look alike
--> $DIR/lint-confusable-idents.rs:8:9
|
LL | const s: usize = 42;
| -- this is where the previous identifier occurred
| -- other identifier used here
...
LL | let s = "rust";
| ^
| ^ this identifier can be confused with `s`
|
note: the lint level is defined here
--> $DIR/lint-confusable-idents.rs:1:9
|
LL | #![deny(confusable_idents)]
| ^^^^^^^^^^^^^^^^^

error: identifier pair considered confusable between `s_s` and `s_s`
error: found both `s_s` and `s_s` 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 s_s = "rust2";
| ^^^^^
| ^^^^^ this identifier can be confused with `s_s`

error: aborting due to 2 previous errors