Skip to content

Commit 8fe99f5

Browse files
author
Lukas Markeffsky
committed
remove unnecessary sized checks
1 parent 8ad9411 commit 8fe99f5

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

compiler/rustc_const_eval/src/interpret/eval_context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,8 +1034,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
10341034
) -> InterpResult<'tcx> {
10351035
trace!("{:?} is now live", local);
10361036

1037-
// We avoid `ty.is_trivially_sized` since that (a) cannot assume WF, so it recurses through
1038-
// all fields of a tuple, and (b) does something expensive for ADTs.
1037+
// We avoid `ty.is_trivially_sized` since that does something expensive for ADTs.
10391038
fn is_very_trivially_sized(ty: Ty<'_>) -> bool {
10401039
match ty.kind() {
10411040
ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
@@ -1054,9 +1053,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
10541053
| ty::Closure(..)
10551054
| ty::CoroutineClosure(..)
10561055
| ty::Never
1057-
| ty::Error(_) => true,
1056+
| ty::Error(_)
1057+
| ty::Dynamic(_, _, ty::DynStar) => true,
10581058

1059-
ty::Str | ty::Slice(_) | ty::Dynamic(..) | ty::Foreign(..) => false,
1059+
ty::Str | ty::Slice(_) | ty::Dynamic(_, _, ty::Dyn) | ty::Foreign(..) => false,
10601060

10611061
ty::Tuple(tys) => tys.last().iter().all(|ty| is_very_trivially_sized(**ty)),
10621062

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2484,13 +2484,16 @@ impl<'tcx> Ty<'tcx> {
24842484
| ty::Closure(..)
24852485
| ty::CoroutineClosure(..)
24862486
| ty::Never
2487-
| ty::Error(_) => true,
2487+
| ty::Error(_)
2488+
| ty::Dynamic(_, _, ty::DynStar) => true,
24882489

2489-
ty::Str | ty::Slice(_) | ty::Dynamic(..) | ty::Foreign(..) => false,
2490+
ty::Str | ty::Slice(_) | ty::Dynamic(_, _, ty::Dyn) | ty::Foreign(..) => false,
24902491

2491-
ty::Tuple(tys) => tys.iter().all(|ty| ty.is_trivially_sized(tcx)),
2492+
ty::Tuple(tys) => tys.last().map_or(true, |ty| ty.is_trivially_sized(tcx)),
24922493

2493-
ty::Adt(def, _args) => def.sized_constraint(tcx).is_none(),
2494+
ty::Adt(def, args) => def
2495+
.sized_constraint(tcx)
2496+
.map_or(true, |ty| ty.instantiate(tcx, args).is_trivially_sized(tcx)),
24942497

24952498
ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) | ty::Bound(..) => false,
24962499

compiler/rustc_trait_selection/src/solve/assembly/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ pub(super) trait GoalKind<'tcx>:
128128
goal: Goal<'tcx, Self>,
129129
) -> QueryResult<'tcx>;
130130

131-
/// A type is `Copy` or `Clone` if its components are `Sized`.
131+
/// A type is `Sized` if its tail component is `Sized`.
132132
///
133133
/// These components are given by built-in rules from
134134
/// [`structural_traits::instantiate_constituent_tys_for_sized_trait`].

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,9 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_sized_trait<'tcx>(
154154
bug!("unexpected type `{ty}`")
155155
}
156156

157-
// impl Sized for (T1, T2, .., Tn) where T1: Sized, T2: Sized, .. Tn: Sized
158-
ty::Tuple(tys) => Ok(tys.iter().map(ty::Binder::dummy).collect()),
157+
// impl Sized for ()
158+
// impl Sized for (T1, T2, .., Tn) where Tn: Sized if n >= 1
159+
ty::Tuple(tys) => Ok(tys.last().map_or_else(Vec::new, |&ty| vec![ty::Binder::dummy(ty)])),
159160

160161
// impl Sized for Adt<Args...> where sized_constraint(Adt)<Args...>: Sized
161162
// `sized_constraint(Adt)` is the deepest struct trail that can be determined

0 commit comments

Comments
 (0)