2121//! `struct T(i32, char)`).
2222//! - `EnumMatching`, when `Self` is an enum and all the arguments are the
2323//! 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 .
2525//! - `StaticEnum` and `StaticStruct` for static methods, where the type
2626//! being derived upon is either an enum or struct respectively. (Any
2727//! argument with type Self is just grouped among the non-self
143143//! )
144144//! ```
145145//!
146- //! For the tags ,
146+ //! For the discriminants ,
147147//!
148148//! ```text
149- //! EnumTag (
150- //! &[<ident of self tag >, <ident of other tag >],
149+ //! EnumDiscr (
150+ //! &[<ident of self discriminant >, <ident of other discriminant >],
151151//! <expr to combine with>,
152152//! )
153153//! ```
@@ -315,10 +315,10 @@ pub enum SubstructureFields<'a> {
315315 /// variant.
316316 EnumMatching ( usize , & ' a ast:: Variant , Vec < FieldInfo > ) ,
317317
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
319319 /// 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 > > ) ,
322322
323323 /// A static method where `Self` is a struct.
324324 StaticStruct ( & ' a ast:: VariantData , StaticFields ) ,
@@ -1137,9 +1137,9 @@ impl<'a> MethodDef<'a> {
11371137 /// impl ::core::cmp::PartialEq for A {
11381138 /// #[inline]
11391139 /// 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
11431143 /// && match (self, other) {
11441144 /// (A::A2(__self_0), A::A2(__arg1_0)) => *__self_0 == *__arg1_0,
11451145 /// _ => true,
@@ -1148,7 +1148,7 @@ impl<'a> MethodDef<'a> {
11481148 /// }
11491149 /// ```
11501150 ///
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
11521152 /// `selflike_args`, with an arm for each variant with fields, possibly an
11531153 /// arm for each fieldless variant (if `unify_fieldless_variants` is not
11541154 /// `Unify`), and possibly a default arm.
@@ -1169,7 +1169,7 @@ impl<'a> MethodDef<'a> {
11691169 let span = trait_. span ;
11701170 let variants = & enum_def. variants ;
11711171
1172- // Traits that unify fieldless variants always use the tag (s).
1172+ // Traits that unify fieldless variants always use the discriminant (s).
11731173 let unify_fieldless_variants =
11741174 self . fieldless_variants_strategy == FieldlessVariantsStrategy :: Unify ;
11751175
@@ -1199,25 +1199,25 @@ impl<'a> MethodDef<'a> {
11991199 //
12001200 // e.g. for `PartialEq::eq` builds two statements:
12011201 // ```
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);
12041204 // ```
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
12071207 . 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) )
12091209 . collect ( ) ;
12101210
1211- let mut tag_exprs : Vec < _ > = tag_idents
1211+ let mut discr_exprs : Vec < _ > = discr_idents
12121212 . iter ( )
12131213 . map ( |& ident| cx. expr_addr_of ( span, cx. expr_ident ( span, ident) ) )
12141214 . collect ( ) ;
12151215
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 } ;
12191219
1220- let tag_let_stmts : ThinVec < _ > = iter:: zip ( & tag_idents , & selflike_args)
1220+ let discr_let_stmts : ThinVec < _ > = iter:: zip ( & discr_idents , & selflike_args)
12211221 . map ( |( & ident, selflike_arg) | {
12221222 let variant_value = deriving:: call_intrinsic (
12231223 cx,
@@ -1229,7 +1229,7 @@ impl<'a> MethodDef<'a> {
12291229 } )
12301230 . collect ( ) ;
12311231
1232- ( tag_field , tag_let_stmts )
1232+ ( discr_field , discr_let_stmts )
12331233 } ;
12341234
12351235 // There are some special cases involving fieldless enums where no
@@ -1239,19 +1239,19 @@ impl<'a> MethodDef<'a> {
12391239 if variants. len ( ) > 1 {
12401240 match self . fieldless_variants_strategy {
12411241 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
12431243 // 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 (
12471247 cx,
12481248 trait_,
12491249 type_ident,
12501250 nonselflike_args,
1251- & EnumTag ( tag_field , None ) ,
1251+ & EnumDiscr ( discr_field , None ) ,
12521252 ) ;
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 ) ;
12551255 }
12561256 FieldlessVariantsStrategy :: SpecializeIfAllVariantsFieldless => {
12571257 return self . call_substructure_method (
@@ -1266,7 +1266,7 @@ impl<'a> MethodDef<'a> {
12661266 }
12671267 } else if variants. len ( ) == 1 {
12681268 // 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.
12701270 return self . call_substructure_method (
12711271 cx,
12721272 trait_,
@@ -1380,22 +1380,22 @@ impl<'a> MethodDef<'a> {
13801380 cx. expr_match ( span, match_arg, match_arms)
13811381 } ;
13821382
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
13851385 // is enough.
13861386 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) ;
13881388
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 (
13911391 cx,
13921392 trait_,
13931393 type_ident,
13941394 nonselflike_args,
1395- & EnumTag ( tag_field , Some ( get_match_expr ( selflike_args) ) ) ,
1395+ & EnumDiscr ( discr_field , Some ( get_match_expr ( selflike_args) ) ) ,
13961396 ) ;
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 )
13991399 } else {
14001400 BlockOrExpr ( ThinVec :: new ( ) , Some ( get_match_expr ( selflike_args) ) )
14011401 }
@@ -1701,16 +1701,16 @@ where
17011701 rest. iter ( ) . rfold ( base_expr, op)
17021702 }
17031703 }
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 ) ) ;
17061706 if let Some ( match_expr) = match_expr {
17071707 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 ( ) ) )
17091709 } 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 ) )
17111711 }
17121712 } else {
1713- tag_check_expr
1713+ discr_check_expr
17141714 }
17151715 }
17161716 StaticEnum ( ..) | StaticStruct ( ..) => {
0 commit comments