allow invalid_from_utf8 lint in tests

This commit is contained in:
David Hewitt 2023-09-23 11:19:07 +01:00
parent 668918f5d3
commit ccc22a905d
2 changed files with 8 additions and 0 deletions

View File

@ -146,6 +146,11 @@ pub fn print_feature_cfgs() {
if rustc_minor_version >= 59 { if rustc_minor_version >= 59 {
println!("cargo:rustc-cfg=thread_local_const_init"); println!("cargo:rustc-cfg=thread_local_const_init");
} }
// invalid_from_utf8 lint was added in Rust 1.74
if rustc_minor_version >= 74 {
println!("cargo:rustc-cfg=invalid_from_utf8_lint");
}
} }
/// Private exports used in PyO3's build.rs /// Private exports used in PyO3's build.rs

View File

@ -635,6 +635,7 @@ impl PyUnicodeDecodeError {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// #![cfg_attr(invalid_from_utf8_lint, allow(invalid_from_utf8))]
/// use pyo3::prelude::*; /// use pyo3::prelude::*;
/// use pyo3::exceptions::PyUnicodeDecodeError; /// use pyo3::exceptions::PyUnicodeDecodeError;
/// ///
@ -1013,6 +1014,7 @@ mod tests {
#[test] #[test]
fn unicode_decode_error() { fn unicode_decode_error() {
let invalid_utf8 = b"fo\xd8o"; let invalid_utf8 = b"fo\xd8o";
#[cfg_attr(invalid_from_utf8_lint, allow(invalid_from_utf8))]
let err = std::str::from_utf8(invalid_utf8).expect_err("should be invalid utf8"); let err = std::str::from_utf8(invalid_utf8).expect_err("should be invalid utf8");
Python::with_gil(|py| { Python::with_gil(|py| {
let decode_err = PyUnicodeDecodeError::new_utf8(py, invalid_utf8, err).unwrap(); let decode_err = PyUnicodeDecodeError::new_utf8(py, invalid_utf8, err).unwrap();
@ -1069,6 +1071,7 @@ mod tests {
test_exception!(PyUnicodeError); test_exception!(PyUnicodeError);
test_exception!(PyUnicodeDecodeError, |py| { test_exception!(PyUnicodeDecodeError, |py| {
let invalid_utf8 = b"fo\xd8o"; let invalid_utf8 = b"fo\xd8o";
#[cfg_attr(invalid_from_utf8_lint, allow(invalid_from_utf8))]
let err = std::str::from_utf8(invalid_utf8).expect_err("should be invalid utf8"); let err = std::str::from_utf8(invalid_utf8).expect_err("should be invalid utf8");
PyErr::from_value(PyUnicodeDecodeError::new_utf8(py, invalid_utf8, err).unwrap()) PyErr::from_value(PyUnicodeDecodeError::new_utf8(py, invalid_utf8, err).unwrap())
}); });