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".
This commit is contained in:
commit
86f3d525e0
7 changed files with 274 additions and 47 deletions
|
@ -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
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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) }
|
||||
|
|
|
@ -2,8 +2,8 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_the
|
|||
use clippy_utils::source::{snippet, snippet_with_applicability};
|
||||
use clippy_utils::ty::is_type_lang_item;
|
||||
use clippy_utils::{
|
||||
SpanlessEq, get_expr_use_or_unification_node, get_parent_expr, is_lint_allowed, is_path_diagnostic_item,
|
||||
method_calls, peel_blocks,
|
||||
SpanlessEq, get_expr_use_or_unification_node, get_parent_expr, is_lint_allowed, method_calls, path_def_id,
|
||||
peel_blocks,
|
||||
};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::def_id::DefId;
|
||||
|
@ -253,8 +253,9 @@ impl<'tcx> LateLintPass<'tcx> for StringLitAsBytes {
|
|||
use rustc_ast::LitKind;
|
||||
|
||||
if let ExprKind::Call(fun, [bytes_arg]) = e.kind
|
||||
// Find std::str::converts::from_utf8
|
||||
&& is_path_diagnostic_item(cx, fun, sym::str_from_utf8)
|
||||
// Find `std::str::converts::from_utf8` or `std::primitive::str::from_utf8`
|
||||
&& let Some(sym::str_from_utf8 | sym::str_inherent_from_utf8) =
|
||||
path_def_id(cx, fun).and_then(|id| cx.tcx.get_diagnostic_name(id))
|
||||
|
||||
// Find string::as_bytes
|
||||
&& let ExprKind::AddrOf(BorrowKind::Ref, _, args) = bytes_arg.kind
|
||||
|
|
|
@ -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() {}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue