Skip to content

Commit 1863067

Browse files
committed
Auto merge of #62990 - Centril:rollup-k9n0hvs, r=Centril
Rollup of 15 pull requests Successful merges: - #60066 (Stabilize the type_name intrinsic in core::any) - #60938 (rustdoc: make #[doc(include)] relative to the containing file) - #61884 (Stablize Euclidean Modulo (feature euclidean_division)) - #61890 (Fix some sanity checks) - #62528 (Add joining slices of slices with a slice separator, not just a single item) - #62707 (Add tests for overlapping explicitly dropped locals in generators) - #62735 (Turn `#[global_allocator]` into a regular attribute macro) - #62822 (Improve some pointer-related documentation) - #62887 (Make the parser TokenStream more resilient after mismatched delimiter recovery) - #62921 (Add method disambiguation help for trait implementation) - #62930 (Add test for #51559) - #62942 (Use match ergonomics in Condvar documentation) - #62977 (Fix inconsistent highlight blocks.) - #62978 (Remove `cfg(bootstrap)` code for array implementations) - #62981 (Add note suggesting to borrow a String argument to find) Failed merges: - #62964 (clarify and unify some type test names) r? @ghost
2 parents 890881f + 1a775b3 commit 1863067

File tree

98 files changed

+1330
-1239
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+1330
-1239
lines changed

Cargo.lock

-18
Original file line numberDiff line numberDiff line change
@@ -2751,20 +2751,6 @@ dependencies = [
27512751
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
27522752
]
27532753

