@@ -187,7 +187,6 @@ use rustc_ast::ptr::P;
187
187
use rustc_attr as attr;
188
188
use rustc_data_structures:: map_in_place:: MapInPlace ;
189
189
use rustc_expand:: base:: { Annotatable , ExtCtxt } ;
190
- use rustc_session:: parse:: ParseSess ;
191
190
use rustc_span:: source_map:: respan;
192
191
use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
193
192
use rustc_span:: Span ;
@@ -437,14 +436,7 @@ impl<'a> TraitDef<'a> {
437
436
// This can only cause further compilation errors
438
437
// downstream in blatantly illegal code, so it
439
438
// is fine.
440
- self . expand_enum_def (
441
- cx,
442
- enum_def,
443
- & item. attrs ,
444
- item. ident ,
445
- generics,
446
- from_scratch,
447
- )
439
+ self . expand_enum_def ( cx, enum_def, item. ident , generics, from_scratch)
448
440
}
449
441
ast:: ItemKind :: Union ( ref struct_def, ref generics) => {
450
442
if self . supports_unions {
@@ -769,7 +761,6 @@ impl<'a> TraitDef<'a> {
769
761
& self ,
770
762
cx : & mut ExtCtxt < ' _ > ,
771
763
enum_def : & ' a EnumDef ,
772
- type_attrs : & [ ast:: Attribute ] ,
773
764
type_ident : Ident ,
774
765
generics : & Generics ,
775
766
from_scratch : bool ,
@@ -801,7 +792,6 @@ impl<'a> TraitDef<'a> {
801
792
cx,
802
793
self ,
803
794
enum_def,
804
- type_attrs,
805
795
type_ident,
806
796
self_args,
807
797
& nonself_args[ ..] ,
@@ -816,38 +806,6 @@ impl<'a> TraitDef<'a> {
816
806
}
817
807
}
818
808
819
- fn find_repr_type_name ( sess : & ParseSess , type_attrs : & [ ast:: Attribute ] ) -> & ' static str {
820
- let mut repr_type_name = "isize" ;
821
- for a in type_attrs {
822
- for r in & attr:: find_repr_attrs ( sess, a) {
823
- repr_type_name = match * r {
824
- attr:: ReprPacked ( _)
825
- | attr:: ReprSimd
826
- | attr:: ReprAlign ( _)
827
- | attr:: ReprTransparent
828
- | attr:: ReprNoNiche => continue ,
829
-
830
- attr:: ReprC => "i32" ,
831
-
832
- attr:: ReprInt ( attr:: SignedInt ( ast:: IntTy :: Isize ) ) => "isize" ,
833
- attr:: ReprInt ( attr:: SignedInt ( ast:: IntTy :: I8 ) ) => "i8" ,
834
- attr:: ReprInt ( attr:: SignedInt ( ast:: IntTy :: I16 ) ) => "i16" ,
835
- attr:: ReprInt ( attr:: SignedInt ( ast:: IntTy :: I32 ) ) => "i32" ,
836
- attr:: ReprInt ( attr:: SignedInt ( ast:: IntTy :: I64 ) ) => "i64" ,
837
- attr:: ReprInt ( attr:: SignedInt ( ast:: IntTy :: I128 ) ) => "i128" ,
838
-
839
- attr:: ReprInt ( attr:: UnsignedInt ( ast:: UintTy :: Usize ) ) => "usize" ,
840
- attr:: ReprInt ( attr:: UnsignedInt ( ast:: UintTy :: U8 ) ) => "u8" ,
841
- attr:: ReprInt ( attr:: UnsignedInt ( ast:: UintTy :: U16 ) ) => "u16" ,
842
- attr:: ReprInt ( attr:: UnsignedInt ( ast:: UintTy :: U32 ) ) => "u32" ,
843
- attr:: ReprInt ( attr:: UnsignedInt ( ast:: UintTy :: U64 ) ) => "u64" ,
844
- attr:: ReprInt ( attr:: UnsignedInt ( ast:: UintTy :: U128 ) ) => "u128" ,
845
- }
846
- }
847
- }
848
- repr_type_name
849
- }
850
-
851
809
impl < ' a > MethodDef < ' a > {
852
810
fn call_substructure_method (
853
811
& self ,
@@ -1148,20 +1106,11 @@ impl<'a> MethodDef<'a> {
1148
1106
cx : & mut ExtCtxt < ' _ > ,
1149
1107
trait_ : & TraitDef < ' b > ,
1150
1108
enum_def : & ' b EnumDef ,
1151
- type_attrs : & [ ast:: Attribute ] ,
1152
1109
type_ident : Ident ,
1153
1110
self_args : Vec < P < Expr > > ,
1154
1111
nonself_args : & [ P < Expr > ] ,
1155
1112
) -> P < Expr > {
1156
- self . build_enum_match_tuple (
1157
- cx,
1158
- trait_,
1159
- enum_def,
1160
- type_attrs,
1161
- type_ident,
1162
- self_args,
1163
- nonself_args,
1164
- )
1113
+ self . build_enum_match_tuple ( cx, trait_, enum_def, type_ident, self_args, nonself_args)
1165
1114
}
1166
1115
1167
1116
/// Creates a match for a tuple of all `self_args`, where either all
@@ -1181,11 +1130,11 @@ impl<'a> MethodDef<'a> {
1181
1130
1182
1131
/// ```{.text}
1183
1132
/// let __self0_vi = unsafe {
1184
- /// std::intrinsics::discriminant_value(&self) } as i32 ;
1133
+ /// std::intrinsics::discriminant_value(&self) };
1185
1134
/// let __self1_vi = unsafe {
1186
- /// std::intrinsics::discriminant_value(&arg1) } as i32 ;
1135
+ /// std::intrinsics::discriminant_value(&arg1) };
1187
1136
/// let __self2_vi = unsafe {
1188
- /// std::intrinsics::discriminant_value(&arg2) } as i32 ;
1137
+ /// std::intrinsics::discriminant_value(&arg2) };
1189
1138
///
1190
1139
/// if __self0_vi == __self1_vi && __self0_vi == __self2_vi && ... {
1191
1140
/// match (...) {
@@ -1204,7 +1153,6 @@ impl<'a> MethodDef<'a> {
1204
1153
cx : & mut ExtCtxt < ' _ > ,
1205
1154
trait_ : & TraitDef < ' b > ,
1206
1155
enum_def : & ' b EnumDef ,
1207
- type_attrs : & [ ast:: Attribute ] ,
1208
1156
type_ident : Ident ,
1209
1157
mut self_args : Vec < P < Expr > > ,
1210
1158
nonself_args : & [ P < Expr > ] ,
@@ -1392,39 +1340,31 @@ impl<'a> MethodDef<'a> {
1392
1340
//
1393
1341
if variants. len ( ) > 1 && self_args. len ( ) > 1 {
1394
1342
// Build a series of let statements mapping each self_arg
1395
- // to its discriminant value. If this is a C-style enum
1396
- // with a specific repr type, then casts the values to
1397
- // that type. Otherwise casts to `i32` (the default repr
1398
- // type).
1343
+ // to its discriminant value.
1399
1344
//
1400
1345
// i.e., for `enum E<T> { A, B(1), C(T, T) }`, and a deriving
1401
1346
// with three Self args, builds three statements:
1402
1347
//
1403
1348
// ```
1404
1349
// let __self0_vi = unsafe {
1405
- // std::intrinsics::discriminant_value(&self) } as i32 ;
1350
+ // std::intrinsics::discriminant_value(&self) };
1406
1351
// let __self1_vi = unsafe {
1407
- // std::intrinsics::discriminant_value(&arg1) } as i32 ;
1352
+ // std::intrinsics::discriminant_value(&arg1) };
1408
1353
// let __self2_vi = unsafe {
1409
- // std::intrinsics::discriminant_value(&arg2) } as i32 ;
1354
+ // std::intrinsics::discriminant_value(&arg2) };
1410
1355
// ```
1411
1356
let mut index_let_stmts: Vec < ast:: Stmt > = Vec :: with_capacity ( vi_idents. len ( ) + 1 ) ;
1412
1357
1413
1358
// We also build an expression which checks whether all discriminants are equal
1414
1359
// discriminant_test = __self0_vi == __self1_vi && __self0_vi == __self2_vi && ...
1415
1360
let mut discriminant_test = cx. expr_bool ( sp, true ) ;
1416
1361
1417
- let target_type_name = find_repr_type_name ( & cx. parse_sess , type_attrs) ;
1418
-
1419
1362
let mut first_ident = None ;
1420
1363
for ( & ident, self_arg) in vi_idents. iter ( ) . zip ( & self_args) {
1421
1364
let self_addr = cx. expr_addr_of ( sp, self_arg. clone ( ) ) ;
1422
1365
let variant_value =
1423
1366
deriving:: call_intrinsic ( cx, sp, "discriminant_value" , vec ! [ self_addr] ) ;
1424
-
1425
- let target_ty = cx. ty_ident ( sp, cx. ident_of ( target_type_name, sp) ) ;
1426
- let variant_disr = cx. expr_cast ( sp, variant_value, target_ty) ;
1427
- let let_stmt = cx. stmt_let ( sp, false , ident, variant_disr) ;
1367
+ let let_stmt = cx. stmt_let ( sp, false , ident, variant_value) ;
1428
1368
index_let_stmts. push ( let_stmt) ;
1429
1369
1430
1370
match first_ident {
0 commit comments