@@ -3967,7 +3967,6 @@ def_type_content_sets! {
3967
3967
None = 0b0000_0000__0000_0000__0000 ,
3968
3968
3969
3969
// Things that are interior to the value (first nibble):
3970
- InteriorUnsized = 0b0000_0000__0000_0000__0001 ,
3971
3970
InteriorUnsafe = 0b0000_0000__0000_0000__0010 ,
3972
3971
InteriorParam = 0b0000_0000__0000_0000__0100 ,
3973
3972
// InteriorAll = 0b00000000__00000000__1111,
@@ -3977,18 +3976,9 @@ def_type_content_sets! {
3977
3976
OwnsDtor = 0b0000_0000__0000_0010__0000 ,
3978
3977
OwnsAll = 0b0000_0000__1111_1111__0000 ,
3979
3978
3980
- // Things that are reachable by the value in any way (fourth nibble):
3981
- ReachesBorrowed = 0b0000_0010__0000_0000__0000 ,
3982
- ReachesMutable = 0b0000_1000__0000_0000__0000 ,
3983
- ReachesFfiUnsafe = 0b0010_0000__0000_0000__0000 ,
3984
- ReachesAll = 0b0011_1111__0000_0000__0000 ,
3985
-
3986
3979
// Things that mean drop glue is necessary
3987
3980
NeedsDrop = 0b0000_0000__0000_0111__0000 ,
3988
3981
3989
- // Things that prevent values from being considered sized
3990
- Nonsized = 0b0000_0000__0000_0000__0001 ,
3991
-
3992
3982
// All bits
3993
3983
All = 0b1111_1111__1111_1111__1111
3994
3984
}
@@ -4007,10 +3997,6 @@ impl TypeContents {
4007
3997
self . intersects ( TC :: OwnsOwned )
4008
3998
}
4009
3999
4010
- pub fn is_sized ( & self , _: & ctxt ) -> bool {
4011
- !self . intersects ( TC :: Nonsized )
4012
- }
4013
-
4014
4000
pub fn interior_param ( & self ) -> bool {
4015
4001
self . intersects ( TC :: InteriorParam )
4016
4002
}
@@ -4019,29 +4005,13 @@ impl TypeContents {
4019
4005
self . intersects ( TC :: InteriorUnsafe )
4020
4006
}
4021
4007
4022
- pub fn interior_unsized ( & self ) -> bool {
4023
- self . intersects ( TC :: InteriorUnsized )
4024
- }
4025
-
4026
4008
pub fn needs_drop ( & self , _: & ctxt ) -> bool {
4027
4009
self . intersects ( TC :: NeedsDrop )
4028
4010
}
4029
4011
4030
4012
/// Includes only those bits that still apply when indirected through a `Box` pointer
4031
4013
pub fn owned_pointer ( & self ) -> TypeContents {
4032
- TC :: OwnsOwned | (
4033
- * self & ( TC :: OwnsAll | TC :: ReachesAll ) )
4034
- }
4035
-
4036
- /// Includes only those bits that still apply when indirected through a reference (`&`)
4037
- pub fn reference ( & self , bits : TypeContents ) -> TypeContents {
4038
- bits | (
4039
- * self & TC :: ReachesAll )
4040
- }
4041
-
4042
- /// Includes only those bits that still apply when indirected through a raw pointer (`*`)
4043
- pub fn unsafe_pointer ( & self ) -> TypeContents {
4044
- * self & TC :: ReachesAll
4014
+ TC :: OwnsOwned | ( * self & TC :: OwnsAll )
4045
4015
}
4046
4016
4047
4017
pub fn union < T , F > ( v : & [ T ] , mut f : F ) -> TypeContents where
@@ -4129,7 +4099,7 @@ impl<'tcx> TyS<'tcx> {
4129
4099
let result = match ty. sty {
4130
4100
// usize and isize are ffi-unsafe
4131
4101
TyUint ( ast:: TyUs ) | TyInt ( ast:: TyIs ) => {
4132
- TC :: ReachesFfiUnsafe
4102
+ TC :: None
4133
4103
}
4134
4104
4135
4105
// Scalar and unique types are sendable, and durable
@@ -4140,40 +4110,35 @@ impl<'tcx> TyS<'tcx> {
4140
4110
}
4141
4111
4142
4112
TyBox ( typ) => {
4143
- TC :: ReachesFfiUnsafe | tc_ty ( cx, typ, cache) . owned_pointer ( )
4113
+ tc_ty ( cx, typ, cache) . owned_pointer ( )
4144
4114
}
4145
4115
4146
- TyTrait ( box TraitTy { ref bounds , .. } ) => {
4147
- object_contents ( bounds ) | TC :: ReachesFfiUnsafe | TC :: Nonsized
4116
+ TyTrait ( _ ) => {
4117
+ TC :: All - TC :: InteriorParam
4148
4118
}
4149
4119
4150
- TyRawPtr ( ref mt ) => {
4151
- tc_ty ( cx , mt . ty , cache ) . unsafe_pointer ( )
4120
+ TyRawPtr ( _ ) => {
4121
+ TC :: None
4152
4122
}
4153
4123
4154
- TyRef ( r, ref mt) => {
4155
- tc_ty ( cx, mt. ty , cache) . reference ( borrowed_contents ( * r, mt. mutbl ) ) |
4156
- TC :: ReachesFfiUnsafe
4124
+ TyRef ( _, _) => {
4125
+ TC :: None
4157
4126
}
4158
4127
4159
4128
TyArray ( ty, _) => {
4160
4129
tc_ty ( cx, ty, cache)
4161
4130
}
4162
4131
4163
4132
TySlice ( ty) => {
4164
- tc_ty ( cx, ty, cache) | TC :: Nonsized
4133
+ tc_ty ( cx, ty, cache)
4165
4134
}
4166
- TyStr => TC :: Nonsized ,
4135
+ TyStr => TC :: None ,
4167
4136
4168
4137
TyStruct ( did, substs) => {
4169
4138
let flds = cx. struct_fields ( did, substs) ;
4170
4139
let mut res =
4171
4140
TypeContents :: union ( & flds[ ..] ,
4172
- |f| tc_mt ( cx, f. mt , cache) ) ;
4173
-
4174
- if !cx. lookup_repr_hints ( did) . contains ( & attr:: ReprExtern ) {
4175
- res = res | TC :: ReachesFfiUnsafe ;
4176
- }
4141
+ |f| tc_ty ( cx, f. mt . ty , cache) ) ;
4177
4142
4178
4143
if cx. has_dtor ( did) {
4179
4144
res = res | TC :: OwnsDtor ;
@@ -4182,7 +4147,6 @@ impl<'tcx> TyS<'tcx> {
4182
4147
}
4183
4148
4184
4149
TyClosure ( did, substs) => {
4185
- // FIXME(#14449): `borrowed_contents` below assumes `&mut` closure.
4186
4150
let param_env = cx. empty_parameter_environment ( ) ;
4187
4151
let infcx = infer:: new_infer_ctxt ( cx, & cx. tables , Some ( param_env) , false ) ;
4188
4152
let upvars = infcx. closure_upvars ( did, substs) . unwrap ( ) ;
@@ -4208,44 +4172,6 @@ impl<'tcx> TyS<'tcx> {
4208
4172
res = res | TC :: OwnsDtor ;
4209
4173
}
4210
4174
4211
- if !variants. is_empty ( ) {
4212
- let repr_hints = cx. lookup_repr_hints ( did) ;
4213
- if repr_hints. len ( ) > 1 {
4214
- // this is an error later on, but this type isn't safe
4215
- res = res | TC :: ReachesFfiUnsafe ;
4216
- }
4217
-
4218
- match repr_hints. get ( 0 ) {
4219
- Some ( h) => if !h. is_ffi_safe ( ) {
4220
- res = res | TC :: ReachesFfiUnsafe ;
4221
- } ,
4222
- // ReprAny
4223
- None => {
4224
- res = res | TC :: ReachesFfiUnsafe ;
4225
-
4226
- // We allow ReprAny enums if they are eligible for
4227
- // the nullable pointer optimization and the
4228
- // contained type is an `extern fn`
4229
-
4230
- if variants. len ( ) == 2 {
4231
- let mut data_idx = 0 ;
4232
-
4233
- if variants[ 0 ] . args . is_empty ( ) {
4234
- data_idx = 1 ;
4235
- }
4236
-
4237
- if variants[ data_idx] . args . len ( ) == 1 {
4238
- match variants[ data_idx] . args [ 0 ] . sty {
4239
- TyBareFn ( ..) => { res = res - TC :: ReachesFfiUnsafe ; }
4240
- _ => { }
4241
- }
4242
- }
4243
- }
4244
- }
4245
- }
4246
- }
4247
-
4248
-
4249
4175
apply_lang_items ( cx, did, res)
4250
4176
}
4251
4177
@@ -4264,14 +4190,6 @@ impl<'tcx> TyS<'tcx> {
4264
4190
result
4265
4191
}
4266
4192
4267
- fn tc_mt < ' tcx > ( cx : & ctxt < ' tcx > ,
4268
- mt : TypeAndMut < ' tcx > ,
4269
- cache : & mut FnvHashMap < Ty < ' tcx > , TypeContents > ) -> TypeContents
4270
- {
4271
- let mc = TC :: ReachesMutable . when ( mt. mutbl == MutMutable ) ;
4272
- mc | tc_ty ( cx, mt. ty , cache)
4273
- }
4274
-
4275
4193
fn apply_lang_items ( cx : & ctxt , did : ast:: DefId , tc : TypeContents )
4276
4194
-> TypeContents {
4277
4195
if Some ( did) == cx. lang_items . unsafe_cell_type ( ) {
@@ -4280,32 +4198,6 @@ impl<'tcx> TyS<'tcx> {
4280
4198
tc
4281
4199
}
4282
4200
}
4283
-
4284
- /// Type contents due to containing a reference with
4285
- /// the region `region` and borrow kind `bk`.
4286
- fn borrowed_contents ( region : ty:: Region ,
4287
- mutbl : ast:: Mutability )
4288
- -> TypeContents {
4289
- let b = match mutbl {
4290
- ast:: MutMutable => TC :: ReachesMutable ,
4291
- ast:: MutImmutable => TC :: None ,
4292
- } ;
4293
- b | ( TC :: ReachesBorrowed ) . when ( region != ty:: ReStatic )
4294
- }
4295
-
4296
- fn object_contents ( bounds : & ExistentialBounds ) -> TypeContents {
4297
- // These are the type contents of the (opaque) interior. We
4298
- // make no assumptions (other than that it cannot have an
4299
- // in-scope type parameter within, which makes no sense).
4300
- let mut tc = TC :: All - TC :: InteriorParam ;
4301
- for bound in & bounds. builtin_bounds {
4302
- tc = tc - match bound {
4303
- BoundSync | BoundSend | BoundCopy => TC :: None ,
4304
- BoundSized => TC :: Nonsized ,
4305
- } ;
4306
- }
4307
- return tc;
4308
- }
4309
4201
}
4310
4202
4311
4203
fn impls_bound < ' a > ( & ' tcx self , param_env : & ParameterEnvironment < ' a , ' tcx > ,
@@ -4399,10 +4291,6 @@ impl<'tcx> TyS<'tcx> {
4399
4291
result
4400
4292
}
4401
4293
4402
- pub fn is_ffi_safe ( & ' tcx self , cx : & ctxt < ' tcx > ) -> bool {
4403
- !self . type_contents ( cx) . intersects ( TC :: ReachesFfiUnsafe )
4404
- }
4405
-
4406
4294
// True if instantiating an instance of `r_ty` requires an instance of `r_ty`.
4407
4295
pub fn is_instantiable ( & ' tcx self , cx : & ctxt < ' tcx > ) -> bool {
4408
4296
fn type_requires < ' tcx > ( cx : & ctxt < ' tcx > , seen : & mut Vec < DefId > ,
0 commit comments