Skip to content

Commit 14d9512

Browse files
committed
Auto merge of #62509 - Centril:rollup-lod7gdi, r=Centril
Rollup of 4 pull requests Successful merges: - #61613 (Support `impl Trait` in inlined documentation) - #62090 (typeck: merge opaque type inference logic) - #62403 (Replace SliceConcatExt trait with inherent methods and SliceConcat helper trait) - #62494 (Remove unused dependencies) Failed merges: r? @ghost
2 parents 09ab31b + fba01b6 commit 14d9512

File tree

23 files changed

+543
-286
lines changed

23 files changed

+543
-286
lines changed

Cargo.lock

-3
Original file line numberDiff line numberDiff line change
@@ -2985,7 +2985,6 @@ dependencies = [
29852985
"num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
29862986
"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
29872987
"rustc 0.0.0",
2988-
"rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
29892988
"rustc_allocator 0.0.0",
29902989
"rustc_apfloat 0.0.0",
29912990
"rustc_codegen_utils 0.0.0",
@@ -3064,7 +3063,6 @@ dependencies = [
30643063
"rustc_target 0.0.0",
30653064
"rustc_traits 0.0.0",
30663065
"rustc_typeck 0.0.0",
3067-
"scoped-tls 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
30683066
"serialize 0.0.0",
30693067
"smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
30703068
"syntax 0.0.0",
@@ -3128,7 +3126,6 @@ dependencies = [
31283126
"rustc_resolve 0.0.0",
31293127
"rustc_traits 0.0.0",
31303128
"rustc_typeck 0.0.0",
3131-
"scoped-tls 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
31323129
"serialize 0.0.0",
31333130
"smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
31343131
"syntax 0.0.0",

src/liballoc/prelude/v1.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@
66

77
#[unstable(feature = "alloc_prelude", issue = "58935")] pub use crate::borrow::ToOwned;
88
#[unstable(feature = "alloc_prelude", issue = "58935")] pub use crate::boxed::Box;
9-
#[unstable(feature = "alloc_prelude", issue = "58935")] pub use crate::slice::SliceConcatExt;
109
#[unstable(feature = "alloc_prelude", issue = "58935")] pub use crate::string::{String, ToString};
1110
#[unstable(feature = "alloc_prelude", issue = "58935")] pub use crate::vec::Vec;

src/liballoc/slice.rs

+69-60
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,56 @@ impl<T> [T] {
484484
}
485485
buf
486486
}
487+
488+
/// Flattens a slice of `T` into a single value `Self::Output`.
489+
///
490+
/// # Examples
491+
///
492+
/// ```
493+
/// assert_eq!(["hello", "world"].concat(), "helloworld");
494+
/// assert_eq!([[1, 2], [3, 4]].concat(), [1, 2, 3, 4]);
495+
/// ```
496+
#[stable(feature = "rust1", since = "1.0.0")]
497+
pub fn concat<Separator: ?Sized>(&self) -> T::Output
498+
where T: SliceConcat<Separator>
499+
{
500+
SliceConcat::concat(self)
501+
}
502+
503+
/// Flattens a slice of `T` into a single value `Self::Output`, placing a
504+
/// given separator between each.
505+
///
506+
/// # Examples
507+
///
508+
/// ```
509+
/// assert_eq!(["hello", "world"].join(" "), "hello world");
510+
/// assert_eq!([[1, 2], [3, 4]].join(&0), [1, 2, 0, 3, 4]);
511+
/// ```
512+
#[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>
515+
{
516+
SliceConcat::join(self, sep)
517+
}
518+
519+
/// Flattens a slice of `T` into a single value `Self::Output`, placing a
520+
/// given separator between each.
521+
///
522+
/// # Examples
523+
///
524+
/// ```
525+
/// # #![allow(deprecated)]
526+
/// assert_eq!(["hello", "world"].connect(" "), "hello world");
527+
/// assert_eq!([[1, 2], [3, 4]].connect(&0), [1, 2, 0, 3, 4]);
528+
/// ```
529+
#[stable(feature = "rust1", since = "1.0.0")]
530+
#[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>
533+
{
534+
SliceConcat::join(self, sep)
535+
}
536+
487537
}
488538

489539
#[lang = "slice_u8_alloc"]
@@ -527,87 +577,46 @@ impl [u8] {
527577
////////////////////////////////////////////////////////////////////////////////
528578
// Extension traits for slices over specific kinds of data
529579
////////////////////////////////////////////////////////////////////////////////
530-
#[unstable(feature = "slice_concat_ext",
531-
reason = "trait should not have to exist",
532-
issue = "27747")]
533-
/// An extension trait for concatenating slices
534-
///
535-
/// While this trait is unstable, the methods are stable. `SliceConcatExt` is
536-
/// included in the [standard library prelude], so you can use [`join()`] and
537-
/// [`concat()`] as if they existed on `[T]` itself.
538-
///
539-
/// [standard library prelude]: ../../std/prelude/index.html
540-
/// [`join()`]: #tymethod.join
541-
/// [`concat()`]: #tymethod.concat
542-
pub trait SliceConcatExt<T: ?Sized> {
543-
#[unstable(feature = "slice_concat_ext",
544-
reason = "trait should not have to exist",
545-
issue = "27747")]
580+
581+
/// Helper trait for [`[T]::concat`](../../std/primitive.slice.html#method.concat)
582+
/// and [`[T]::join`](../../std/primitive.slice.html#method.join)
583+
#[unstable(feature = "slice_concat_trait", issue = "27747")]
584+
pub trait SliceConcat<Separator: ?Sized>: Sized {
585+
#[unstable(feature = "slice_concat_trait", issue = "27747")]
546586
/// The resulting type after concatenation
547587
type Output;
548588

549-
/// Flattens a slice of `T` into a single value `Self::Output`.
550-
///
551-
/// # Examples
552-
///
553-
/// ```
554-
/// assert_eq!(["hello", "world"].concat(), "helloworld");
555-
/// assert_eq!([[1, 2], [3, 4]].concat(), [1, 2, 3, 4]);
556-
/// ```
557-
#[stable(feature = "rust1", since = "1.0.0")]
558-
fn concat(&self) -> Self::Output;
559-
560-
/// Flattens a slice of `T` into a single value `Self::Output`, placing a
561-
/// given separator between each.
562-
///
563-
/// # Examples
564-
///
565-
/// ```
566-
/// assert_eq!(["hello", "world"].join(" "), "hello world");
567-
/// assert_eq!([[1, 2], [3, 4]].join(&0), [1, 2, 0, 3, 4]);
568-
/// ```
569-
#[stable(feature = "rename_connect_to_join", since = "1.3.0")]
570-
fn join(&self, sep: &T) -> Self::Output;
589+
/// Implementation of [`[T]::concat`](../../std/primitive.slice.html#method.concat)
590+
#[unstable(feature = "slice_concat_trait", issue = "27747")]
591+
fn concat(slice: &[Self]) -> Self::Output;
571592

572-
/// Flattens a slice of `T` into a single value `Self::Output`, placing a
573-
/// given separator between each.
574-
///
575-
/// # Examples
576-
///
577-
/// ```
578-
/// # #![allow(deprecated)]
579-
/// assert_eq!(["hello", "world"].connect(" "), "hello world");
580-
/// assert_eq!([[1, 2], [3, 4]].connect(&0), [1, 2, 0, 3, 4]);
581-
/// ```
582-
#[stable(feature = "rust1", since = "1.0.0")]
583-
#[rustc_deprecated(since = "1.3.0", reason = "renamed to join")]
584-
fn connect(&self, sep: &T) -> Self::Output {
585-
self.join(sep)
586-
}
593+
/// Implementation of [`[T]::join`](../../std/primitive.slice.html#method.join)
594+
#[unstable(feature = "slice_concat_trait", issue = "27747")]
595+
fn join(slice: &[Self], sep: &Separator) -> Self::Output;
587596
}
588597

