Skip to content

Commit cac61fe

Browse files
committed
rework implementation for inherent impls for builtin types
1 parent 2401650 commit cac61fe

File tree

5 files changed

+102
-0
lines changed

5 files changed

+102
-0
lines changed

alloc/src/slice.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ impl<T> [T] {
267267
/// assert!(v == [-5, -3, 1, 2, 4]);
268268
/// ```
269269
#[cfg(not(no_global_oom_handling))]
270+
#[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)]
270271
#[stable(feature = "rust1", since = "1.0.0")]
271272
#[inline]
272273
pub fn sort(&mut self)
@@ -322,6 +323,7 @@ impl<T> [T] {
322323
/// assert!(v == [5, 4, 3, 2, 1]);
323324
/// ```
324325
#[cfg(not(no_global_oom_handling))]
326+
#[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)]
325327
#[stable(feature = "rust1", since = "1.0.0")]
326328
#[inline]
327329
pub fn sort_by<F>(&mut self, mut compare: F)
@@ -363,6 +365,7 @@ impl<T> [T] {
363365
/// assert!(v == [1, 2, -3, 4, -5]);
364366
/// ```
365367
#[cfg(not(no_global_oom_handling))]
368+
#[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)]
366369
#[stable(feature = "slice_sort_by_key", since = "1.7.0")]
367370
#[inline]
368371
pub fn sort_by_key<K, F>(&mut self, mut f: F)
@@ -409,6 +412,7 @@ impl<T> [T] {
409412
///
410413
/// [pdqsort]: https://github.com/orlp/pdqsort
411414
#[cfg(not(no_global_oom_handling))]
415+
#[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)]
412416
#[stable(feature = "slice_sort_by_cached_key", since = "1.34.0")]
413417
#[inline]
414418
pub fn sort_by_cached_key<K, F>(&mut self, f: F)
@@ -467,6 +471,7 @@ impl<T> [T] {
467471
/// // Here, `s` and `x` can be modified independently.
468472
/// ```
469473
#[cfg(not(no_global_oom_handling))]
474+
#[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)]
470475
#[rustc_conversion_suggestion]
471476
#[stable(feature = "rust1", since = "1.0.0")]
472477
#[inline]
@@ -491,6 +496,7 @@ impl<T> [T] {
491496
/// // Here, `s` and `x` can be modified independently.
492497
/// ```
493498
#[cfg(not(no_global_oom_handling))]
499+
#[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)]
494500
#[inline]
495501
#[unstable(feature = "allocator_api", issue = "32838")]
496502
pub fn to_vec_in<A: Allocator>(&self, alloc: A) -> Vec<T, A>
@@ -515,6 +521,7 @@ impl<T> [T] {
515521
///
516522
/// assert_eq!(x, vec![10, 40, 30]);
517523
/// ```
524+
#[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)]
518525
#[stable(feature = "rust1", since = "1.0.0")]
519526
#[inline]
520527
pub fn into_vec<A: Allocator>(self: Box<Self, A>) -> Vec<T, A> {
@@ -542,6 +549,7 @@ impl<T> [T] {
542549
/// // this will panic at runtime
543550
/// b"0123456789abcdef".repeat(usize::MAX);
544551
/// ```
552+
#[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)]
545553
#[cfg(not(no_global_oom_handling))]
546554
#[stable(feature = "repeat_generic_slice", since = "1.40.0")]
547555
pub fn repeat(&self, n: usize) -> Vec<T>
@@ -610,6 +618,7 @@ impl<T> [T] {
610618
/// assert_eq!(["hello", "world"].concat(), "helloworld");
611619
/// assert_eq!([[1, 2], [3, 4]].concat(), [1, 2, 3, 4]);
612620
/// ```
621+
#[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)]
613622
#[stable(feature = "rust1", since = "1.0.0")]
614623
pub fn concat<Item: ?Sized>(&self) -> <Self as Concat<Item>>::Output
615624
where
@@ -628,6 +637,7 @@ impl<T> [T] {
628637
/// assert_eq!([[1, 2], [3, 4]].join(&0), [1, 2, 0, 3, 4]);
629638
/// assert_eq!([[1, 2], [3, 4]].join(&[0, 0][..]), [1, 2, 0, 0, 3, 4]);
630639
/// ```
640+
#[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)]
631641
#[stable(feature = "rename_connect_to_join", since = "1.3.0")]
632642
pub fn join<Separator>(&self, sep: Separator) -> <Self as Join<Separator>>::Output
633643
where
@@ -646,6 +656,7 @@ impl<T> [T] {
646656
/// assert_eq!(["hello", "world"].connect(" "), "hello world");
647657
/// assert_eq!([[1, 2], [3, 4]].connect(&0), [1, 2, 0, 3, 4]);
648658
/// ```
659+
#[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)]
649660
#[stable(feature = "rust1", since = "1.0.0")]
650661
#[rustc_deprecated(since = "1.3.0", reason = "renamed to join")]
651662
pub fn connect<Separator>(&self, sep: Separator) -> <Self as Join<Separator>>::Output
@@ -669,6 +680,7 @@ impl [u8] {
669680
///
670681
/// [`make_ascii_uppercase`]: slice::make_ascii_uppercase
671682
#[cfg(not(no_global_oom_handling))]
683+
#[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)]
672684
#[must_use = "this returns the uppercase bytes as a new Vec, \
673685
without modifying the original"]
674686
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
@@ -689,6 +701,7 @@ impl [u8] {
689701
///
690702
/// [`make_ascii_lowercase`]: slice::make_ascii_lowercase
691703
#[cfg(not(no_global_oom_handling))]
704+
#[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)]
692705
#[must_use = "this returns the lowercase bytes as a new Vec, \
693706
without modifying the original"]
694707
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]

alloc/src/str.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ impl str {
250250
/// let boxed_bytes = boxed_str.into_boxed_bytes();
251251
/// assert_eq!(*boxed_bytes, *s.as_bytes());
252252
/// ```
253+
#[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)]
253254
#[stable(feature = "str_box_extras", since = "1.20.0")]
254255
#[must_use = "`self` will be dropped if the result is not used"]
255256
#[inline]
@@ -280,6 +281,7 @@ impl str {
280281
/// assert_eq!(s, s.replace("cookie monster", "little lamb"));
281282
/// ```
282283
#[cfg(not(no_global_oom_handling))]
284+
#[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)]
283285
#[must_use = "this returns the replaced string as a new allocation, \
284286
without modifying the original"]
285287
#[stable(feature = "rust1", since = "1.0.0")]
@@ -320,6 +322,7 @@ impl str {
320322
/// assert_eq!(s, s.replacen("cookie monster", "little lamb", 10));
321323
/// ```
322324
#[cfg(not(no_global_oom_handling))]
325+
#[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)]
323326
#[must_use = "this returns the replaced string as a new allocation, \
324327
without modifying the original"]
325328
#[stable(feature = "str_replacen", since = "1.16.0")]
@@ -376,6 +379,7 @@ impl str {
376379
/// assert_eq!(new_year, new_year.to_lowercase());
377380
/// ```
378381
#[cfg(not(no_global_oom_handling))]
382+
#[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)]
379383
#[must_use = "this returns the lowercase string as a new String, \
380384
without modifying the original"]
381385
#[stable(feature = "unicode_case_mapping", since = "1.2.0")]
@@ -458,6 +462,7 @@ impl str {
458462
/// assert_eq!("TSCHÜSS", s.to_uppercase());
459463
/// ```
460464
#[cfg(not(no_global_oom_handling))]
465+
#[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)]
461466
#[must_use = "this returns the uppercase string as a new String, \
462467
without modifying the original"]
463468
#[stable(feature = "unicode_case_mapping", since = "1.2.0")]
@@ -493,6 +498,7 @@ impl str {
493498
/// assert_eq!(boxed_str.into_string(), string);
494499
/// ```
495500
#[stable(feature = "box_str", since = "1.4.0")]
501+
#[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)]
496502
#[must_use = "`self` will be dropped if the result is not used"]
497503
#[inline]
498504
pub fn into_string(self: Box<str>) -> String {
@@ -521,6 +527,7 @@ impl str {
521527
/// let huge = "0123456789abcdef".repeat(usize::MAX);
522528
/// ```
523529
#[cfg(not(no_global_oom_handling))]
530+
#[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)]
524531
#[must_use]
525532
#[stable(feature = "repeat_str", since = "1.16.0")]
526533
pub fn repeat(&self, n: usize) -> String {
@@ -549,6 +556,7 @@ impl str {
549556
/// [`make_ascii_uppercase`]: str::make_ascii_uppercase
550557
/// [`to_uppercase`]: #method.to_uppercase
551558
#[cfg(not(no_global_oom_handling))]
559+
#[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)]
552560
#[must_use = "to uppercase the value in-place, use `make_ascii_uppercase()`"]
553561
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
554562
#[inline]
@@ -581,6 +589,7 @@ impl str {
581589
/// [`make_ascii_lowercase`]: str::make_ascii_lowercase
582590
/// [`to_lowercase`]: #method.to_lowercase
583591
#[cfg(not(no_global_oom_handling))]
592+
#[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)]
584593
#[must_use = "to lowercase the value in-place, use `make_ascii_lowercase()`"]
585594
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
586595
#[inline]

core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
target_has_atomic_load_store = "ptr",
8585
))]
8686
#![no_core]
87+
#![cfg_attr(not(bootstrap), rustc_coherence_is_core)]
8788
//
8889
// Lints:
8990
#![deny(rust_2021_incompatible_or_patterns)]

0 commit comments

Comments
 (0)