Skip to content

Commit c42f697

Browse files
committed
Make tuples implicitly sized
1 parent 30f168e commit c42f697

File tree

59 files changed

+268
-412
lines changed

Some content is hidden

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

59 files changed

+268
-412
lines changed

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,12 +1918,11 @@ impl<'tcx> Ty<'tcx> {
19181918
| ty::CoroutineClosure(..)
19191919
| ty::Never
19201920
| ty::Error(_)
1921+
| ty::Tuple(_)
19211922
| ty::Dynamic(_, _, ty::DynStar) => true,
19221923

19231924
ty::Str | ty::Slice(_) | ty::Dynamic(_, _, ty::Dyn) | ty::Foreign(..) => false,
19241925

1925-
ty::Tuple(tys) => tys.last().is_none_or(|ty| ty.is_trivially_sized(tcx)),
1926-
19271926
ty::Adt(def, args) => def
19281927
.sized_constraint(tcx)
19291928
.is_none_or(|ty| ty.instantiate(tcx, args).is_trivially_sized(tcx)),

compiler/rustc_middle/src/ty/util.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,6 @@ impl<'tcx> TyCtxt<'tcx> {
269269
}
270270
}
271271

272-
ty::Tuple(tys) if let Some((&last_ty, _)) = tys.split_last() => {
273-
f();
274-
ty = last_ty;
275-
}
276-
277272
ty::Tuple(_) => break,
278273

