]> git.lizzy.rs Git - rust.git/blobdiff - library/alloc/tests/str.rs
Rollup merge of #106917 - compiler-errors:const-closure-foreign, r=tmiasko
[rust.git] / library / alloc / tests / str.rs
index 9689196ef21ac78d537ebb9926a249bd3fd331f6..4d182be02c9e9588aaec476b19a19d0693d11983 100644 (file)
@@ -1631,6 +1631,18 @@ fn strslice_issue_16878() {
     assert!(!"00abc01234567890123456789abc".contains("bcabc"));
 }
 
+#[test]
+fn strslice_issue_104726() {
+    // Edge-case in the simd_contains impl.
+    // The first and last byte are the same so it backtracks by one byte
+    // which aligns with the end of the string. Previously incorrect offset calculations
+    // lead to out-of-bounds slicing.
+    #[rustfmt::skip]
+    let needle =                        "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaba";
+    let haystack = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab";
+    assert!(!haystack.contains(needle));
+}
+
 #[test]
 #[cfg_attr(miri, ignore)] // Miri is too slow
 fn test_strslice_contains() {