diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 095605326c7f5..800e2dcc27893 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -562,7 +562,7 @@ enum Searcher { impl Searcher { fn new(haystack: &[u8], needle: &[u8]) -> Searcher { // FIXME: Tune this. - if needle.len() > haystack.len() - 20 { + if needle.len() + 20 > haystack.len() { Naive(NaiveSearcher::new()) } else { let searcher = TwoWaySearcher::new(needle); diff --git a/src/libcoretest/lib.rs b/src/libcoretest/lib.rs index 3864321586ca6..7866d2f4a111c 100644 --- a/src/libcoretest/lib.rs +++ b/src/libcoretest/lib.rs @@ -29,4 +29,5 @@ mod ptr; mod raw; mod result; mod slice; +mod str; mod tuple; diff --git a/src/libcoretest/str.rs b/src/libcoretest/str.rs new file mode 100644 index 0000000000000..bac8d509b1314 --- /dev/null +++ b/src/libcoretest/str.rs @@ -0,0 +1,14 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[test] +fn strslice_issue_16589() { + assert!("bananas".contains("nana")); +}