21
21
//! `struct T(i32, char)`).
22
22
//! - `EnumMatching`, when `Self` is an enum and all the arguments are the
23
23
//! same variant of the enum (e.g., `Some(1)`, `Some(3)` and `Some(4)`)
24
- //! - `EnumTag ` when `Self` is an enum, for comparing the enum tags .
24
+ //! - `EnumDiscr ` when `Self` is an enum, for comparing the enum discriminants .
25
25
//! - `StaticEnum` and `StaticStruct` for static methods, where the type
26
26
//! being derived upon is either an enum or struct respectively. (Any
27
27
//! argument with type Self is just grouped among the non-self
143
143
//! )
144
144
//! ```
145
145
//!
146
- //! For the tags ,
146
+ //! For the discriminants ,
147
147
//!
148
148
//! ```text
149
- //! EnumTag (
150
- //! &[<ident of self tag >, <ident of other tag >],
149
+ //! EnumDiscr (
150
+ //! &[<ident of self discriminant >, <ident of other discriminant >],
151
151
//! <expr to combine with>,
152
152
//! )
153
153
//! ```
@@ -315,10 +315,10 @@ pub enum SubstructureFields<'a> {
315
315
/// variant.
316
316
EnumMatching ( usize , & ' a ast:: Variant , Vec < FieldInfo > ) ,
317
317
318
- /// The tag of an enum. The first field is a `FieldInfo` for the tags , as
318
+ /// The discriminant of an enum. The first field is a `FieldInfo` for the discriminants , as
319
319
/// if they were fields. The second field is the expression to combine the
320
- /// tag expression with; it will be `None` if no match is necessary.
321
- EnumTag ( FieldInfo , Option < P < Expr > > ) ,
320
+ /// discriminant expression with; it will be `None` if no match is necessary.
321
+ EnumDiscr ( FieldInfo , Option < P < Expr > > ) ,
322
322
323
323
/// A static method where `Self` is a struct.
324
324
StaticStruct ( & ' a ast:: VariantData , StaticFields ) ,
@@ -1137,9 +1137,9 @@ impl<'a> MethodDef<'a> {
1137
1137
/// impl ::core::cmp::PartialEq for A {
1138
1138
/// #[inline]
1139
1139
/// fn eq(&self, other: &A) -> bool {
1140
- /// let __self_tag = ::core::intrinsics::discriminant_value(self);
1141
- /// let __arg1_tag = ::core::intrinsics::discriminant_value(other);
1142
- /// __self_tag == __arg1_tag
1140
+ /// let __self_discr = ::core::intrinsics::discriminant_value(self);
1141
+ /// let __arg1_discr = ::core::intrinsics::discriminant_value(other);
1142
+ /// __self_discr == __arg1_discr
1143
1143
/// && match (self, other) {
1144
1144
/// (A::A2(__self_0), A::A2(__arg1_0)) => *__self_0 == *__arg1_0,
1145
1145
/// _ => true,
@@ -1148,7 +1148,7 @@ impl<'a> MethodDef<'a> {
1148
1148
/// }
1149
1149
/// ```
1150
1150
///
1151
- /// Creates a tag check combined with a match for a tuple of all
1151
+ /// Creates a discriminant check combined with a match for a tuple of all
1152
1152
/// `selflike_args`, with an arm for each variant with fields, possibly an
1153
1153
/// arm for each fieldless variant (if `unify_fieldless_variants` is not
1154
1154
/// `Unify`), and possibly a default arm.
@@ -1169,7 +1169,7 @@ impl<'a> MethodDef<'a> {
1169
1169
let span = trait_. span ;
1170
1170
let variants = & enum_def. variants ;
1171
1171
1172
- // Traits that unify fieldless variants always use the tag (s).
1172
+ // Traits that unify fieldless variants always use the discriminant (s).
1173
1173
let unify_fieldless_variants =
1174
1174
self . fieldless_variants_strategy == FieldlessVariantsStrategy :: Unify ;
1175
1175
@@ -1199,25 +1199,25 @@ impl<'a> MethodDef<'a> {
1199
1199
//
1200
1200
// e.g. for `PartialEq::eq` builds two statements:
1201
1201
// ```
1202
- // let __self_tag = ::core::intrinsics::discriminant_value(self);
1203
- // let __arg1_tag = ::core::intrinsics::discriminant_value(other);
1202
+ // let __self_discr = ::core::intrinsics::discriminant_value(self);
1203
+ // let __arg1_discr = ::core::intrinsics::discriminant_value(other);
1204
1204
// ```
1205
- let get_tag_pieces = |cx : & ExtCtxt < ' _ > | {
1206
- let tag_idents : Vec < _ > = prefixes
1205
+ let get_discr_pieces = |cx : & ExtCtxt < ' _ > | {
1206
+ let discr_idents : Vec < _ > = prefixes
1207
1207
. iter ( )
1208
- . map ( |name| Ident :: from_str_and_span ( & format ! ( "{name}_tag " ) , span) )
1208
+ . map ( |name| Ident :: from_str_and_span ( & format ! ( "{name}_discr " ) , span) )
1209
1209
. collect ( ) ;
1210
1210
1211
- let mut tag_exprs : Vec < _ > = tag_idents
1211
+ let mut discr_exprs : Vec < _ > = discr_idents
1212
1212
. iter ( )
1213
1213
. map ( |& ident| cx. expr_addr_of ( span, cx. expr_ident ( span, ident) ) )
1214
1214
. collect ( ) ;
1215
1215
1216
- let self_expr = tag_exprs . remove ( 0 ) ;
1217
- let other_selflike_exprs = tag_exprs ;
1218
- let tag_field = FieldInfo { span, name : None , self_expr, other_selflike_exprs } ;
1216
+ let self_expr = discr_exprs . remove ( 0 ) ;
1217
+ let other_selflike_exprs = discr_exprs ;
1218
+ let discr_field = FieldInfo { span, name : None , self_expr, other_selflike_exprs } ;
1219
1219
1220
- let tag_let_stmts : ThinVec < _ > = iter:: zip ( & tag_idents , & selflike_args)
1220
+ let discr_let_stmts : ThinVec < _ > = iter:: zip ( & discr_idents , & selflike_args)
1221
1221
. map ( |( & ident, selflike_arg) | {
1222
1222
let variant_value = deriving:: call_intrinsic (
1223
1223
cx,
@@ -1229,7 +1229,7 @@ impl<'a> MethodDef<'a> {
1229
1229
} )
1230
1230
. collect ( ) ;
1231
1231
1232
- ( tag_field , tag_let_stmts )
1232
+ ( discr_field , discr_let_stmts )
1233
1233
} ;
1234
1234
1235
1235
// There are some special cases involving fieldless enums where no
@@ -1239,19 +1239,19 @@ impl<'a> MethodDef<'a> {
1239
1239
if variants. len ( ) > 1 {
1240
1240
match self . fieldless_variants_strategy {
1241
1241
FieldlessVariantsStrategy :: Unify => {
1242
- // If the type is fieldless and the trait uses the tag and
1242
+ // If the type is fieldless and the trait uses the discriminant and
1243
1243
// there are multiple variants, we need just an operation on
1244
- // the tag (s).
1245
- let ( tag_field , mut tag_let_stmts ) = get_tag_pieces ( cx) ;
1246
- let mut tag_check = self . call_substructure_method (
1244
+ // the discriminant (s).
1245
+ let ( discr_field , mut discr_let_stmts ) = get_discr_pieces ( cx) ;
1246
+ let mut discr_check = self . call_substructure_method (
1247
1247
cx,
1248
1248
trait_,
1249
1249
type_ident,
1250
1250
nonselflike_args,
1251
- & EnumTag ( tag_field , None ) ,
1251
+ & EnumDiscr ( discr_field , None ) ,
1252
1252
) ;
1253
- tag_let_stmts . append ( & mut tag_check . 0 ) ;
1254
- return BlockOrExpr ( tag_let_stmts , tag_check . 1 ) ;
1253
+ discr_let_stmts . append ( & mut discr_check . 0 ) ;
1254
+ return BlockOrExpr ( discr_let_stmts , discr_check . 1 ) ;
1255
1255
}
1256
1256
FieldlessVariantsStrategy :: SpecializeIfAllVariantsFieldless => {
1257
1257
return self . call_substructure_method (
@@ -1266,7 +1266,7 @@ impl<'a> MethodDef<'a> {
1266
1266
}
1267
1267
} else if variants. len ( ) == 1 {
1268
1268
// If there is a single variant, we don't need an operation on
1269
- // the tag (s). Just use the most degenerate result.
1269
+ // the discriminant (s). Just use the most degenerate result.
1270
1270
return self . call_substructure_method (
1271
1271
cx,
1272
1272
trait_,
@@ -1380,22 +1380,22 @@ impl<'a> MethodDef<'a> {
1380
1380
cx. expr_match ( span, match_arg, match_arms)
1381
1381
} ;
1382
1382
1383
- // If the trait uses the tag and there are multiple variants, we need
1384
- // to add a tag check operation before the match. Otherwise, the match
1383
+ // If the trait uses the discriminant and there are multiple variants, we need
1384
+ // to add a discriminant check operation before the match. Otherwise, the match
1385
1385
// is enough.
1386
1386
if unify_fieldless_variants && variants. len ( ) > 1 {
1387
- let ( tag_field , mut tag_let_stmts ) = get_tag_pieces ( cx) ;
1387
+ let ( discr_field , mut discr_let_stmts ) = get_discr_pieces ( cx) ;
1388
1388
1389
- // Combine a tag check with the match.
1390
- let mut tag_check_plus_match = self . call_substructure_method (
1389
+ // Combine a discriminant check with the match.
1390
+ let mut discr_check_plus_match = self . call_substructure_method (
1391
1391
cx,
1392
1392
trait_,
1393
1393
type_ident,
1394
1394
nonselflike_args,
1395
- & EnumTag ( tag_field , Some ( get_match_expr ( selflike_args) ) ) ,
1395
+ & EnumDiscr ( discr_field , Some ( get_match_expr ( selflike_args) ) ) ,
1396
1396
) ;
1397
- tag_let_stmts . append ( & mut tag_check_plus_match . 0 ) ;
1398
- BlockOrExpr ( tag_let_stmts , tag_check_plus_match . 1 )
1397
+ discr_let_stmts . append ( & mut discr_check_plus_match . 0 ) ;
1398
+ BlockOrExpr ( discr_let_stmts , discr_check_plus_match . 1 )
1399
1399
} else {
1400
1400
BlockOrExpr ( ThinVec :: new ( ) , Some ( get_match_expr ( selflike_args) ) )
1401
1401
}
@@ -1701,16 +1701,16 @@ where
1701
1701
rest. iter ( ) . rfold ( base_expr, op)
1702
1702
}
1703
1703
}
1704
- EnumTag ( tag_field , match_expr) => {
1705
- let tag_check_expr = f ( cx, CsFold :: Single ( tag_field ) ) ;
1704
+ EnumDiscr ( discr_field , match_expr) => {
1705
+ let discr_check_expr = f ( cx, CsFold :: Single ( discr_field ) ) ;
1706
1706
if let Some ( match_expr) = match_expr {
1707
1707
if use_foldl {
1708
- f ( cx, CsFold :: Combine ( trait_span, tag_check_expr , match_expr. clone ( ) ) )
1708
+ f ( cx, CsFold :: Combine ( trait_span, discr_check_expr , match_expr. clone ( ) ) )
1709
1709
} else {
1710
- f ( cx, CsFold :: Combine ( trait_span, match_expr. clone ( ) , tag_check_expr ) )
1710
+ f ( cx, CsFold :: Combine ( trait_span, match_expr. clone ( ) , discr_check_expr ) )
1711
1711
}
1712
1712
} else {
1713
- tag_check_expr
1713
+ discr_check_expr
1714
1714
}
1715
1715
}
1716
1716
StaticEnum ( ..) | StaticStruct ( ..) => {
0 commit comments