@@ -181,11 +181,10 @@ use crate::{deriving, errors};
181181use rustc_ast:: ptr:: P ;
182182use rustc_ast:: {
183183 self as ast, BindingMode , ByRef , EnumDef , Expr , GenericArg , GenericParamKind , Generics ,
184- Mutability , PatKind , TyKind , VariantData ,
184+ Mutability , PatKind , VariantData ,
185185} ;
186186use rustc_attr as attr;
187187use rustc_expand:: base:: { Annotatable , ExtCtxt } ;
188- use rustc_session:: lint:: builtin:: BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE ;
189188use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
190189use rustc_span:: { Span , DUMMY_SP } ;
191190use std:: cell:: RefCell ;
@@ -1599,52 +1598,11 @@ impl<'a> TraitDef<'a> {
15991598 ) ,
16001599 ) ;
16011600 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+ ) ;
16481606 }
16491607 cx. expr_addr_of ( sp, field_expr)
16501608 } )
0 commit comments