From 476dfc24b311a837f931e678c4bdfbb99d29f4e4 Mon Sep 17 00:00:00 2001 From: blake2-ppc Date: Mon, 5 Aug 2013 17:52:03 +0200 Subject: [PATCH] std: Use correct lifetime parameter on str::raw::slice_bytes 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 5c6895fea43c..f1a44c4b3863 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -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));