From f53d0f502dba3b378d8baef159b97e685ba40f33 Mon Sep 17 00:00:00 2001 From: Pavel Grigorenko Date: Sun, 16 Feb 2025 00:40:25 +0300 Subject: [PATCH] invalid_from_utf8[_unchecked]: also lint inherent methods --- compiler/rustc_lint/messages.ftl | 4 +- compiler/rustc_lint/src/invalid_from_utf8.rs | 10 +- compiler/rustc_span/src/symbol.rs | 4 + library/core/src/str/mod.rs | 4 + tests/ui/lint/invalid_from_utf8.rs | 53 ++++- tests/ui/lint/invalid_from_utf8.stderr | 237 ++++++++++++++++--- 6 files changed, 269 insertions(+), 43 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 62723e385cf..4c2f7ad6d3c 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, diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs index 05c16791ce7..fd2cd59f88e 100644 --- a/library/core/src/str/mod.rs +++ b/library/core/src/str/mod.rs @@ -238,6 +238,7 @@ impl str { /// assert_eq!("💖", sparkle_heart); /// ``` #[unstable(feature = "inherent_str_constructors", issue = "131114")] + #[rustc_diagnostic_item = "str_inherent_from_utf8"] pub const fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error> { converts::from_utf8(v) } @@ -274,6 +275,7 @@ impl str { /// errors that can be returned. #[unstable(feature = "inherent_str_constructors", issue = "131114")] #[rustc_const_unstable(feature = "const_str_from_utf8", issue = "91006")] + #[rustc_diagnostic_item = "str_inherent_from_utf8_mut"] pub const fn from_utf8_mut(v: &mut [u8]) -> Result<&mut str, Utf8Error> { converts::from_utf8_mut(v) } @@ -306,6 +308,7 @@ impl str { #[inline] #[must_use] #[unstable(feature = "inherent_str_constructors", issue = "131114")] + #[rustc_diagnostic_item = "str_inherent_from_utf8_unchecked"] pub const unsafe fn from_utf8_unchecked(v: &[u8]) -> &str { // SAFETY: converts::from_utf8_unchecked has the same safety requirements as this function. unsafe { converts::from_utf8_unchecked(v) } @@ -331,6 +334,7 @@ impl str { #[inline] #[must_use] #[unstable(feature = "inherent_str_constructors", issue = "131114")] + #[rustc_diagnostic_item = "str_inherent_from_utf8_unchecked_mut"] pub const unsafe fn from_utf8_unchecked_mut(v: &mut [u8]) -> &mut str { // SAFETY: converts::from_utf8_unchecked_mut has the same safety requirements as this function. unsafe { converts::from_utf8_unchecked_mut(v) } diff --git a/tests/ui/lint/invalid_from_utf8.rs b/tests/ui/lint/invalid_from_utf8.rs index 2d1822a54ac..8f8000fe34d 100644 --- a/tests/ui/lint/invalid_from_utf8.rs +++ b/tests/ui/lint/invalid_from_utf8.rs @@ -1,7 +1,7 @@ //@ check-pass #![feature(concat_bytes)] - +#![feature(inherent_str_constructors)] #![warn(invalid_from_utf8_unchecked)] #![warn(invalid_from_utf8)] @@ -9,7 +9,9 @@ pub fn from_utf8_unchecked_mut() { // Valid unsafe { std::str::from_utf8_unchecked_mut(&mut [99, 108, 105, 112, 112, 121]); + str::from_utf8_unchecked_mut(&mut [99, 108, 105, 112, 112, 121]); std::str::from_utf8_unchecked_mut(&mut [b'c', b'l', b'i', b'p', b'p', b'y']); + str::from_utf8_unchecked_mut(&mut [b'c', b'l', b'i', b'p', b'p', b'y']); let x = 0xA0; std::str::from_utf8_unchecked_mut(&mut [0xC0, x]); @@ -19,8 +21,12 @@ pub fn from_utf8_unchecked_mut() { unsafe { std::str::from_utf8_unchecked_mut(&mut [99, 108, 130, 105, 112, 112, 121]); //~^ WARN calls to `std::str::from_utf8_unchecked_mut` + str::from_utf8_unchecked_mut(&mut [99, 108, 130, 105, 112, 112, 121]); + //~^ WARN calls to `str::from_utf8_unchecked_mut` std::str::from_utf8_unchecked_mut(&mut [b'c', b'l', b'\x82', b'i', b'p', b'p', b'y']); //~^ WARN calls to `std::str::from_utf8_unchecked_mut` + str::from_utf8_unchecked_mut(&mut [b'c', b'l', b'\x82', b'i', b'p', b'p', b'y']); + //~^ WARN calls to `str::from_utf8_unchecked_mut` } } @@ -28,23 +34,35 @@ pub fn from_utf8_unchecked() { // Valid unsafe { std::str::from_utf8_unchecked(&[99, 108, 105, 112, 112, 121]); + str::from_utf8_unchecked(&[99, 108, 105, 112, 112, 121]); std::str::from_utf8_unchecked(&[b'c', b'l', b'i', b'p', b'p', b'y']); + str::from_utf8_unchecked(&[b'c', b'l', b'i', b'p', b'p', b'y']); std::str::from_utf8_unchecked(b"clippy"); + str::from_utf8_unchecked(b"clippy"); let x = 0xA0; std::str::from_utf8_unchecked(&[0xC0, x]); + str::from_utf8_unchecked(&[0xC0, x]); } // Invalid unsafe { std::str::from_utf8_unchecked(&[99, 108, 130, 105, 112, 112, 121]); //~^ WARN calls to `std::str::from_utf8_unchecked` + str::from_utf8_unchecked(&[99, 108, 130, 105, 112, 112, 121]); + //~^ WARN calls to `str::from_utf8_unchecked` std::str::from_utf8_unchecked(&[b'c', b'l', b'\x82', b'i', b'p', b'p', b'y']); //~^ WARN calls to `std::str::from_utf8_unchecked` + str::from_utf8_unchecked(&[b'c', b'l', b'\x82', b'i', b'p', b'p', b'y']); + //~^ WARN calls to `str::from_utf8_unchecked` std::str::from_utf8_unchecked(b"cl\x82ippy"); //~^ WARN calls to `std::str::from_utf8_unchecked` + str::from_utf8_unchecked(b"cl\x82ippy"); + //~^ WARN calls to `str::from_utf8_unchecked` std::str::from_utf8_unchecked(concat_bytes!(b"cl", b"\x82ippy")); //~^ WARN calls to `std::str::from_utf8_unchecked` + str::from_utf8_unchecked(concat_bytes!(b"cl", b"\x82ippy")); + //~^ WARN calls to `str::from_utf8_unchecked` } } @@ -52,18 +70,25 @@ pub fn from_utf8_mut() { // Valid { std::str::from_utf8_mut(&mut [99, 108, 105, 112, 112, 121]); + str::from_utf8_mut(&mut [99, 108, 105, 112, 112, 121]); std::str::from_utf8_mut(&mut [b'c', b'l', b'i', b'p', b'p', b'y']); + str::from_utf8_mut(&mut [b'c', b'l', b'i', b'p', b'p', b'y']); let x = 0xa0; std::str::from_utf8_mut(&mut [0xc0, x]); + str::from_utf8_mut(&mut [0xc0, x]); } // Invalid { std::str::from_utf8_mut(&mut [99, 108, 130, 105, 112, 112, 121]); //~^ WARN calls to `std::str::from_utf8_mut` + str::from_utf8_mut(&mut [99, 108, 130, 105, 112, 112, 121]); + //~^ WARN calls to `str::from_utf8_mut` std::str::from_utf8_mut(&mut [b'c', b'l', b'\x82', b'i', b'p', b'p', b'y']); //~^ WARN calls to `std::str::from_utf8_mut` + str::from_utf8_mut(&mut [b'c', b'l', b'\x82', b'i', b'p', b'p', b'y']); + //~^ WARN calls to `str::from_utf8_mut` } } @@ -71,23 +96,35 @@ pub fn from_utf8() { // Valid { std::str::from_utf8(&[99, 108, 105, 112, 112, 121]); + str::from_utf8(&[99, 108, 105, 112, 112, 121]); std::str::from_utf8(&[b'c', b'l', b'i', b'p', b'p', b'y']); + str::from_utf8(&[b'c', b'l', b'i', b'p', b'p', b'y']); std::str::from_utf8(b"clippy"); + str::from_utf8(b"clippy"); let x = 0xA0; std::str::from_utf8(&[0xC0, x]); + str::from_utf8(&[0xC0, x]); } // Invalid { std::str::from_utf8(&[99, 108, 130, 105, 112, 112, 121]); //~^ WARN calls to `std::str::from_utf8` + str::from_utf8(&[99, 108, 130, 105, 112, 112, 121]); + //~^ WARN calls to `str::from_utf8` std::str::from_utf8(&[b'c', b'l', b'\x82', b'i', b'p', b'p', b'y']); //~^ WARN calls to `std::str::from_utf8` + str::from_utf8(&[b'c', b'l', b'\x82', b'i', b'p', b'p', b'y']); + //~^ WARN calls to `str::from_utf8` std::str::from_utf8(b"cl\x82ippy"); //~^ WARN calls to `std::str::from_utf8` + str::from_utf8(b"cl\x82ippy"); + //~^ WARN calls to `str::from_utf8` std::str::from_utf8(concat_bytes!(b"cl", b"\x82ippy")); //~^ WARN calls to `std::str::from_utf8` + str::from_utf8(concat_bytes!(b"cl", b"\x82ippy")); + //~^ WARN calls to `str::from_utf8` } } @@ -95,25 +132,39 @@ pub fn from_utf8_with_indirections() { let mut a = [99, 108, 130, 105, 112, 112, 121]; std::str::from_utf8_mut(&mut a); //~^ WARN calls to `std::str::from_utf8_mut` + str::from_utf8_mut(&mut a); + //~^ WARN calls to `str::from_utf8_mut` let mut b = &mut a; let mut c = b; std::str::from_utf8_mut(c); //~^ WARN calls to `std::str::from_utf8_mut` + str::from_utf8_mut(c); + //~^ WARN calls to `str::from_utf8_mut` let mut c = &[99, 108, 130, 105, 112, 112, 121]; std::str::from_utf8(c); //~^ WARN calls to `std::str::from_utf8` + str::from_utf8(c); + //~^ WARN calls to `str::from_utf8` const INVALID_1: [u8; 7] = [99, 108, 130, 105, 112, 112, 121]; std::str::from_utf8(&INVALID_1); //~^ WARN calls to `std::str::from_utf8` + str::from_utf8(&INVALID_1); + //~^ WARN calls to `str::from_utf8` static INVALID_2: [u8; 7] = [99, 108, 130, 105, 112, 112, 121]; std::str::from_utf8(&INVALID_2); //~^ WARN calls to `std::str::from_utf8` + str::from_utf8(&INVALID_2); + //~^ WARN calls to `str::from_utf8` const INVALID_3: &'static [u8; 7] = &[99, 108, 130, 105, 112, 112, 121]; std::str::from_utf8(INVALID_3); //~^ WARN calls to `std::str::from_utf8` + str::from_utf8(INVALID_3); + //~^ WARN calls to `str::from_utf8` const INVALID_4: &'static [u8; 7] = { &[99, 108, 130, 105, 112, 112, 121] }; std::str::from_utf8(INVALID_4); //~^ WARN calls to `std::str::from_utf8` + str::from_utf8(INVALID_4); + //~^ WARN calls to `str::from_utf8` } fn main() {} diff --git a/tests/ui/lint/invalid_from_utf8.stderr b/tests/ui/lint/invalid_from_utf8.stderr index 07616e11801..715ecf56f21 100644 --- a/tests/ui/lint/invalid_from_utf8.stderr +++ b/tests/ui/lint/invalid_from_utf8.stderr @@ -1,5 +1,5 @@ -warning: calls to `std::str::from_utf8_unchecked_mut` with a invalid literal are undefined behavior - --> $DIR/invalid_from_utf8.rs:20:9 +warning: calls to `std::str::from_utf8_unchecked_mut` with an invalid literal are undefined behavior + --> $DIR/invalid_from_utf8.rs:22:9 | LL | std::str::from_utf8_unchecked_mut(&mut [99, 108, 130, 105, 112, 112, 121]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^----------------------------------^ @@ -12,48 +12,96 @@ note: the lint level is defined here LL | #![warn(invalid_from_utf8_unchecked)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -warning: calls to `std::str::from_utf8_unchecked_mut` with a invalid literal are undefined behavior - --> $DIR/invalid_from_utf8.rs:22:9 +warning: calls to `str::from_utf8_unchecked_mut` with an invalid literal are undefined behavior + --> $DIR/invalid_from_utf8.rs:24:9 + | +LL | str::from_utf8_unchecked_mut(&mut [99, 108, 130, 105, 112, 112, 121]); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^----------------------------------^ + | | + | the literal was valid UTF-8 up to the 2 bytes + +warning: calls to `std::str::from_utf8_unchecked_mut` with an invalid literal are undefined behavior + --> $DIR/invalid_from_utf8.rs:26:9 | LL | std::str::from_utf8_unchecked_mut(&mut [b'c', b'l', b'\x82', b'i', b'p', b'p', b'y']); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------------------------------------^ | | | the literal was valid UTF-8 up to the 2 bytes -warning: calls to `std::str::from_utf8_unchecked` with a invalid literal are undefined behavior - --> $DIR/invalid_from_utf8.rs:40:9 +warning: calls to `str::from_utf8_unchecked_mut` with an invalid literal are undefined behavior + --> $DIR/invalid_from_utf8.rs:28:9 + | +LL | str::from_utf8_unchecked_mut(&mut [b'c', b'l', b'\x82', b'i', b'p', b'p', b'y']); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------------------------------------^ + | | + | the literal was valid UTF-8 up to the 2 bytes + +warning: calls to `std::str::from_utf8_unchecked` with an invalid literal are undefined behavior + --> $DIR/invalid_from_utf8.rs:50:9 | LL | std::str::from_utf8_unchecked(&[99, 108, 130, 105, 112, 112, 121]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^----------------------------------^ | | | the literal was valid UTF-8 up to the 2 bytes -warning: calls to `std::str::from_utf8_unchecked` with a invalid literal are undefined behavior - --> $DIR/invalid_from_utf8.rs:42:9 +warning: calls to `str::from_utf8_unchecked` with an invalid literal are undefined behavior + --> $DIR/invalid_from_utf8.rs:52:9 + | +LL | str::from_utf8_unchecked(&[99, 108, 130, 105, 112, 112, 121]); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^----------------------------------^ + | | + | the literal was valid UTF-8 up to the 2 bytes + +warning: calls to `std::str::from_utf8_unchecked` with an invalid literal are undefined behavior + --> $DIR/invalid_from_utf8.rs:54:9 | LL | std::str::from_utf8_unchecked(&[b'c', b'l', b'\x82', b'i', b'p', b'p', b'y']); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------------------------------------^ | | | the literal was valid UTF-8 up to the 2 bytes -warning: calls to `std::str::from_utf8_unchecked` with a invalid literal are undefined behavior - --> $DIR/invalid_from_utf8.rs:44:9 +warning: calls to `str::from_utf8_unchecked` with an invalid literal are undefined behavior + --> $DIR/invalid_from_utf8.rs:56:9 + | +LL | str::from_utf8_unchecked(&[b'c', b'l', b'\x82', b'i', b'p', b'p', b'y']); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^---------------------------------------------^ + | | + | the literal was valid UTF-8 up to the 2 bytes + +warning: calls to `std::str::from_utf8_unchecked` with an invalid literal are undefined behavior + --> $DIR/invalid_from_utf8.rs:58:9 | LL | std::str::from_utf8_unchecked(b"cl\x82ippy"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-------------^ | | | the literal was valid UTF-8 up to the 2 bytes -warning: calls to `std::str::from_utf8_unchecked` with a invalid literal are undefined behavior - --> $DIR/invalid_from_utf8.rs:46:9 +warning: calls to `str::from_utf8_unchecked` with an invalid literal are undefined behavior + --> $DIR/invalid_from_utf8.rs:60:9 + | +LL | str::from_utf8_unchecked(b"cl\x82ippy"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^-------------^ + | | + | the literal was valid UTF-8 up to the 2 bytes + +warning: calls to `std::str::from_utf8_unchecked` with an invalid literal are undefined behavior + --> $DIR/invalid_from_utf8.rs:62:9 | LL | std::str::from_utf8_unchecked(concat_bytes!(b"cl", b"\x82ippy")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------------------------^ | | | the literal was valid UTF-8 up to the 2 bytes -warning: calls to `std::str::from_utf8_mut` with a invalid literal always return an error - --> $DIR/invalid_from_utf8.rs:63:9 +warning: calls to `str::from_utf8_unchecked` with an invalid literal are undefined behavior + --> $DIR/invalid_from_utf8.rs:64:9 + | +LL | str::from_utf8_unchecked(concat_bytes!(b"cl", b"\x82ippy")); + | ^^^^^^^^^^^^^^^^^^^^^^^^^---------------------------------^ + | | + | the literal was valid UTF-8 up to the 2 bytes + +warning: calls to `std::str::from_utf8_mut` with an invalid literal always return an error + --> $DIR/invalid_from_utf8.rs:84:9 | LL | std::str::from_utf8_mut(&mut [99, 108, 130, 105, 112, 112, 121]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^----------------------------------^ @@ -66,56 +114,113 @@ note: the lint level is defined here LL | #![warn(invalid_from_utf8)] | ^^^^^^^^^^^^^^^^^ -warning: calls to `std::str::from_utf8_mut` with a invalid literal always return an error - --> $DIR/invalid_from_utf8.rs:65:9 +warning: calls to `str::from_utf8_mut` with an invalid literal always return an error + --> $DIR/invalid_from_utf8.rs:86:9 + | +LL | str::from_utf8_mut(&mut [99, 108, 130, 105, 112, 112, 121]); + | ^^^^^^^^^^^^^^^^^^^^^^^^----------------------------------^ + | | + | the literal was valid UTF-8 up to the 2 bytes + +warning: calls to `std::str::from_utf8_mut` with an invalid literal always return an error + --> $DIR/invalid_from_utf8.rs:88:9 | LL | std::str::from_utf8_mut(&mut [b'c', b'l', b'\x82', b'i', b'p', b'p', b'y']); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------------------------------------^ | | | the literal was valid UTF-8 up to the 2 bytes -warning: calls to `std::str::from_utf8` with a invalid literal always return an error - --> $DIR/invalid_from_utf8.rs:83:9 +warning: calls to `str::from_utf8_mut` with an invalid literal always return an error + --> $DIR/invalid_from_utf8.rs:90:9 + | +LL | str::from_utf8_mut(&mut [b'c', b'l', b'\x82', b'i', b'p', b'p', b'y']); + | ^^^^^^^^^^^^^^^^^^^^^^^^---------------------------------------------^ + | | + | the literal was valid UTF-8 up to the 2 bytes + +warning: calls to `std::str::from_utf8` with an invalid literal always return an error + --> $DIR/invalid_from_utf8.rs:112:9 | LL | std::str::from_utf8(&[99, 108, 130, 105, 112, 112, 121]); | ^^^^^^^^^^^^^^^^^^^^^----------------------------------^ | | | the literal was valid UTF-8 up to the 2 bytes -warning: calls to `std::str::from_utf8` with a invalid literal always return an error - --> $DIR/invalid_from_utf8.rs:85:9 +warning: calls to `str::from_utf8` with an invalid literal always return an error + --> $DIR/invalid_from_utf8.rs:114:9 + | +LL | str::from_utf8(&[99, 108, 130, 105, 112, 112, 121]); + | ^^^^^^^^^^^^^^^^----------------------------------^ + | | + | the literal was valid UTF-8 up to the 2 bytes + +warning: calls to `std::str::from_utf8` with an invalid literal always return an error + --> $DIR/invalid_from_utf8.rs:116:9 | LL | std::str::from_utf8(&[b'c', b'l', b'\x82', b'i', b'p', b'p', b'y']); | ^^^^^^^^^^^^^^^^^^^^^---------------------------------------------^ | | | the literal was valid UTF-8 up to the 2 bytes -warning: calls to `std::str::from_utf8` with a invalid literal always return an error - --> $DIR/invalid_from_utf8.rs:87:9 +warning: calls to `str::from_utf8` with an invalid literal always return an error + --> $DIR/invalid_from_utf8.rs:118:9 + | +LL | str::from_utf8(&[b'c', b'l', b'\x82', b'i', b'p', b'p', b'y']); + | ^^^^^^^^^^^^^^^^---------------------------------------------^ + | | + | the literal was valid UTF-8 up to the 2 bytes + +warning: calls to `std::str::from_utf8` with an invalid literal always return an error + --> $DIR/invalid_from_utf8.rs:120:9 | LL | std::str::from_utf8(b"cl\x82ippy"); | ^^^^^^^^^^^^^^^^^^^^-------------^ | | | the literal was valid UTF-8 up to the 2 bytes -warning: calls to `std::str::from_utf8` with a invalid literal always return an error - --> $DIR/invalid_from_utf8.rs:89:9 +warning: calls to `str::from_utf8` with an invalid literal always return an error + --> $DIR/invalid_from_utf8.rs:122:9 + | +LL | str::from_utf8(b"cl\x82ippy"); + | ^^^^^^^^^^^^^^^-------------^ + | | + | the literal was valid UTF-8 up to the 2 bytes + +warning: calls to `std::str::from_utf8` with an invalid literal always return an error + --> $DIR/invalid_from_utf8.rs:124:9 | LL | std::str::from_utf8(concat_bytes!(b"cl", b"\x82ippy")); | ^^^^^^^^^^^^^^^^^^^^---------------------------------^ | | | the literal was valid UTF-8 up to the 2 bytes -warning: calls to `std::str::from_utf8_mut` with a invalid literal always return an error - --> $DIR/invalid_from_utf8.rs:96:5 +warning: calls to `str::from_utf8` with an invalid literal always return an error + --> $DIR/invalid_from_utf8.rs:126:9 + | +LL | str::from_utf8(concat_bytes!(b"cl", b"\x82ippy")); + | ^^^^^^^^^^^^^^^---------------------------------^ + | | + | the literal was valid UTF-8 up to the 2 bytes + +warning: calls to `std::str::from_utf8_mut` with an invalid literal always return an error + --> $DIR/invalid_from_utf8.rs:133:5 | LL | let mut a = [99, 108, 130, 105, 112, 112, 121]; | ---------------------------------- the literal was valid UTF-8 up to the 2 bytes LL | std::str::from_utf8_mut(&mut a); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -warning: calls to `std::str::from_utf8_mut` with a invalid literal always return an error - --> $DIR/invalid_from_utf8.rs:100:5 +warning: calls to `str::from_utf8_mut` with an invalid literal always return an error + --> $DIR/invalid_from_utf8.rs:135:5 + | +LL | let mut a = [99, 108, 130, 105, 112, 112, 121]; + | ---------------------------------- the literal was valid UTF-8 up to the 2 bytes +... +LL | str::from_utf8_mut(&mut a); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: calls to `std::str::from_utf8_mut` with an invalid literal always return an error + --> $DIR/invalid_from_utf8.rs:139:5 | LL | let mut a = [99, 108, 130, 105, 112, 112, 121]; | ---------------------------------- the literal was valid UTF-8 up to the 2 bytes @@ -123,45 +228,99 @@ LL | let mut a = [99, 108, 130, 105, 112, 112, 121]; LL | std::str::from_utf8_mut(c); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -warning: calls to `std::str::from_utf8` with a invalid literal always return an error - --> $DIR/invalid_from_utf8.rs:103:5 +warning: calls to `str::from_utf8_mut` with an invalid literal always return an error + --> $DIR/invalid_from_utf8.rs:141:5 + | +LL | let mut a = [99, 108, 130, 105, 112, 112, 121]; + | ---------------------------------- the literal was valid UTF-8 up to the 2 bytes +... +LL | str::from_utf8_mut(c); + | ^^^^^^^^^^^^^^^^^^^^^ + +warning: calls to `std::str::from_utf8` with an invalid literal always return an error + --> $DIR/invalid_from_utf8.rs:144:5 | LL | let mut c = &[99, 108, 130, 105, 112, 112, 121]; | ---------------------------------- the literal was valid UTF-8 up to the 2 bytes LL | std::str::from_utf8(c); | ^^^^^^^^^^^^^^^^^^^^^^ -warning: calls to `std::str::from_utf8` with a invalid literal always return an error - --> $DIR/invalid_from_utf8.rs:106:5 +warning: calls to `str::from_utf8` with an invalid literal always return an error + --> $DIR/invalid_from_utf8.rs:146:5 + | +LL | let mut c = &[99, 108, 130, 105, 112, 112, 121]; + | ---------------------------------- the literal was valid UTF-8 up to the 2 bytes +... +LL | str::from_utf8(c); + | ^^^^^^^^^^^^^^^^^ + +warning: calls to `std::str::from_utf8` with an invalid literal always return an error + --> $DIR/invalid_from_utf8.rs:149:5 | LL | const INVALID_1: [u8; 7] = [99, 108, 130, 105, 112, 112, 121]; | ---------------------------------- the literal was valid UTF-8 up to the 2 bytes LL | std::str::from_utf8(&INVALID_1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -warning: calls to `std::str::from_utf8` with a invalid literal always return an error - --> $DIR/invalid_from_utf8.rs:109:5 +warning: calls to `str::from_utf8` with an invalid literal always return an error + --> $DIR/invalid_from_utf8.rs:151:5 + | +LL | const INVALID_1: [u8; 7] = [99, 108, 130, 105, 112, 112, 121]; + | ---------------------------------- the literal was valid UTF-8 up to the 2 bytes +... +LL | str::from_utf8(&INVALID_1); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: calls to `std::str::from_utf8` with an invalid literal always return an error + --> $DIR/invalid_from_utf8.rs:154:5 | LL | static INVALID_2: [u8; 7] = [99, 108, 130, 105, 112, 112, 121]; | ---------------------------------- the literal was valid UTF-8 up to the 2 bytes LL | std::str::from_utf8(&INVALID_2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -warning: calls to `std::str::from_utf8` with a invalid literal always return an error - --> $DIR/invalid_from_utf8.rs:112:5 +warning: calls to `str::from_utf8` with an invalid literal always return an error + --> $DIR/invalid_from_utf8.rs:156:5 + | +LL | static INVALID_2: [u8; 7] = [99, 108, 130, 105, 112, 112, 121]; + | ---------------------------------- the literal was valid UTF-8 up to the 2 bytes +... +LL | str::from_utf8(&INVALID_2); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: calls to `std::str::from_utf8` with an invalid literal always return an error + --> $DIR/invalid_from_utf8.rs:159:5 | LL | const INVALID_3: &'static [u8; 7] = &[99, 108, 130, 105, 112, 112, 121]; | ---------------------------------- the literal was valid UTF-8 up to the 2 bytes LL | std::str::from_utf8(INVALID_3); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -warning: calls to `std::str::from_utf8` with a invalid literal always return an error - --> $DIR/invalid_from_utf8.rs:115:5 +warning: calls to `str::from_utf8` with an invalid literal always return an error + --> $DIR/invalid_from_utf8.rs:161:5 + | +LL | const INVALID_3: &'static [u8; 7] = &[99, 108, 130, 105, 112, 112, 121]; + | ---------------------------------- the literal was valid UTF-8 up to the 2 bytes +... +LL | str::from_utf8(INVALID_3); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: calls to `std::str::from_utf8` with an invalid literal always return an error + --> $DIR/invalid_from_utf8.rs:164:5 | LL | const INVALID_4: &'static [u8; 7] = { &[99, 108, 130, 105, 112, 112, 121] }; | ---------------------------------- the literal was valid UTF-8 up to the 2 bytes LL | std::str::from_utf8(INVALID_4); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -warning: 19 warnings emitted +warning: calls to `str::from_utf8` with an invalid literal always return an error + --> $DIR/invalid_from_utf8.rs:166:5 + | +LL | const INVALID_4: &'static [u8; 7] = { &[99, 108, 130, 105, 112, 112, 121] }; + | ---------------------------------- the literal was valid UTF-8 up to the 2 bytes +... +LL | str::from_utf8(INVALID_4); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: 38 warnings emitted