]> git.lizzy.rs Git - rust.git/commitdiff
auto merge of #8308 : blake2-ppc/rust/str-slice-bytes, r=alexcrichton
authorbors <bors@rust-lang.org>
Tue, 6 Aug 2013 12:26:01 +0000 (05:26 -0700)
committerbors <bors@rust-lang.org>
Tue, 6 Aug 2013 12:26:01 +0000 (05:26 -0700)
`fn slice_bytes` is marked unsafe since it allows violating the valid
string encoding property; but the function did also allow extending the
lifetime of the slice by mistake, since it's returning `&str`.

Use the annotation `slice_bytes<'a>(&'a str, ...) -> &'a str` so
that all uses of `slice_bytes` are region checked correctly.

src/libstd/str.rs

index 95a411a3f96736009bd2461e6dc137a2656badcf..b4057b85cbfef5cbfae74b54555c359c3e9f5376 100644 (file)
@@ -885,7 +885,7 @@ pub unsafe fn c_str_to_static_slice(s: *libc::c_char) -> &'static str {
     /// If begin is greater than end.
     /// If end is greater than the length of the string.
     #[inline]
-    pub unsafe fn slice_bytes(s: &str, begin: uint, end: uint) -> &str {
+    pub unsafe fn slice_bytes<'a>(s: &'a str, begin: uint, end: uint) -> &'a str {
         do s.as_imm_buf |sbuf, n| {
              assert!((begin <= end));
              assert!((end <= n));