2754-
[[package]]
2755-
name = "rustc_allocator"
2756-
version = "0.0.0"
2757-
dependencies = [
2758-
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
2759-
"rustc 0.0.0",
2760-
"rustc_data_structures 0.0.0",
2761-
"rustc_errors 0.0.0",
2762-
"rustc_target 0.0.0",
2763-
"smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
2764-
"syntax 0.0.0",
2765-
"syntax_pos 0.0.0",
2766-
]
2767-
27682754
[[package]]
27692755
name = "rustc_apfloat"
27702756
version = "0.0.0"
@@ -2822,7 +2808,6 @@ dependencies = [
28222808
"num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
28232809
"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
28242810
"rustc 0.0.0",
2825-
"rustc_allocator 0.0.0",
28262811
"rustc_apfloat 0.0.0",
28272812
"rustc_codegen_utils 0.0.0",
28282813
"rustc_data_structures 0.0.0",
@@ -2883,7 +2868,6 @@ dependencies = [
28832868
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
28842869
"rustc 0.0.0",
28852870
"rustc-rayon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
2886-
"rustc_allocator 0.0.0",
28872871
"rustc_ast_borrowck 0.0.0",
28882872
"rustc_codegen_utils 0.0.0",
28892873
"rustc_data_structures 0.0.0",
@@ -2904,7 +2888,6 @@ dependencies = [
29042888
"serialize 0.0.0",
29052889
"smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
29062890
"syntax 0.0.0",
2907-
"syntax_ext 0.0.0",
29082891
"syntax_pos 0.0.0",
29092892
]
29102893

@@ -2948,7 +2931,6 @@ dependencies = [
29482931
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
29492932
"rustc 0.0.0",
29502933
"rustc-rayon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
2951-
"rustc_allocator 0.0.0",
29522934
"rustc_ast_borrowck 0.0.0",
29532935
"rustc_codegen_ssa 0.0.0",
29542936
"rustc_codegen_utils 0.0.0",

src/bootstrap/sanity.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,11 @@ pub fn check(build: &mut Build) {
7878

7979
// We need cmake, but only if we're actually building LLVM or sanitizers.
8080
let building_llvm = build.hosts.iter()
81-
.filter_map(|host| build.config.target_config.get(host))
82-
.any(|config| config.llvm_config.is_none());
81+
.map(|host| build.config.target_config
82+
.get(host)
83+
.map(|config| config.llvm_config.is_none())
84+
.unwrap_or(true))
85+
.any(|build_llvm_ourselves| build_llvm_ourselves);
8386
if building_llvm || build.config.sanitizers {
8487
cmd_finder.must_have("cmake");
8588
}
@@ -106,6 +109,14 @@ pub fn check(build: &mut Build) {
106109
build.config.ninja = true;
107110
}
108111
}
112+
113+
if build.config.lldb_enabled {
114+
cmd_finder.must_have("swig");
115+
let out = output(Command::new("swig").arg("-version"));
116+
if !out.contains("SWIG Version 3") && !out.contains("SWIG Version 4") {
117+
panic!("Ensure that Swig 3.x.x or 4.x.x is installed.");
118+
}
119+
}
109120
}
110121

111122
build.config.python = build.config.python.take().map(|p| cmd_finder.must_have(p))

src/doc/rustdoc/src/unstable-features.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,8 @@ Book][unstable-masked] and [its tracking issue][issue-masked].
183183

184184
As designed in [RFC 1990], Rustdoc can read an external file to use as a type's documentation. This
185185
is useful if certain documentation is so long that it would break the flow of reading the source.
186-
Instead of writing it all inline, writing `#[doc(include = "sometype.md")]` (where `sometype.md` is
187-
a file adjacent to the `lib.rs` for the crate) will ask Rustdoc to instead read that file and use it
188-
as if it were written inline.
186+
Instead of writing it all inline, writing `#[doc(include = "sometype.md")]` will ask Rustdoc to
187+
instead read that file and use it as if it were written inline.
189188

190189
[RFC 1990]: https://github.com/rust-lang/rfcs/pull/1990
191190

src/liballoc/slice.rs

+83-21
Original file line numberDiff line numberDiff line change
@@ -494,10 +494,10 @@ impl<T> [T] {
494494
/// assert_eq!([[1, 2], [3, 4]].concat(), [1, 2, 3, 4]);
495495
/// ```
496496
#[stable(feature = "rust1", since = "1.0.0")]
497-
pub fn concat<Separator: ?Sized>(&self) -> T::Output
498-
where T: SliceConcat<Separator>
497+
pub fn concat<Item: ?Sized>(&self) -> <Self as Concat<Item>>::Output
498+
where Self: Concat<Item>
499499
{
500-
SliceConcat::concat(self)
500+
Concat::concat(self)
501501
}
502502

503503
/// Flattens a slice of `T` into a single value `Self::Output`, placing a
@@ -508,12 +508,13 @@ impl<T> [T] {
508508
/// ```
509509
/// assert_eq!(["hello", "world"].join(" "), "hello world");
510510
/// assert_eq!([[1, 2], [3, 4]].join(&0), [1, 2, 0, 3, 4]);
511+
/// assert_eq!([[1, 2], [3, 4]].join(&[0, 0][..]), [1, 2, 0, 0, 3, 4]);
511512
/// ```
512513
#[stable(feature = "rename_connect_to_join", since = "1.3.0")]
513-
pub fn join<Separator: ?Sized>(&self, sep: &Separator) -> T::Output
514-
where T: SliceConcat<Separator>
514+
pub fn join<Separator>(&self, sep: Separator) -> <Self as Join<Separator>>::Output
515+
where Self: Join<Separator>
515516
{
516-
SliceConcat::join(self, sep)
517+
Join::join(self, sep)
517518
}
518519

519520
/// Flattens a slice of `T` into a single value `Self::Output`, placing a
@@ -528,10 +529,10 @@ impl<T> [T] {
528529
/// ```
529530
#[stable(feature = "rust1", since = "1.0.0")]
530531
#[rustc_deprecated(since = "1.3.0", reason = "renamed to join")]
531-
pub fn connect<Separator: ?Sized>(&self, sep: &Separator) -> T::Output
532-
where T: SliceConcat<Separator>
532+
pub fn connect<Separator>(&self, sep: Separator) -> <Self as Join<Separator>>::Output
533+
where Self: Join<Separator>
533534
{
534-
SliceConcat::join(self, sep)
535+
Join::join(self, sep)
535536
}
536537

537538
}
@@ -578,45 +579,83 @@ impl [u8] {
578579
// Extension traits for slices over specific kinds of data
579580
////////////////////////////////////////////////////////////////////////////////
580581

581-
/// Helper trait for [`[T]::concat`](../../std/primitive.slice.html#method.concat)
582-
/// and [`[T]::join`](../../std/primitive.slice.html#method.join)
582+
/// Helper trait for [`[T]::concat`](../../std/primitive.slice.html#method.concat).
583+
///
584+
/// Note: the `Item` type parameter is not used in this trait,
585+
/// but it allows impls to be more generic.
586+
/// Without it, we get this error:
587+
///
588+
/// ```error
589+
/// error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predica
590+
/// --> src/liballoc/slice.rs:608:6
591+
/// |
592+
/// 608 | impl<T: Clone, V: Borrow<[T]>> Concat for [V] {
593+
/// | ^ unconstrained type parameter
594+
/// ```
595+
///
596+
/// This is because there could exist `V` types with multiple `Borrow<[_]>` impls,
597+
/// such that multiple `T` types would apply:
598+
///
599+
/// ```
600+
/// # #[allow(dead_code)]
601+
/// pub struct Foo(Vec<u32>, Vec<String>);
602+
///
603+
/// impl std::borrow::Borrow<[u32]> for Foo {
604+
/// fn borrow(&self) -> &[u32] { &self.0 }
605+
/// }
606+
///
607+
/// impl std::borrow::Borrow<[String]> for Foo {
608+
/// fn borrow(&self) -> &[String] { &self.1 }
609+
/// }
610+
/// ```
583611
#[unstable(feature = "slice_concat_trait", issue = "27747")]
584-
pub trait SliceConcat<Separator: ?Sized>: Sized {
612+
pub trait Concat<Item: ?Sized> {
585613
#[unstable(feature = "slice_concat_trait", issue = "27747")]
586614
/// The resulting type after concatenation
587615
type Output;
588616

589617
/// Implementation of [`[T]::concat`](../../std/primitive.slice.html#method.concat)
590618
#[unstable(feature = "slice_concat_trait", issue = "27747")]
591-
fn concat(slice: &[Self]) -> Self::Output;
619+
fn concat(slice: &Self) -> Self::Output;
620+
}
621+
622+
/// Helper trait for [`[T]::join`](../../std/primitive.slice.html#method.join)
623+
#[unstable(feature = "slice_concat_trait", issue = "27747")]
624+
pub trait Join<Separator> {
625+
#[unstable(feature = "slice_concat_trait", issue = "27747")]
626+
/// The resulting type after concatenation
627+
type Output;
592628

593629
/// Implementation of [`[T]::join`](../../std/primitive.slice.html#method.join)
594630
#[unstable(feature = "slice_concat_trait", issue = "27747")]
595-
fn join(slice: &[Self], sep: &Separator) -> Self::Output;
631+
fn join(slice: &Self, sep: Separator) -> Self::Output;
596632
}
597633

598-
#[unstable(feature = "slice_concat_ext",
599-
reason = "trait should not have to exist",
600-
issue = "27747")]
601-
impl<T: Clone, V: Borrow<[T]>> SliceConcat<T> for V {
634+
#[unstable(feature = "slice_concat_ext", issue = "27747")]
635+
impl<T: Clone, V: Borrow<[T]>> Concat<T> for [V] {
602636
type Output = Vec<T>;
603637

604-
fn concat(slice: &[Self]) -> Vec<T> {
638+
fn concat(slice: &Self) -> Vec<T> {
605639
let size = slice.iter().map(|slice| slice.borrow().len()).sum();
606640
let mut result = Vec::with_capacity(size);
607641
for v in slice {
608642
result.extend_from_slice(v.borrow())
609643
}
610644
result
611645
}
646+
}
647+
648+
#[unstable(feature = "slice_concat_ext", issue = "27747")]
649+
impl<T: Clone, V: Borrow<[T]>> Join<&T> for [V] {
650+
type Output = Vec<T>;
612651

613-
fn join(slice: &[Self], sep: &T) -> Vec<T> {
652+
fn join(slice: &Self, sep: &T) -> Vec<T> {
614653
let mut iter = slice.iter();
615654
let first = match iter.next() {
616655
Some(first) => first,
617656
None => return vec![],
618657
};
619-
let size = slice.iter().map(|slice| slice.borrow().len()).sum::<usize>() + slice.len() - 1;
658+
let size = slice.iter().map(|v| v.borrow().len()).sum::<usize>() + slice.len() - 1;
620659
let mut result = Vec::with_capacity(size);
621660
result.extend_from_slice(first.borrow());
622661

@@ -628,6 +667,29 @@ impl<T: Clone, V: Borrow<[T]>> SliceConcat<T> for V {
628667
}
629668
}
630669

670+
#[unstable(feature = "slice_concat_ext", issue = "27747")]
671+
impl<T: Clone, V: Borrow<[T]>> Join<&[T]> for [V] {
672+
type Output = Vec<T>;
673+
674+
fn join(slice: &Self, sep: &[T]) -> Vec<T> {
675+
let mut iter = slice.iter();
676+
let first = match iter.next() {
677+
Some(first) => first,
678+
None => return vec![],
679+
};
680+
let size = slice.iter().map(|v| v.borrow().len()).sum::<usize>() +
681+
sep.len() * (slice.len() - 1);
682+
let mut result = Vec::with_capacity(size);
683+
result.extend_from_slice(first.borrow());
684+
685+
for v in iter {
686+
result.extend_from_slice(sep);
687+
result.extend_from_slice(v.borrow())
688+
}
689+
result
690+
}
691+
}
692+
631693
////////////////////////////////////////////////////////////////////////////////
632694
// Standard trait implementations for slices
633695
////////////////////////////////////////////////////////////////////////////////

src/liballoc/str.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use core::unicode::conversions;
3737

3838
use crate::borrow::ToOwned;
3939
use crate::boxed::Box;
40-
use crate::slice::{SliceConcat, SliceIndex};
40+
use crate::slice::{Concat, Join, SliceIndex};
4141
use crate::string::String;
4242
use crate::vec::Vec;
4343

@@ -71,17 +71,22 @@ pub use core::str::SplitAsciiWhitespace;
7171
#[stable(feature = "str_escape", since = "1.34.0")]
7272
pub use core::str::{EscapeDebug, EscapeDefault, EscapeUnicode};
7373

74-
#[unstable(feature = "slice_concat_ext",
75-
reason = "trait should not have to exist",
76-
issue = "27747")]
77-
impl<S: Borrow<str>> SliceConcat<str> for S {
74+
/// Note: `str` in `Concat<str>` is not meaningful here.
75+
/// This type parameter of the trait only exists to enable another impl.
76+
#[unstable(feature = "slice_concat_ext", issue = "27747")]
77+
impl<S: Borrow<str>> Concat<str> for [S] {
7878
type Output = String;
7979

80-
fn concat(slice: &[Self]) -> String {
81-
Self::join(slice, "")
80+
fn concat(slice: &Self) -> String {
81+
Join::join(slice, "")
8282
}
83+
}
84+
85+
#[unstable(feature = "slice_concat_ext", issue = "27747")]
86+
impl<S: Borrow<str>> Join<&str> for [S] {
87+
type Output = String;
8388

84-
fn join(slice: &[Self], sep: &str) -> String {
89+
fn join(slice: &Self, sep: &str) -> String {
8590
unsafe {
8691
String::from_utf8_unchecked( join_generic_copy(slice, sep.as_bytes()) )
8792
}

src/libcore/any.rs

+26
Original file line numberDiff line numberDiff line change
@@ -450,3 +450,29 @@ impl TypeId {
450450
}
451451
}
452452
}
453+
454+
/// Returns the name of a type as a string slice.
455+
///
456+
/// # Note
457+
///
458+
/// This is intended for diagnostic use. The exact contents and format of the
459+
/// string are not specified, other than being a best-effort description of the
460+
/// type. For example, `type_name::<Option<String>>()` could return the
461+
/// `"Option<String>"` or `"std::option::Option<std::string::String>"`, but not
462+
/// `"foobar"`. In addition, the output may change between versions of the
463+
/// compiler.
464+
///
465+
/// The type name should not be considered a unique identifier of a type;
466+
/// multiple types may share the same type name.
467+
///
468+
/// The current implementation uses the same infrastructure as compiler
469+
/// diagnostics and debuginfo, but this is not guaranteed.
470+
#[stable(feature = "type_name", since = "1.38.0")]
471+
pub fn type_name<T: ?Sized>() -> &'static str {
472+
#[cfg(bootstrap)]
473+
unsafe {
474+
intrinsics::type_name::<T>()
475+
}
476+
#[cfg(not(bootstrap))]
477+
intrinsics::type_name::<T>()
478+
}

0 commit comments

Comments
 (0)