589598
#[unstable(feature = "slice_concat_ext",
590599
reason = "trait should not have to exist",
591600
issue = "27747")]
592-
impl<T: Clone, V: Borrow<[T]>> SliceConcatExt<T> for [V] {
601+
impl<T: Clone, V: Borrow<[T]>> SliceConcat<T> for V {
593602
type Output = Vec<T>;
594603

595-
fn concat(&self) -> Vec<T> {
596-
let size = self.iter().map(|slice| slice.borrow().len()).sum();
604+
fn concat(slice: &[Self]) -> Vec<T> {
605+
let size = slice.iter().map(|slice| slice.borrow().len()).sum();
597606
let mut result = Vec::with_capacity(size);
598-
for v in self {
607+
for v in slice {
599608
result.extend_from_slice(v.borrow())
600609
}
601610
result
602611
}
603612

604-
fn join(&self, sep: &T) -> Vec<T> {
605-
let mut iter = self.iter();
613+
fn join(slice: &[Self], sep: &T) -> Vec<T> {
614+
let mut iter = slice.iter();
606615
let first = match iter.next() {
607616
Some(first) => first,
608617
None => return vec![],
609618
};
610-
let size = self.iter().map(|slice| slice.borrow().len()).sum::<usize>() + self.len() - 1;
619+
let size = slice.iter().map(|slice| slice.borrow().len()).sum::<usize>() + slice.len() - 1;
611620
let mut result = Vec::with_capacity(size);
612621
result.extend_from_slice(first.borrow());
613622

src/liballoc/str.rs

+7-7
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::{SliceConcatExt, SliceIndex};
40+
use crate::slice::{SliceConcat, SliceIndex};
4141
use crate::string::String;
4242
use crate::vec::Vec;
4343

@@ -74,16 +74,16 @@ pub use core::str::{EscapeDebug, EscapeDefault, EscapeUnicode};
7474
#[unstable(feature = "slice_concat_ext",
7575
reason = "trait should not have to exist",
7676
issue = "27747")]
77-
impl<S: Borrow<str>> SliceConcatExt<str> for [S] {
77+
impl<S: Borrow<str>> SliceConcat<str> for S {
7878
type Output = String;
7979

80-
fn concat(&self) -> String {
81-
self.join("")
80+
fn concat(slice: &[Self]) -> String {
81+
Self::join(slice, "")
8282
}
8383

84-
fn join(&self, sep: &str) -> String {
84+
fn join(slice: &[Self], sep: &str) -> String {
8585
unsafe {
86-
String::from_utf8_unchecked( join_generic_copy(self, sep.as_bytes()) )
86+
String::from_utf8_unchecked( join_generic_copy(slice, sep.as_bytes()) )
8787
}
8888
}
8989
}
@@ -126,7 +126,7 @@ macro_rules! copy_slice_and_advance {
126126

127127
// Optimized join implementation that works for both Vec<T> (T: Copy) and String's inner vec
128128
// Currently (2018-05-13) there is a bug with type inference and specialization (see issue #36262)
129-
// For this reason SliceConcatExt<T> is not specialized for T: Copy and SliceConcatExt<str> is the
129+
// For this reason SliceConcat<T> is not specialized for T: Copy and SliceConcat<str> is the
130130
// only user of this function. It is left in place for the time when that is fixed.
131131
//
132132
// the bounds for String-join are S: Borrow<str> and for Vec-join Borrow<[T]>

src/librustc/infer/opaque_types/mod.rs

+75-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::hir::Node;
44
use crate::infer::outlives::free_region_map::FreeRegionRelations;
55
use crate::infer::{self, InferCtxt, InferOk, TypeVariableOrigin, TypeVariableOriginKind};
66
use crate::middle::region;
7+
use crate::mir::interpret::ConstValue;
78
use crate::traits::{self, PredicateObligation};
89
use crate::ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder, TypeVisitor};
910
use crate::ty::subst::{InternalSubsts, Kind, SubstsRef, UnpackedKind};
@@ -553,6 +554,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
553554
def_id: DefId,
554555
opaque_defn: &OpaqueTypeDecl<'tcx>,
555556
instantiated_ty: Ty<'tcx>,
557+
span: Span,
556558
) -> Ty<'tcx> {
557559
debug!(
558560
"infer_opaque_definition_from_instantiation(def_id={:?}, instantiated_ty={:?})",
@@ -584,6 +586,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
584586
def_id,
585587
map,
586588
instantiated_ty,
589+
span,
587590
));
588591
debug!("infer_opaque_definition_from_instantiation: definition_ty={:?}", definition_ty);
589592

@@ -761,6 +764,9 @@ struct ReverseMapper<'tcx> {
761764

762765
/// initially `Some`, set to `None` once error has been reported
763766
hidden_ty: Option<Ty<'tcx>>,
767+
768+
/// Span of function being checked.
769+
span: Span,
764770
}
765771

766772
impl ReverseMapper<'tcx> {
@@ -770,6 +776,7 @@ impl ReverseMapper<'tcx> {
770776
opaque_type_def_id: DefId,
771777
map: FxHashMap<Kind<'tcx>, Kind<'tcx>>,
772778
hidden_ty: Ty<'tcx>,
779+
span: Span,
773780
) -> Self {
774781
Self {
775782
tcx,
@@ -778,6 +785,7 @@ impl ReverseMapper<'tcx> {
778785
map,
779786
map_missing_regions_to_empty: false,
780787
hidden_ty: Some(hidden_ty),
788+
span,
781789
}
782790
}
783791

@@ -812,10 +820,11 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> {
812820
_ => { }
813821
}
814822

823+
let generics = self.tcx().generics_of(self.opaque_type_def_id);
815824
match self.map.get(&r.into()).map(|k| k.unpack()) {
816825
Some(UnpackedKind::Lifetime(r1)) => r1,
817826
Some(u) => panic!("region mapped to unexpected kind: {:?}", u),
818-
None => {
827+
None if generics.parent.is_some() => {
819828
if !self.map_missing_regions_to_empty && !self.tainted_by_errors {
820829
if let Some(hidden_ty) = self.hidden_ty.take() {
821830
unexpected_hidden_region_diagnostic(
@@ -829,6 +838,21 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> {
829838
}
830839
self.tcx.lifetimes.re_empty
831840
}
841+
None => {
842+
self.tcx.sess
843+
.struct_span_err(
844+
self.span,
845+
"non-defining existential type use in defining scope"
846+
)
847+
.span_label(
848+
self.span,
849+
format!("lifetime `{}` is part of concrete type but not used in \
850+
parameter list of existential type", r),
851+
)
852+
.emit();
853+
854+
self.tcx().global_tcx().mk_region(ty::ReStatic)
855+
},
832856
}
833857
}
834858

@@ -890,9 +914,59 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> {
890914
self.tcx.mk_generator(def_id, ty::GeneratorSubsts { substs }, movability)
891915
}
892916

917+
ty::Param(..) => {
918+
// Look it up in the substitution list.
919+
match self.map.get(&ty.into()).map(|k| k.unpack()) {
920+
// Found it in the substitution list; replace with the parameter from the
921+
// existential type.
922+
Some(UnpackedKind::Type(t1)) => t1,
923+
Some(u) => panic!("type mapped to unexpected kind: {:?}", u),
924+
None => {
925+
self.tcx.sess
926+
.struct_span_err(
927+
self.span,
928+
&format!("type parameter `{}` is part of concrete type but not \
929+
used in parameter list for existential type", ty),
930+
)
931+
.emit();
932+
933+
self.tcx().types.err
934+
}
935+
}
936+
}
937+
893938
_ => ty.super_fold_with(self),
894939
}
895940
}
941+
942+
fn fold_const(&mut self, ct: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
943+
trace!("checking const {:?}", ct);
944+
// Find a const parameter
945+
match ct.val {
946+
ConstValue::Param(..) => {
947+
// Look it up in the substitution list.
948+
match self.map.get(&ct.into()).map(|k| k.unpack()) {
949+
// Found it in the substitution list, replace with the parameter from the
950+
// existential type.
951+
Some(UnpackedKind::Const(c1)) => c1,
952+
Some(u) => panic!("const mapped to unexpected kind: {:?}", u),
953+
None => {
954+
self.tcx.sess
955+
.struct_span_err(
956+
self.span,
957+
&format!("const parameter `{}` is part of concrete type but not \
958+
used in parameter list for existential type", ct)
959+
)
960+
.emit();
961+
962+
self.tcx().consts.err
963+
}
964+
}
965+
}
966+
967+
_ => ct,
968+
}
969+
}
896970
}
897971

898972
struct Instantiator<'a, 'tcx> {

src/librustc_codegen_ssa/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ test = false
1313
bitflags = "1.0.4"
1414
cc = "1.0.1"
1515
num_cpus = "1.0"
16-
rustc-demangle = "0.1.15"
1716
memmap = "0.6"
1817
log = "0.4.5"
1918
libc = "0.2.44"

src/librustc_driver/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ graphviz = { path = "../libgraphviz" }
1515
log = "0.4"
1616
env_logger = { version = "0.5", default-features = false }
1717
rayon = { version = "0.2.0", package = "rustc-rayon" }
18-
scoped-tls = "1.0"
1918
rustc = { path = "../librustc" }
2019
rustc_allocator = { path = "../librustc_allocator" }
2120
rustc_target = { path = "../librustc_target" }

0 commit comments

Comments
 (0)