diff options
| author | bors <bors@rust-lang.org> | 2018-09-13 22:40:35 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-09-13 22:40:35 +0000 |
| commit | 4f921d7a8d8dee7b511e4956e06a80f550003afc (patch) | |
| tree | 2669f8223a1f824c967e590624e285a31c1f6e49 /src/libstd | |
| parent | 90d36fb5905bbe5004f5b465ea14b53d10dae260 (diff) | |
| parent | 07dc4b3759f3cc0e97777fe944dbc54c967424fd (diff) | |
| download | rust-4f921d7a8d8dee7b511e4956e06a80f550003afc.tar.gz rust-4f921d7a8d8dee7b511e4956e06a80f550003afc.zip | |
Auto merge of #54168 - kennytm:rollup, r=kennytm
Rollup of 11 pull requests Successful merges: - #53371 (Do not emit E0277 on incorrect tuple destructured binding) - #53829 (Add rustc SHA to released DWARF debuginfo) - #53950 (Allow for opting out of ThinLTO and clean up LTO related cli flag handling.) - #53976 (Replace unwrap calls in example by expect) - #54070 (Add Error::description soft-deprecation to RELEASES) - #54076 (miri loop detector hashing) - #54119 (Add some unit tests for find_best_match_for_name) - #54147 (Add a test that tries to modify static memory at compile-time) - #54150 (Updated 1.29 release notes with --document-private-items flag) - #54163 (Update stage 0 to latest beta) - #54170 (COMPILER_TESTS.md has been moved)
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/build.rs | 4 | ||||
| -rw-r--r-- | src/libstd/ffi/c_str.rs | 64 |
2 files changed, 38 insertions, 30 deletions
diff --git a/src/libstd/build.rs b/src/libstd/build.rs index 016e7adb4c9..0831e29bddd 100644 --- a/src/libstd/build.rs +++ b/src/libstd/build.rs @@ -97,6 +97,10 @@ fn build_libbacktrace(target: &str) -> Result<(), ()> { .file("../libbacktrace/sort.c") .file("../libbacktrace/state.c"); + let any_debug = env::var("RUSTC_DEBUGINFO").unwrap_or(String::new()) == "true" || + env::var("RUSTC_DEBUGINFO_LINES").unwrap_or(String::new()) == "true"; + build.debug(any_debug); + if target.contains("darwin") { build.file("../libbacktrace/macho.c"); } else if target.contains("windows") { diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index 372f3e83e3d..63dd12f782f 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -102,8 +102,8 @@ use sys; /// } /// /// // We are certain that our string doesn't have 0 bytes in the middle, -/// // so we can .unwrap() -/// let c_to_print = CString::new("Hello, world!").unwrap(); +/// // so we can .expect() +/// let c_to_print = CString::new("Hello, world!").expect("CString::new failed"); /// unsafe { /// my_printer(c_to_print.as_ptr()); /// } @@ -175,7 +175,7 @@ pub struct CString { /// unsafe { work_with(data.as_ptr()) } /// } /// -/// let s = CString::new("data data data data").unwrap(); +/// let s = CString::new("data data data data").expect("CString::new failed"); /// work(&s); /// ``` /// @@ -314,7 +314,7 @@ impl CString { /// /// extern { fn puts(s: *const c_char); } /// - /// let to_print = CString::new("Hello!").unwrap(); + /// let to_print = CString::new("Hello!").expect("CString::new failed"); /// unsafe { /// puts(to_print.as_ptr()); /// } @@ -398,7 +398,7 @@ impl CString { /// fn some_extern_function(s: *mut c_char); /// } /// - /// let c_string = CString::new("Hello!").unwrap(); + /// let c_string = CString::new("Hello!").expect("CString::new failed"); /// let raw = c_string.into_raw(); /// unsafe { /// some_extern_function(raw); @@ -428,7 +428,7 @@ impl CString { /// ``` /// use std::ffi::CString; /// - /// let c_string = CString::new("foo").unwrap(); + /// let c_string = CString::new("foo").expect("CString::new failed"); /// /// let ptr = c_string.into_raw(); /// @@ -460,12 +460,12 @@ impl CString { /// use std::ffi::CString; /// /// let valid_utf8 = vec![b'f', b'o', b'o']; - /// let cstring = CString::new(valid_utf8).unwrap(); - /// assert_eq!(cstring.into_string().unwrap(), "foo"); + /// let cstring = CString::new(valid_utf8).expect("CString::new failed"); + /// assert_eq!(cstring.into_string().expect("into_string() call failed"), "foo"); /// /// let invalid_utf8 = vec![b'f', 0xff, b'o', b'o']; - /// let cstring = CString::new(invalid_utf8).unwrap(); - /// let err = cstring.into_string().err().unwrap(); + /// let cstring = CString::new(invalid_utf8).expect("CString::new failed"); + /// let err = cstring.into_string().err().expect("into_string().err() failed"); /// assert_eq!(err.utf8_error().valid_up_to(), 1); /// ``` @@ -489,7 +489,7 @@ impl CString { /// ``` /// use std::ffi::CString; /// - /// let c_string = CString::new("foo").unwrap(); + /// let c_string = CString::new("foo").expect("CString::new failed"); /// let bytes = c_string.into_bytes(); /// assert_eq!(bytes, vec![b'f', b'o', b'o']); /// ``` @@ -511,7 +511,7 @@ impl CString { /// ``` /// use std::ffi::CString; /// - /// let c_string = CString::new("foo").unwrap(); + /// let c_string = CString::new("foo").expect("CString::new failed"); /// let bytes = c_string.into_bytes_with_nul(); /// assert_eq!(bytes, vec![b'f', b'o', b'o', b'\0']); /// ``` @@ -534,7 +534,7 @@ impl CString { /// ``` /// use std::ffi::CString; /// - /// let c_string = CString::new("foo").unwrap(); + /// let c_string = CString::new("foo").expect("CString::new failed"); /// let bytes = c_string.as_bytes(); /// assert_eq!(bytes, &[b'f', b'o', b'o']); /// ``` @@ -554,7 +554,7 @@ impl CString { /// ``` /// use std::ffi::CString; /// - /// let c_string = CString::new("foo").unwrap(); + /// let c_string = CString::new("foo").expect("CString::new failed"); /// let bytes = c_string.as_bytes_with_nul(); /// assert_eq!(bytes, &[b'f', b'o', b'o', b'\0']); /// ``` @@ -573,9 +573,10 @@ impl CString { /// ``` /// use std::ffi::{CString, CStr}; /// - /// let c_string = CString::new(b"foo".to_vec()).unwrap(); + /// let c_string = CString::new(b"foo".to_vec()).expect("CString::new failed"); /// let c_str = c_string.as_c_str(); - /// assert_eq!(c_str, CStr::from_bytes_with_nul(b"foo\0").unwrap()); + /// assert_eq!(c_str, + /// CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed")); /// ``` #[inline] #[stable(feature = "as_c_str", since = "1.20.0")] @@ -592,16 +593,17 @@ impl CString { /// ``` /// use std::ffi::{CString, CStr}; /// - /// let c_string = CString::new(b"foo".to_vec()).unwrap(); + /// let c_string = CString::new(b"foo".to_vec()).expect("CString::new failed"); /// let boxed = c_string.into_boxed_c_str(); - /// assert_eq!(&*boxed, CStr::from_bytes_with_nul(b"foo\0").unwrap()); + /// assert_eq!(&*boxed, + /// CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed")); /// ``` #[stable(feature = "into_boxed_c_str", since = "1.20.0")] pub fn into_boxed_c_str(self) -> Box<CStr> { unsafe { Box::from_raw(Box::into_raw(self.into_inner()) as *mut CStr) } } - // Bypass "move out of struct which implements [`Drop`] trait" restriction. + /// Bypass "move out of struct which implements [`Drop`] trait" restriction. /// /// [`Drop`]: ../ops/trait.Drop.html fn into_inner(self) -> Box<[u8]> { @@ -1031,7 +1033,7 @@ impl CStr { /// use std::ffi::{CStr, CString}; /// /// unsafe { - /// let cstring = CString::new("hello").unwrap(); + /// let cstring = CString::new("hello").expect("CString::new failed"); /// let cstr = CStr::from_bytes_with_nul_unchecked(cstring.to_bytes_with_nul()); /// assert_eq!(cstr, &*cstring); /// } @@ -1058,7 +1060,7 @@ impl CStr { /// # #![allow(unused_must_use)] /// use std::ffi::{CString}; /// - /// let ptr = CString::new("Hello").unwrap().as_ptr(); + /// let ptr = CString::new("Hello").expect("CString::new failed").as_ptr(); /// unsafe { /// // `ptr` is dangling /// *ptr; @@ -1067,14 +1069,14 @@ impl CStr { /// /// This happens because the pointer returned by `as_ptr` does not carry any /// lifetime information and the [`CString`] is deallocated immediately after - /// the `CString::new("Hello").unwrap().as_ptr()` expression is evaluated. + /// the `CString::new("Hello").expect("CString::new failed").as_ptr()` expression is evaluated. /// To fix the problem, bind the `CString` to a local variable: /// /// ```no_run /// # #![allow(unused_must_use)] /// use std::ffi::{CString}; /// - /// let hello = CString::new("Hello").unwrap(); + /// let hello = CString::new("Hello").expect("CString::new failed"); /// let ptr = hello.as_ptr(); /// unsafe { /// // `ptr` is valid because `hello` is in scope @@ -1106,7 +1108,7 @@ impl CStr { /// ``` /// use std::ffi::CStr; /// - /// let c_str = CStr::from_bytes_with_nul(b"foo\0").unwrap(); + /// let c_str = CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed"); /// assert_eq!(c_str.to_bytes(), b"foo"); /// ``` #[inline] @@ -1132,7 +1134,7 @@ impl CStr { /// ``` /// use std::ffi::CStr; /// - /// let c_str = CStr::from_bytes_with_nul(b"foo\0").unwrap(); + /// let c_str = CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed"); /// assert_eq!(c_str.to_bytes_with_nul(), b"foo\0"); /// ``` #[inline] @@ -1159,7 +1161,7 @@ impl CStr { /// ``` /// use std::ffi::CStr; /// - /// let c_str = CStr::from_bytes_with_nul(b"foo\0").unwrap(); + /// let c_str = CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed"); /// assert_eq!(c_str.to_str(), Ok("foo")); /// ``` #[stable(feature = "cstr_to_str", since = "1.4.0")] @@ -1200,7 +1202,8 @@ impl CStr { /// use std::borrow::Cow; /// use std::ffi::CStr; /// - /// let c_str = CStr::from_bytes_with_nul(b"Hello World\0").unwrap(); + /// let c_str = CStr::from_bytes_with_nul(b"Hello World\0") + /// .expect("CStr::from_bytes_with_nul failed"); /// assert_eq!(c_str.to_string_lossy(), Cow::Borrowed("Hello World")); /// ``` /// @@ -1210,7 +1213,8 @@ impl CStr { /// use std::borrow::Cow; /// use std::ffi::CStr; /// - /// let c_str = CStr::from_bytes_with_nul(b"Hello \xF0\x90\x80World\0").unwrap(); + /// let c_str = CStr::from_bytes_with_nul(b"Hello \xF0\x90\x80World\0") + /// .expect("CStr::from_bytes_with_nul failed"); /// assert_eq!( /// c_str.to_string_lossy(), /// Cow::Owned(String::from("Hello �World")) as Cow<str> @@ -1231,9 +1235,9 @@ impl CStr { /// ``` /// use std::ffi::CString; /// - /// let c_string = CString::new(b"foo".to_vec()).unwrap(); + /// let c_string = CString::new(b"foo".to_vec()).expect("CString::new failed"); /// let boxed = c_string.into_boxed_c_str(); - /// assert_eq!(boxed.into_c_string(), CString::new("foo").unwrap()); + /// assert_eq!(boxed.into_c_string(), CString::new("foo").expect("CString::new failed")); /// ``` #[stable(feature = "into_boxed_c_str", since = "1.20.0")] pub fn into_c_string(self: Box<CStr>) -> CString { |
