@@ -195,7 +195,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
195195
196196 assert_eq ! ( self . tcx. hir( ) . body_owner_def_id( body. id( ) ) , closure_def_id) ;
197197 let mut delegate = InferBorrowKind {
198- fcx : self ,
199198 closure_def_id,
200199 capture_information : Default :: default ( ) ,
201200 fake_reads : Default :: default ( ) ,
@@ -1607,34 +1606,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16071606/// Truncate the capture so that the place being borrowed is in accordance with RFC 1240,
16081607/// which states that it's unsafe to take a reference into a struct marked `repr(packed)`.
16091608fn restrict_repr_packed_field_ref_capture < ' tcx > (
1610- tcx : TyCtxt < ' tcx > ,
1611- param_env : ty:: ParamEnv < ' tcx > ,
16121609 mut place : Place < ' tcx > ,
16131610 mut curr_borrow_kind : ty:: UpvarCapture ,
16141611) -> ( Place < ' tcx > , ty:: UpvarCapture ) {
16151612 let pos = place. projections . iter ( ) . enumerate ( ) . position ( |( i, p) | {
16161613 let ty = place. ty_before_projection ( i) ;
16171614
1618- // Return true for fields of packed structs, unless those fields have alignment 1 .
1615+ // Return true for fields of packed structs.
16191616 match p. kind {
16201617 ProjectionKind :: Field ( ..) => match ty. kind ( ) {
16211618 ty:: Adt ( def, _) if def. repr ( ) . packed ( ) => {
1622- // We erase regions here because they cannot be hashed
1623- match tcx. layout_of ( param_env. and ( tcx. erase_regions ( p. ty ) ) ) {
1624- Ok ( layout) if layout. align . abi . bytes ( ) == 1 => {
1625- // if the alignment is 1, the type can't be further
1626- // disaligned.
1627- debug ! (
1628- "restrict_repr_packed_field_ref_capture: ({:?}) - align = 1" ,
1629- place
1630- ) ;
1631- false
1632- }
1633- _ => {
1634- debug ! ( "restrict_repr_packed_field_ref_capture: ({:?}) - true" , place) ;
1635- true
1636- }
1637- }
1619+ // We stop here regardless of field alignment. Field alignment can change as
1620+ // types change, including the types of private fields in other crates, and that
1621+ // shouldn't affect how we compute our captures.
1622+ true
16381623 }
16391624
16401625 _ => false ,
@@ -1689,9 +1674,7 @@ fn drop_location_span(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> Span {
16891674 tcx. sess . source_map ( ) . end_point ( owner_span)
16901675}
16911676
1692- struct InferBorrowKind < ' a , ' tcx > {
1693- fcx : & ' a FnCtxt < ' a , ' tcx > ,
1694-
1677+ struct InferBorrowKind < ' tcx > {
16951678 // The def-id of the closure whose kind and upvar accesses are being inferred.
16961679 closure_def_id : LocalDefId ,
16971680
@@ -1725,7 +1708,7 @@ struct InferBorrowKind<'a, 'tcx> {
17251708 fake_reads : Vec < ( Place < ' tcx > , FakeReadCause , hir:: HirId ) > ,
17261709}
17271710
1728- impl < ' a , ' tcx > euv:: Delegate < ' tcx > for InferBorrowKind < ' a , ' tcx > {
1711+ impl < ' tcx > euv:: Delegate < ' tcx > for InferBorrowKind < ' tcx > {
17291712 fn fake_read (
17301713 & mut self ,
17311714 place : & PlaceWithHirId < ' tcx > ,
@@ -1740,12 +1723,7 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for InferBorrowKind<'a, 'tcx> {
17401723
17411724 let ( place, _) = restrict_capture_precision ( place. place . clone ( ) , dummy_capture_kind) ;
17421725
1743- let ( place, _) = restrict_repr_packed_field_ref_capture (
1744- self . fcx . tcx ,
1745- self . fcx . param_env ,
1746- place,
1747- dummy_capture_kind,
1748- ) ;
1726+ let ( place, _) = restrict_repr_packed_field_ref_capture ( place, dummy_capture_kind) ;
17491727 self . fake_reads . push ( ( place, cause, diag_expr_id) ) ;
17501728 }
17511729
@@ -1780,12 +1758,8 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for InferBorrowKind<'a, 'tcx> {
17801758 // We only want repr packed restriction to be applied to reading references into a packed
17811759 // struct, and not when the data is being moved. Therefore we call this method here instead
17821760 // of in `restrict_capture_precision`.
1783- let ( place, mut capture_kind) = restrict_repr_packed_field_ref_capture (
1784- self . fcx . tcx ,
1785- self . fcx . param_env ,
1786- place_with_id. place . clone ( ) ,
1787- capture_kind,
1788- ) ;
1761+ let ( place, mut capture_kind) =
1762+ restrict_repr_packed_field_ref_capture ( place_with_id. place . clone ( ) , capture_kind) ;
17891763
17901764 // Raw pointers don't inherit mutability
17911765 if place_with_id. place . deref_tys ( ) . any ( Ty :: is_unsafe_ptr) {
0 commit comments