diff options
| author | bors <bors@rust-lang.org> | 2021-03-28 06:32:34 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-03-28 06:32:34 +0000 |
| commit | 5208f63ba8ec70a2a7a074d7ecd59a94693286fc (patch) | |
| tree | b7cf431d74816b089406921bb79739f94ebe0b0d /library/alloc/tests | |
| parent | 1df20569dd07d91ed270ea9cfc2dbb9f56700703 (diff) | |
| parent | 26a62701e42d10c03ce5f2f911e7d5edeefa2f0f (diff) | |
Auto merge of #81728 - Qwaz:fix-80335, r=joshtriplett
Fixes API soundness issue in join() Fixes #80335
Diffstat (limited to 'library/alloc/tests')
| -rw-r--r-- | library/alloc/tests/str.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/library/alloc/tests/str.rs b/library/alloc/tests/str.rs index 604835e6cc4..6df8d8c2f35 100644 --- a/library/alloc/tests/str.rs +++ b/library/alloc/tests/str.rs @@ -161,6 +161,36 @@ fn test_join_for_different_lengths_with_long_separator() { } #[test] +fn test_join_isue_80335() { + use core::{borrow::Borrow, cell::Cell}; + + struct WeirdBorrow { + state: Cell<bool>, + } + + impl Default for WeirdBorrow { + fn default() -> Self { + WeirdBorrow { state: Cell::new(false) } + } + } + + impl Borrow<str> for WeirdBorrow { + fn borrow(&self) -> &str { + let state = self.state.get(); + if state { + "0" + } else { + self.state.set(true); + "123456" + } + } + } + + let arr: [WeirdBorrow; 3] = Default::default(); + test_join!("0-0-0", arr, "-"); +} + +#[test] #[cfg_attr(miri, ignore)] // Miri is too slow fn test_unsafe_slice() { assert_eq!("ab", unsafe { "abc".get_unchecked(0..2) }); |
