A slice points into an existing string, so the normal borrowing rules apply to both the slice and its source. The compiler prevents the source from being invalidated while the slice is still in use.

This is why clearing a String after taking a slice from it is rejected when that slice is used later: the mutation could invalidate the borrowed range.

Source