Skip to content

Commit a14153d

Browse files
committed
Auto merge of rust-lang#123299 - workingjubilee:rollup-2z8amaj, r=workingjubilee
Rollup of 5 pull requests Successful merges: - rust-lang#123180 (Rewrite `core-no-fp-fmt-parse` test in Rust) - rust-lang#123267 (std::thread: adding get_name haiku implementation.) - rust-lang#123268 (warn against implementing Freeze) - rust-lang#123271 (doc: describe panic conditions for SliceIndex implementations) - rust-lang#123295 (add myself to compiler review rotation) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 638a6a8 + 89219c1 commit a14153d

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

Diff for: core/src/marker.rs

+7
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,13 @@ pub trait DiscriminantKind {
817817
/// This can be used to declare that a constant with a generic type
818818
/// will not contain interior mutability, and subsequently allow
819819
/// placing the constant behind references.
820+
///
821+
/// # Safety
822+
///
823+
/// This trait is a core part of the language, it is just expressed as a trait in libcore for
824+
/// convenience. Do *not* implement it for other types.
825+
// FIXME: Eventually this trait should become `#[rustc_deny_explicit_impl]`.
826+
// That requires porting the impls below to native internal impls.
820827
#[lang = "freeze"]
821828
#[unstable(feature = "freeze", issue = "121675")]
822829
pub unsafe auto trait Freeze {}

Diff for: core/src/slice/index.rs

+11
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ pub unsafe trait SliceIndex<T: ?Sized>: private_slice_index::Sealed {
195195
fn index_mut(self, slice: &mut T) -> &mut Self::Output;
196196
}
197197

198+
/// The methods `index` and `index_mut` panic if the index is out of bounds.
198199
#[stable(feature = "slice_get_slice_impls", since = "1.15.0")]
199200
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
200201
unsafe impl<T> SliceIndex<[T]> for usize {
@@ -328,6 +329,9 @@ unsafe impl<T> SliceIndex<[T]> for ops::IndexRange {
328329
}
329330
}
330331

332+
/// The methods `index` and `index_mut` panic if:
333+
/// - the start of the range is greater than the end of the range or
334+
/// - the end of the range is out of bounds.
331335
#[stable(feature = "slice_get_slice_impls", since = "1.15.0")]
332336
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
333337
unsafe impl<T> SliceIndex<[T]> for ops::Range<usize> {
@@ -416,6 +420,7 @@ unsafe impl<T> SliceIndex<[T]> for ops::Range<usize> {
416420
}
417421
}
418422

423+
/// The methods `index` and `index_mut` panic if the end of the range is out of bounds.
419424
#[stable(feature = "slice_get_slice_impls", since = "1.15.0")]
420425
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
421426
unsafe impl<T> SliceIndex<[T]> for ops::RangeTo<usize> {
@@ -454,6 +459,7 @@ unsafe impl<T> SliceIndex<[T]> for ops::RangeTo<usize> {
454459
}
455460
}
456461

462+
/// The methods `index` and `index_mut` panic if the start of the range is out of bounds.
457463
#[stable(feature = "slice_get_slice_impls", since = "1.15.0")]
458464
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
459465
unsafe impl<T> SliceIndex<[T]> for ops::RangeFrom<usize> {
@@ -536,6 +542,10 @@ unsafe impl<T> SliceIndex<[T]> for ops::RangeFull {
536542
}
537543
}
538544

545+
/// The methods `index` and `index_mut` panic if:
546+
/// - the end of the range is `usize::MAX` or
547+
/// - the start of the range is greater than the end of the range or
548+
/// - the end of the range is out of bounds.
539549
#[stable(feature = "inclusive_range", since = "1.26.0")]
540550
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
541551
unsafe impl<T> SliceIndex<[T]> for ops::RangeInclusive<usize> {
@@ -580,6 +590,7 @@ unsafe impl<T> SliceIndex<[T]> for ops::RangeInclusive<usize> {
580590
}
581591
}
582592

593+
/// The methods `index` and `index_mut` panic if the end of the range is out of bounds.
583594
#[stable(feature = "inclusive_range", since = "1.26.0")]
584595
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
585596
unsafe impl<T> SliceIndex<[T]> for ops::RangeToInclusive<usize> {

Diff for: std/src/sys/pal/unix/thread.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,32 @@ impl Thread {
257257
CString::new(name).ok()
258258
}
259259

260+
#[cfg(target_os = "haiku")]
261+
pub fn get_name() -> Option<CString> {
262+
unsafe {
263+
let mut tinfo = mem::MaybeUninit::<libc::thread_info>::uninit();
264+
// See BeOS teams group and threads api.
265+
// https://www.haiku-os.org/legacy-docs/bebook/TheKernelKit_ThreadsAndTeams_Overview.html
266+
let thread_self = libc::find_thread(ptr::null_mut());
267+
let res = libc::get_thread_info(thread_self, tinfo.as_mut_ptr());
268+
if res != libc::B_OK {
269+
return None;
270+
}
271+
let info = tinfo.assume_init();
272+
let name = slice::from_raw_parts(info.name.as_ptr() as *const u8, info.name.len());
273+
CStr::from_bytes_until_nul(name).map(CStr::to_owned).ok()
274+
}
275+
}
276+
260277
#[cfg(not(any(
261278
target_os = "linux",
262279
target_os = "freebsd",
263280
target_os = "netbsd",
264281
target_os = "macos",
265282
target_os = "ios",
266283
target_os = "tvos",
267-
target_os = "watchos"
284+
target_os = "watchos",
285+
target_os = "haiku"
268286
)))]
269287
pub fn get_name() -> Option<CString> {
270288
None

0 commit comments

Comments
 (0)