279274
ty::Pat(inner, _) => {

compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ where
108108
match ty.kind() {
109109
// impl Sized for u*, i*, bool, f*, FnDef, FnPtr, *(const/mut) T, char, &mut? T, [T; N], dyn* Trait, !
110110
// impl Sized for Coroutine, CoroutineWitness, Closure, CoroutineClosure
111+
// impl Sized for tuple
111112
ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
112113
| ty::Uint(_)
113114
| ty::Int(_)
@@ -126,6 +127,7 @@ where
126127
| ty::CoroutineClosure(..)
127128
| ty::Never
128129
| ty::Dynamic(_, _, ty::DynStar)
130+
| ty::Tuple(_)
129131
| ty::Error(_) => Ok(ty::Binder::dummy(vec![])),
130132

131133
ty::Str
@@ -143,10 +145,6 @@ where
143145

144146
ty::UnsafeBinder(bound_ty) => Ok(bound_ty.map_bound(|ty| vec![ty])),
145147

146-
// impl Sized for ()
147-
// impl Sized for (T1, T2, .., Tn) where Tn: Sized if n >= 1
148-
ty::Tuple(tys) => Ok(ty::Binder::dummy(tys.last().map_or_else(Vec::new, |ty| vec![ty]))),
149-
150148
// impl Sized for Adt<Args...> where sized_constraint(Adt)<Args...>: Sized
151149
// `sized_constraint(Adt)` is the deepest struct trail that can be determined
152150
// by the definition of `Adt`, independent of the generic args.

compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2712,9 +2712,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
27122712
ObligationCauseCode::ArrayLen(array_ty) => {
27132713
err.note(format!("the length of array `{array_ty}` must be type `usize`"));
27142714
}
2715-
ObligationCauseCode::TupleElem => {
2716-
err.note("only the last element of a tuple may have a dynamically sized type");
2717-
}
2715+
ObligationCauseCode::TupleElem => {}
27182716
ObligationCauseCode::WhereClause(item_def_id, span)
27192717
| ObligationCauseCode::WhereClauseInExpr(item_def_id, span, ..)
27202718
| ObligationCauseCode::HostEffectInExpr(item_def_id, span, ..)

compiler/rustc_trait_selection/src/traits/select/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,17 +2090,14 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
20902090
| ty::CoroutineClosure(..)
20912091
| ty::Never
20922092
| ty::Dynamic(_, _, ty::DynStar)
2093+
| ty::Tuple(_)
20932094
| ty::Error(_) => {
20942095
// safe for everything
20952096
Where(ty::Binder::dummy(Vec::new()))
20962097
}
20972098

20982099
ty::Str | ty::Slice(_) | ty::Dynamic(..) | ty::Foreign(..) => None,
20992100

2100-
ty::Tuple(tys) => Where(
2101-
obligation.predicate.rebind(tys.last().map_or_else(Vec::new, |&last| vec![last])),
2102-
),
2103-
21042101
ty::Pat(ty, _) => Where(obligation.predicate.rebind(vec![*ty])),
21052102

21062103
ty::Adt(def, args) => {

compiler/rustc_trait_selection/src/traits/wf.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -749,10 +749,8 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
749749
}
750750

751751
ty::Tuple(tys) => {
752-
if let Some((_last, rest)) = tys.split_last() {
753-
for &elem in rest {
754-
self.require_sized(elem, ObligationCauseCode::TupleElem);
755-
}
752+
for elem in tys {
753+
self.require_sized(elem, ObligationCauseCode::TupleElem);
756754
}
757755
}
758756

library/core/src/fmt/mod.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2851,7 +2851,7 @@ macro_rules! tuple {
28512851
maybe_tuple_doc! {
28522852
$($name)+ @
28532853
#[stable(feature = "rust1", since = "1.0.0")]
2854-
impl<$($name:Debug),+> Debug for ($($name,)+) where last_type!($($name,)+): ?Sized {
2854+
impl<$($name:Debug),+> Debug for ($($name,)+) {
28552855
#[allow(non_snake_case, unused_assignments)]
28562856
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
28572857
let mut builder = f.debug_tuple("");
@@ -2882,11 +2882,6 @@ macro_rules! maybe_tuple_doc {
28822882
};
28832883
}
28842884

2885-
macro_rules! last_type {
2886-
($a:ident,) => { $a };
2887-
($a:ident, $($rest_a:ident,)+) => { last_type!($($rest_a,)+) };
2888-
}
2889-
28902885
tuple! { E, D, C, B, A, Z, Y, X, W, V, U, T, }
28912886

28922887
#[stable(feature = "rust1", since = "1.0.0")]

library/core/src/hash/mod.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ mod impls {
886886
maybe_tuple_doc! {
887887
$($name)+ @
888888
#[stable(feature = "rust1", since = "1.0.0")]
889-
impl<$($name: Hash),+> Hash for ($($name,)+) where last_type!($($name,)+): ?Sized {
889+
impl<$($name: Hash),+> Hash for ($($name,)+) {
890890
#[allow(non_snake_case)]
891891
#[inline]
892892
fn hash<S: Hasher>(&self, state: &mut S) {
@@ -912,11 +912,6 @@ mod impls {
912912
};
913913
}
914914

915-
macro_rules! last_type {
916-
($a:ident,) => { $a };
917-
($a:ident, $($rest_a:ident,)+) => { last_type!($($rest_a,)+) };
918-
}
919-
920915
impl_hash_tuple! {}
921916
impl_hash_tuple! { T }
922917
impl_hash_tuple! { T B }

library/core/src/ops/range.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,7 @@ pub enum OneSidedRangeBound {
12111211
/// Types that implement `OneSidedRange<T>` must return `Bound::Unbounded`
12121212
/// from one of `RangeBounds::start_bound` or `RangeBounds::end_bound`.
12131213
#[unstable(feature = "one_sided_range", issue = "69780")]
1214-
pub trait OneSidedRange<T: ?Sized>: RangeBounds<T> {
1214+
pub trait OneSidedRange<T>: RangeBounds<T> {
12151215
/// An internal-only helper function for `split_off` and
12161216
/// `split_off_mut` that returns the bound of the one-sided range.
12171217
fn bound(self) -> (OneSidedRangeBound, T);

library/core/src/tuple.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ macro_rules! tuple_impls {
2222
maybe_tuple_doc! {
2323
$($T)+ @
2424
#[stable(feature = "rust1", since = "1.0.0")]
25-
impl<$($T: PartialEq),+> PartialEq for ($($T,)+)
26-
where
27-
last_type!($($T,)+): ?Sized
28-
{
25+
impl<$($T: PartialEq),+> PartialEq for ($($T,)+) {
2926
#[inline]
3027
fn eq(&self, other: &($($T,)+)) -> bool {
3128
$( ${ignore($T)} self.${index()} == other.${index()} )&&+
@@ -41,8 +38,6 @@ macro_rules! tuple_impls {
4138
$($T)+ @
4239
#[stable(feature = "rust1", since = "1.0.0")]
4340
impl<$($T: Eq),+> Eq for ($($T,)+)
44-
where
45-
last_type!($($T,)+): ?Sized
4641
{}
4742
}
4843

@@ -71,8 +66,6 @@ macro_rules! tuple_impls {
7166
$($T)+ @
7267
#[stable(feature = "rust1", since = "1.0.0")]
7368
impl<$($T: PartialOrd),+> PartialOrd for ($($T,)+)
74-
where
75-
last_type!($($T,)+): ?Sized
7669
{
7770
#[inline]
7871
fn partial_cmp(&self, other: &($($T,)+)) -> Option<Ordering> {
@@ -101,8 +94,6 @@ macro_rules! tuple_impls {
10194
$($T)+ @
10295
#[stable(feature = "rust1", since = "1.0.0")]
10396
impl<$($T: Ord),+> Ord for ($($T,)+)
104-
where
105-
last_type!($($T,)+): ?Sized
10697
{
10798
#[inline]
10899
fn cmp(&self, other: &($($T,)+)) -> Ordering {
@@ -205,9 +196,4 @@ macro_rules! lexical_cmp {
205196
($a:expr, $b:expr) => { ($a).cmp(&$b) };
206197
}
207198

208-
macro_rules! last_type {
209-
($a:ident,) => { $a };
210-
($a:ident, $($rest_a:ident,)+) => { last_type!($($rest_a,)+) };
211-
}
212-
213199
tuple_impls!(E D C B A Z Y X W V U T);

0 commit comments

Comments
 (0)