-
Notifications
You must be signed in to change notification settings - Fork 13.3k
std: Align raw
modules with unsafe conventions
#19152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Note that I took a few liberties with functions like |
72daf50
to
83b8efc
Compare
🙊 🎉 (reading now) |
/// Creates a `String` from a `*const u8` buffer of the given length. | ||
/// | ||
/// This function is unsafe because of two reasons: | ||
/// * A raw pointer is dereferenced and transmuted to `&[u8]`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of these you say what's actually done, others you just say "we call an unsafe thing on Vec". Might want to pick one (also no transmute to a &[u8]
every actually occurs).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm yeah I tweaked the implementation in copy/pasting, so I'll clarify these unsafety points.
8299549
to
591fd66
Compare
Ok @gankro, updated with |
@_@ rebased. Just skimming but I think everything's been addressed. r=me but I dunno if you want a second opinion or anything. |
} | ||
result.push_str(unsafe{raw::slice_bytes(me, last_end, me.len())}); | ||
result | ||
replace(self.as_slice(), from, to) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I would've thought we'd deprecate the free replace
fn in favor of this method.
I or github must be missing something: where is |
Oops sorry forgot to update the description, it's not called |
@@ -160,14 +159,14 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result { | |||
|
|||
let opaque = opaque as *mut hoedown_html_renderer_state; | |||
let my_opaque: &MyOpaque = &*((*opaque).opaque as *const MyOpaque); | |||
slice::raw::buf_as_slice((*orig_text).data, (*orig_text).size as uint, | |||
slice::with_raw_buf((*orig_text).data, (*orig_text).size as uint, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't find the definition of this function.
@alexcrichton But it seems to be referenced in the code, still? |
591fd66
to
7ecb717
Compare
/// ``` | ||
#[inline] | ||
#[unstable = "just renamed from `mod raw`"] | ||
pub unsafe fn from_raw_buf<'a, T>(p: &'a *const T, len: uint) -> &'a [T] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm reasonably happy with this design; it's pragmatic.
This commit is an implementation of [RFC 240][rfc] when applied to the standard library. It primarily deprecates the entirety of `string::raw`, `vec::raw`, `slice::raw`, and `str::raw` in favor of associated functions, methods, and other free functions. The detailed renaming is: * slice::raw::buf_as_slice => slice::with_raw_buf * slice::raw::mut_buf_as_slice => slice::with_raw_mut_buf * slice::shift_ptr => deprecated with no replacement * slice::pop_ptr => deprecated with no replacement * str::raw::from_utf8 => str::from_utf8_unchecked * str::raw::c_str_to_static_slice => str::from_c_str * str::raw::slice_bytes => deprecated for slice_unchecked (slight semantic diff) * str::raw::slice_unchecked => str.slice_unchecked * string::raw::from_parts => String::from_raw_parts * string::raw::from_buf_len => String::from_raw_buf_len * string::raw::from_buf => String::from_raw_buf * string::raw::from_utf8 => String::from_utf8_unchecked * vec::raw::from_buf => Vec::from_raw_buf All previous functions exist in their `#[deprecated]` form, and the deprecation messages indicate how to migrate to the newer variants. [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/0240-unsafe-api-location.md [breaking-change] Closes rust-lang#17863
7ecb717
to
8ca27a6
Compare
This commit is an implementation of [RFC 240][rfc] when applied to the standard library. It primarily deprecates the entirety of `string::raw`, `vec::raw`, `slice::raw`, and `str::raw` in favor of associated functions, methods, and other free functions. The detailed renaming is: * slice::raw::buf_as_slice => slice::from_raw_buf * slice::raw::mut_buf_as_slice => slice::from_raw_mut_buf * slice::shift_ptr => deprecated with no replacement * slice::pop_ptr => deprecated with no replacement * str::raw::from_utf8 => str::from_utf8_unchecked * str::raw::c_str_to_static_slice => str::from_c_str * str::raw::slice_bytes => deprecated for slice_unchecked (slight semantic diff) * str::raw::slice_unchecked => str.slice_unchecked * string::raw::from_parts => String::from_raw_parts * string::raw::from_buf_len => String::from_raw_buf_len * string::raw::from_buf => String::from_raw_buf * string::raw::from_utf8 => String::from_utf8_unchecked * vec::raw::from_buf => Vec::from_raw_buf All previous functions exist in their `#[deprecated]` form, and the deprecation messages indicate how to migrate to the newer variants. [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/0240-unsafe-api-location.md [breaking-change] Closes #17863
This commit is an implementation of RFC 240 when applied to the standard
library. It primarily deprecates the entirety of
string::raw
,vec::raw
,slice::raw
, andstr::raw
in favor of associated functions, methods, andother free functions. The detailed renaming is:
All previous functions exist in their
#[deprecated]
form, and the deprecationmessages indicate how to migrate to the newer variants.
[breaking-change]
Closes #17863