@@ -181,11 +181,10 @@ use crate::{deriving, errors};
181
181
use rustc_ast:: ptr:: P ;
182
182
use rustc_ast:: {
183
183
self as ast, BindingMode , ByRef , EnumDef , Expr , GenericArg , GenericParamKind , Generics ,
184
- Mutability , PatKind , TyKind , VariantData ,
184
+ Mutability , PatKind , VariantData ,
185
185
} ;
186
186
use rustc_attr as attr;
187
187
use rustc_expand:: base:: { Annotatable , ExtCtxt } ;
188
- use rustc_session:: lint:: builtin:: BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE ;
189
188
use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
190
189
use rustc_span:: { Span , DUMMY_SP } ;
191
190
use std:: cell:: RefCell ;
@@ -1599,52 +1598,11 @@ impl<'a> TraitDef<'a> {
1599
1598
) ,
1600
1599
) ;
1601
1600
if is_packed {
1602
- // In general, fields in packed structs are copied via a
1603
- // block, e.g. `&{self.0}`. The two exceptions are `[u8]`
1604
- // and `str` fields, which cannot be copied and also never
1605
- // cause unaligned references. These exceptions are allowed
1606
- // to handle the `FlexZeroSlice` type in the `zerovec`
1607
- // crate within `icu4x-0.9.0`.
1608
- //
1609
- // Once use of `icu4x-0.9.0` has dropped sufficiently, this
1610
- // exception should be removed.
1611
- let is_simple_path = |ty : & P < ast:: Ty > , sym| {
1612
- if let TyKind :: Path ( None , ast:: Path { segments, .. } ) = & ty. kind
1613
- && let [ seg] = segments. as_slice ( )
1614
- && seg. ident . name == sym
1615
- && seg. args . is_none ( )
1616
- {
1617
- true
1618
- } else {
1619
- false
1620
- }
1621
- } ;
1622
-
1623
- let exception = if let TyKind :: Slice ( ty) = & struct_field. ty . kind
1624
- && is_simple_path ( ty, sym:: u8)
1625
- {
1626
- Some ( "byte" )
1627
- } else if is_simple_path ( & struct_field. ty , sym:: str) {
1628
- Some ( "string" )
1629
- } else {
1630
- None
1631
- } ;
1632
-
1633
- if let Some ( ty) = exception {
1634
- cx. sess . psess . buffer_lint (
1635
- BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE ,
1636
- sp,
1637
- ast:: CRATE_NODE_ID ,
1638
- rustc_lint_defs:: BuiltinLintDiag :: ByteSliceInPackedStructWithDerive {
1639
- ty : ty. to_string ( ) ,
1640
- } ,
1641
- ) ;
1642
- } else {
1643
- // Wrap the expression in `{...}`, causing a copy.
1644
- field_expr = cx. expr_block (
1645
- cx. block ( struct_field. span , thin_vec ! [ cx. stmt_expr( field_expr) ] ) ,
1646
- ) ;
1647
- }
1601
+ // Fields in packed structs are wrapped in a block, e.g. `&{self.0}`,
1602
+ // causing a copy instead of a (potentially misaligned) reference.
1603
+ field_expr = cx. expr_block (
1604
+ cx. block ( struct_field. span , thin_vec ! [ cx. stmt_expr( field_expr) ] ) ,
1605
+ ) ;
1648
1606
}
1649
1607
cx. expr_addr_of ( sp, field_expr)
1650
1608
} )
0 commit comments