@@ -195,7 +195,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
195
195
196
196
assert_eq ! ( self . tcx. hir( ) . body_owner_def_id( body. id( ) ) , closure_def_id) ;
197
197
let mut delegate = InferBorrowKind {
198
- fcx : self ,
199
198
closure_def_id,
200
199
capture_information : Default :: default ( ) ,
201
200
fake_reads : Default :: default ( ) ,
@@ -1607,34 +1606,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1607
1606
/// Truncate the capture so that the place being borrowed is in accordance with RFC 1240,
1608
1607
/// which states that it's unsafe to take a reference into a struct marked `repr(packed)`.
1609
1608
fn restrict_repr_packed_field_ref_capture < ' tcx > (
1610
- tcx : TyCtxt < ' tcx > ,
1611
- param_env : ty:: ParamEnv < ' tcx > ,
1612
1609
mut place : Place < ' tcx > ,
1613
1610
mut curr_borrow_kind : ty:: UpvarCapture ,
1614
1611
) -> ( Place < ' tcx > , ty:: UpvarCapture ) {
1615
1612
let pos = place. projections . iter ( ) . enumerate ( ) . position ( |( i, p) | {
1616
1613
let ty = place. ty_before_projection ( i) ;
1617
1614
1618
- // Return true for fields of packed structs, unless those fields have alignment 1 .
1615
+ // Return true for fields of packed structs.
1619
1616
match p. kind {
1620
1617
ProjectionKind :: Field ( ..) => match ty. kind ( ) {
1621
1618
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
1638
1623
}
1639
1624
1640
1625
_ => false ,
@@ -1689,9 +1674,7 @@ fn drop_location_span(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> Span {
1689
1674
tcx. sess . source_map ( ) . end_point ( owner_span)
1690
1675
}
1691
1676
1692
- struct InferBorrowKind < ' a , ' tcx > {
1693
- fcx : & ' a FnCtxt < ' a , ' tcx > ,
1694
-
1677
+ struct InferBorrowKind < ' tcx > {
1695
1678
// The def-id of the closure whose kind and upvar accesses are being inferred.
1696
1679
closure_def_id : LocalDefId ,
1697
1680
@@ -1725,7 +1708,7 @@ struct InferBorrowKind<'a, 'tcx> {
1725
1708
fake_reads : Vec < ( Place < ' tcx > , FakeReadCause , hir:: HirId ) > ,
1726
1709
}
1727
1710
1728
- impl < ' a , ' tcx > euv:: Delegate < ' tcx > for InferBorrowKind < ' a , ' tcx > {
1711
+ impl < ' tcx > euv:: Delegate < ' tcx > for InferBorrowKind < ' tcx > {
1729
1712
fn fake_read (
1730
1713
& mut self ,
1731
1714
place : & PlaceWithHirId < ' tcx > ,
@@ -1740,12 +1723,7 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for InferBorrowKind<'a, 'tcx> {
1740
1723
1741
1724
let ( place, _) = restrict_capture_precision ( place. place . clone ( ) , dummy_capture_kind) ;
1742
1725
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) ;
1749
1727
self . fake_reads . push ( ( place, cause, diag_expr_id) ) ;
1750
1728
}
1751
1729
@@ -1780,12 +1758,8 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for InferBorrowKind<'a, 'tcx> {
1780
1758
// We only want repr packed restriction to be applied to reading references into a packed
1781
1759
// struct, and not when the data is being moved. Therefore we call this method here instead
1782
1760
// 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) ;
1789
1763
1790
1764
// Raw pointers don't inherit mutability
1791
1765
if place_with_id. place . deref_tys ( ) . any ( Ty :: is_unsafe_ptr) {
0 commit comments