Skip to content

Commit 379d2a4

Browse files
author
Lukas Markeffsky
committed
remove unnecessary sized checks
1 parent 495807a commit 379d2a4

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

compiler/rustc_const_eval/src/interpret/eval_context.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1008,8 +1008,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
10081008
) -> InterpResult<'tcx> {
10091009
trace!("{:?} is now live", local);
10101010

1011-
// We avoid `ty.is_trivially_sized` since that (a) cannot assume WF, so it recurses through
1012-
// all fields of a tuple, and (b) does something expensive for ADTs.
1011+
// We avoid `ty.is_trivially_sized` since that does something expensive for ADTs.
10131012
fn is_very_trivially_sized(ty: Ty<'_>) -> bool {
10141013
match ty.kind() {
10151014
ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
@@ -1028,11 +1027,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
10281027
| ty::Closure(..)
10291028
| ty::CoroutineClosure(..)
10301029
| ty::Never
1031-
| ty::Error(_) => true,
1030+
| ty::Error(_)
1031+
| ty::Dynamic(_, _, ty::DynStar) => true,
10321032

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

1035-
ty::Tuple(tys) => tys.last().iter().all(|ty| is_very_trivially_sized(**ty)),
1035+
ty::Tuple(tys) => tys.last().map_or(true, |&ty| is_very_trivially_sized(ty)),
10361036

10371037
// We don't want to do any queries, so there is not much we can do with ADTs.
10381038
ty::Adt(..) => false,

compiler/rustc_middle/src/ty/sty.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -2483,13 +2483,16 @@ impl<'tcx> Ty<'tcx> {
24832483
| ty::Closure(..)
24842484
| ty::CoroutineClosure(..)
24852485
| ty::Never
2486-
| ty::Error(_) => true,
2486+
| ty::Error(_)
2487+
| ty::Dynamic(_, _, ty::DynStar) => true,
24872488

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

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

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

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

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

+1-1
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_sized_trait<'tcx>(
152152
bug!("unexpected type `{ty}`")
153153
}
154154

155-
ty::Tuple(tys) => Ok(tys.iter().map(ty::Binder::dummy).collect()),
155+
ty::Tuple(tys) => Ok(tys.last().map_or_else(Vec::new, |&ty| vec![ty::Binder::dummy(ty)])),
156156

157157
ty::Adt(def, args) => {
158158
let sized_crit = def.sized_constraint(ecx.tcx());

0 commit comments

Comments
 (0)