Skip to content

Commit 476dfc2

Browse files
author
blake2-ppc
committed
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.
1 parent dbaca98 commit 476dfc2

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/libstd/str.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ pub mod raw {
885885
/// If begin is greater than end.
886886
/// If end is greater than the length of the string.
887887
#[inline]
888-
pub unsafe fn slice_bytes(s: &str, begin: uint, end: uint) -> &str {
888+
pub unsafe fn slice_bytes<'a>(s: &'a str, begin: uint, end: uint) -> &'a str {
889889
do s.as_imm_buf |sbuf, n| {
890890
assert!((begin <= end));
891891
assert!((end <= n));

0 commit comments

Comments
 (0)