diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2025-02-17 06:37:38 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-17 06:37:38 +0100 |
| commit | 86f3d525e0d16decc3ea82ac226462effcbd87b4 (patch) | |
| tree | 3e4ccd52451535d502e505129dd949b93ecaf152 /compiler | |
| parent | 5dd48bce7cfc25c605518e55a2e8d834e799addf (diff) | |
| parent | 77571a5c8bd1a8958865de75b8ec8b1bc2b4b756 (diff) | |
| download | rust-86f3d525e0d16decc3ea82ac226462effcbd87b4.tar.gz rust-86f3d525e0d16decc3ea82ac226462effcbd87b4.zip | |
Rollup merge of #137101 - GrigorenkoPV:str-inherent-lint, r=Urgau
`invalid_from_utf8[_unchecked]`: also lint inherent methods Addressing https://github.com/rust-lang/rust/issues/131114#issuecomment-2646663535 Also corrected a typo: "_an_ invalid literal", not "_a_ invalid literal".
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_lint/messages.ftl | 4 | ||||
| -rw-r--r-- | compiler/rustc_lint/src/invalid_from_utf8.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_span/src/symbol.rs | 4 |
3 files changed, 15 insertions, 3 deletions
diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl index 480d97e377a..dbe24c9cdf2 100644 --- a/compiler/rustc_lint/messages.ftl +++ b/compiler/rustc_lint/messages.ftl @@ -439,11 +439,11 @@ lint_invalid_crate_type_value = invalid `crate_type` value .suggestion = did you mean # FIXME: we should ordinalize $valid_up_to when we add support for doing so -lint_invalid_from_utf8_checked = calls to `{$method}` with a invalid literal always return an error +lint_invalid_from_utf8_checked = calls to `{$method}` with an invalid literal always return an error .label = the literal was valid UTF-8 up to the {$valid_up_to} bytes # FIXME: we should ordinalize $valid_up_to when we add support for doing so -lint_invalid_from_utf8_unchecked = calls to `{$method}` with a invalid literal are undefined behavior +lint_invalid_from_utf8_unchecked = calls to `{$method}` with an invalid literal are undefined behavior .label = the literal was valid UTF-8 up to the {$valid_up_to} bytes lint_invalid_nan_comparisons_eq_ne = incorrect NaN comparison, NaN cannot be directly compared to itself diff --git a/compiler/rustc_lint/src/invalid_from_utf8.rs b/compiler/rustc_lint/src/invalid_from_utf8.rs index 0081374922e..11eb079ddc0 100644 --- a/compiler/rustc_lint/src/invalid_from_utf8.rs +++ b/compiler/rustc_lint/src/invalid_from_utf8.rs @@ -70,12 +70,20 @@ impl<'tcx> LateLintPass<'tcx> for InvalidFromUtf8 { sym::str_from_utf8_mut, sym::str_from_utf8_unchecked, sym::str_from_utf8_unchecked_mut, + sym::str_inherent_from_utf8, + sym::str_inherent_from_utf8_mut, + sym::str_inherent_from_utf8_unchecked, + sym::str_inherent_from_utf8_unchecked_mut, ] .contains(&diag_item) { let lint = |label, utf8_error: Utf8Error| { let method = diag_item.as_str().strip_prefix("str_").unwrap(); - let method = format!("std::str::{method}"); + let method = if let Some(method) = method.strip_prefix("inherent_") { + format!("str::{method}") + } else { + format!("std::str::{method}") + }; let valid_up_to = utf8_error.valid_up_to(); let is_unchecked_variant = diag_item.as_str().contains("unchecked"); diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 1bd97916d1c..7f8b68bba81 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1973,6 +1973,10 @@ symbols! { str_from_utf8_mut, str_from_utf8_unchecked, str_from_utf8_unchecked_mut, + str_inherent_from_utf8, + str_inherent_from_utf8_mut, + str_inherent_from_utf8_unchecked, + str_inherent_from_utf8_unchecked_mut, str_len, str_split_whitespace, str_starts_with, |
