From 41dd35503a358b652cfbbf7fba499cbaf1234637 Mon Sep 17 00:00:00 2001 From: James Miller Date: Sun, 11 Jan 2015 12:58:20 +1300 Subject: [PATCH 01/10] Implement `discriminant_value` intrinsic Implements an intrinsic for extracting the value of the discriminant enum variant values. For non-enum types, this returns zero, otherwise it returns the value we use for discriminant comparisons. This means that enum types that do not have a discriminant will also work in this arrangement. This is (at least part of) the work on Issue #24263 --- src/libcore/intrinsics.rs | 6 ++++++ src/librustc_trans/trans/intrinsic.rs | 12 ++++++++++++ src/librustc_typeck/check/mod.rs | 6 ++++++ 3 files changed, 24 insertions(+) diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index 0e91eafce187f..80f506ebc0643 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -569,4 +569,10 @@ extern "rust-intrinsic" { pub fn overflowing_sub(a: T, b: T) -> T; /// Returns (a * b) mod 2^N, where N is the width of N in bits. pub fn overflowing_mul(a: T, b: T) -> T; + + /// Returns the value of the discriminant for the variant in 'v', + /// cast to a `u64`; if `T` has no discriminant, returns 0. + // SNAP 5520801 + #[cfg(not(stage0))] + pub fn discriminant_value(v: &T) -> u64; } diff --git a/src/librustc_trans/trans/intrinsic.rs b/src/librustc_trans/trans/intrinsic.rs index 62a6ede4c2f93..fc3c0841dd84e 100644 --- a/src/librustc_trans/trans/intrinsic.rs +++ b/src/librustc_trans/trans/intrinsic.rs @@ -14,6 +14,7 @@ use llvm; use llvm::{SequentiallyConsistent, Acquire, Release, AtomicXchg, ValueRef, TypeKind}; use middle::subst; use middle::subst::FnSpace; +use trans::adt; use trans::base::*; use trans::build::*; use trans::callee; @@ -683,6 +684,17 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, } } + (_, "discriminant_value") => { + let val_ty = substs.types.get(FnSpace, 0); + match val_ty.sty { + ty::ty_enum(..) => { + let repr = adt::represent_type(ccx, *val_ty); + adt::trans_get_discr(bcx, &*repr, llargs[0], Some(llret_ty)) + } + _ => C_null(llret_ty) + } + } + // This requires that atomic intrinsics follow a specific naming pattern: // "atomic_[_]", and no ordering means SeqCst (_, name) if name.starts_with("atomic_") => { diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index f7bbc693ce59b..31039e3abca6e 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -5073,6 +5073,12 @@ pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &ast::ForeignItem) { "assume" => (0, vec![tcx.types.bool], ty::mk_nil(tcx)), + "discriminant_value" => (1, vec![ + ty::mk_imm_rptr(tcx, + tcx.mk_region(ty::ReLateBound(ty::DebruijnIndex::new(1), + ty::BrAnon(0))), + param(ccx, 0))], tcx.types.u64), + ref other => { span_err!(tcx.sess, it.span, E0093, "unrecognized intrinsic function: `{}`", *other); From 800c5f8038280fe8524ebd797b93c2ad4e16e1b7 Mon Sep 17 00:00:00 2001 From: James Miller Date: Sun, 11 Jan 2015 13:51:58 +1300 Subject: [PATCH 02/10] Add test for discriminant_value results --- src/test/run-pass/discriminant_value.rs | 62 +++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/test/run-pass/discriminant_value.rs diff --git a/src/test/run-pass/discriminant_value.rs b/src/test/run-pass/discriminant_value.rs new file mode 100644 index 0000000000000..531a30d658001 --- /dev/null +++ b/src/test/run-pass/discriminant_value.rs @@ -0,0 +1,62 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +extern crate core; +use core::intrinsics::discriminant_value; + +enum CLike1 { + A, + B, + C, + D +} + +enum CLike2 { + A = 5, + B = 2, + C = 19, + D +} + +enum ADT { + First(u32, u32), + Second(u64) +} + +enum NullablePointer { + Something(&'static u32), + Nothing +} + +static CONST : u32 = 0xBEEF; + +pub fn main() { + unsafe { + + assert_eq!(discriminant_value(&CLike1::A), 0); + assert_eq!(discriminant_value(&CLike1::B), 1); + assert_eq!(discriminant_value(&CLike1::C), 2); + assert_eq!(discriminant_value(&CLike1::D), 3); + + assert_eq!(discriminant_value(&CLike2::A), 5); + assert_eq!(discriminant_value(&CLike2::B), 2); + assert_eq!(discriminant_value(&CLike2::C), 19); + assert_eq!(discriminant_value(&CLike2::D), 20); + + assert_eq!(discriminant_value(&ADT::First(0,0)), 0); + assert_eq!(discriminant_value(&ADT::Second(5)), 1); + + assert_eq!(discriminant_value(&NullablePointer::Nothing), 1); + assert_eq!(discriminant_value(&NullablePointer::Something(&CONST)), 0); + + assert_eq!(discriminant_value(&10), 0); + assert_eq!(discriminant_value(&"test"), 0); + } +} From ea2739176be213117f570d6b9ed787deac53880e Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 10 Apr 2015 16:14:00 +0200 Subject: [PATCH 03/10] Rebase discriminant_value test. Add case for a specialized repr. --- src/test/run-pass/discriminant_value.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/run-pass/discriminant_value.rs b/src/test/run-pass/discriminant_value.rs index 531a30d658001..217e696f09538 100644 --- a/src/test/run-pass/discriminant_value.rs +++ b/src/test/run-pass/discriminant_value.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + extern crate core; use core::intrinsics::discriminant_value; @@ -25,6 +27,14 @@ enum CLike2 { D } +#[repr(i8)] +enum CLike3 { + A = 5, + B, + C = -1, + D +} + enum ADT { First(u32, u32), Second(u64) @@ -50,6 +60,11 @@ pub fn main() { assert_eq!(discriminant_value(&CLike2::C), 19); assert_eq!(discriminant_value(&CLike2::D), 20); + assert_eq!(discriminant_value(&CLike3::A), 5); + assert_eq!(discriminant_value(&CLike3::B), 6); + assert_eq!(discriminant_value(&CLike3::C), -1_i8 as u64); + assert_eq!(discriminant_value(&CLike3::D), 0); + assert_eq!(discriminant_value(&ADT::First(0,0)), 0); assert_eq!(discriminant_value(&ADT::Second(5)), 1); From 6118795ee10bd7ad08cf697485be66a3fd685297 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 10 Apr 2015 16:15:12 +0200 Subject: [PATCH 04/10] Change `derive` expansions to use `discriminant_value` intrinsic. Fix #15523. --- src/libcore/lib.rs | 1 + src/libsyntax/ext/deriving/generic/mod.rs | 57 +++++++++++------------ 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 2189e2c3ad1ba..1b7311028f5ed 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -157,6 +157,7 @@ mod tuple; #[doc(hidden)] mod core { + pub use intrinsics; pub use panicking; pub use fmt; pub use clone; diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs index 397775fdbfec3..c3478266db278 100644 --- a/src/libsyntax/ext/deriving/generic/mod.rs +++ b/src/libsyntax/ext/deriving/generic/mod.rs @@ -706,15 +706,6 @@ impl<'a> TraitDef<'a> { } } -fn variant_to_pat(cx: &mut ExtCtxt, sp: Span, enum_ident: ast::Ident, variant: &ast::Variant) - -> P { - let path = cx.path(sp, vec![enum_ident, variant.node.name]); - cx.pat(sp, match variant.node.kind { - ast::TupleVariantKind(..) => ast::PatEnum(path, None), - ast::StructVariantKind(..) => ast::PatStruct(path, Vec::new(), true), - }) -} - impl<'a> MethodDef<'a> { fn call_substructure_method(&self, cx: &mut ExtCtxt, @@ -1044,8 +1035,8 @@ impl<'a> MethodDef<'a> { .collect::>(); // The `vi_idents` will be bound, solely in the catch-all, to - // a series of let statements mapping each self_arg to a usize - // corresponding to its variant index. + // a series of let statements mapping each self_arg to an isize + // corresponding to its discriminant value. let vi_idents: Vec = self_arg_names.iter() .map(|name| { let vi_suffix = format!("{}_vi", &name[..]); cx.ident_of(&vi_suffix[..]) }) @@ -1160,33 +1151,39 @@ impl<'a> MethodDef<'a> { // unreachable-pattern error. // if variants.len() > 1 && self_args.len() > 1 { - let arms: Vec = variants.iter().enumerate() - .map(|(index, variant)| { - let pat = variant_to_pat(cx, sp, type_ident, &**variant); - let lit = ast::LitInt(index as u64, ast::UnsignedIntLit(ast::TyUs)); - cx.arm(sp, vec![pat], cx.expr_lit(sp, lit)) - }).collect(); - // Build a series of let statements mapping each self_arg - // to a usize corresponding to its variant index. + // to its discriminant value. If this is a C-style enum + // with a specific repr type, then casts the values to + // that type. Otherwise casts to `isize`. + // // i.e. for `enum E { A, B(1), C(T, T) }`, and a deriving // with three Self args, builds three statements: // // ``` - // let __self0_vi = match self { - // A => 0, B(..) => 1, C(..) => 2 - // }; - // let __self1_vi = match __arg1 { - // A => 0, B(..) => 1, C(..) => 2 - // }; - // let __self2_vi = match __arg2 { - // A => 0, B(..) => 1, C(..) => 2 - // }; + // let __self0_vi = unsafe { + // std::intrinsics::discriminant_value(&self) } as isize; + // let __self1_vi = unsafe { + // std::intrinsics::discriminant_value(&__arg1) } as isize; + // let __self2_vi = unsafe { + // std::intrinsics::discriminant_value(&__arg2) } as isize; // ``` let mut index_let_stmts: Vec> = Vec::new(); for (&ident, self_arg) in vi_idents.iter().zip(self_args.iter()) { - let variant_idx = cx.expr_match(sp, self_arg.clone(), arms.clone()); - let let_stmt = cx.stmt_let(sp, false, ident, variant_idx); + let path = vec![cx.ident_of_std("core"), + cx.ident_of("intrinsics"), + cx.ident_of("discriminant_value")]; + let call = cx.expr_call_global( + sp, path, vec![cx.expr_addr_of(sp, self_arg.clone())]); + let variant_value = cx.expr_block(P(ast::Block { + stmts: vec![], + expr: Some(call), + id: ast::DUMMY_NODE_ID, + rules: ast::UnsafeBlock(ast::CompilerGenerated), + span: sp })); + + let target_ty = cx.ty_ident(sp, cx.ident_of("isize")); + let variant_disr = cx.expr_cast(sp, variant_value, target_ty); + let let_stmt = cx.stmt_let(sp, false, ident, variant_disr); index_let_stmts.push(let_stmt); } From c44d40e77f4dabbfff95a715006523b73918a7c4 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 10 Apr 2015 16:17:06 +0200 Subject: [PATCH 05/10] Test case for new `derive(PartialOrd)` expansion. --- src/test/run-pass/issue-15523.rs | 49 ++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/test/run-pass/issue-15523.rs diff --git a/src/test/run-pass/issue-15523.rs b/src/test/run-pass/issue-15523.rs new file mode 100644 index 0000000000000..8edf360c98563 --- /dev/null +++ b/src/test/run-pass/issue-15523.rs @@ -0,0 +1,49 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Issue 15523: derive(PartialOrd) should use the provided +// discriminant values for the derived ordering. + +#[derive(PartialEq, PartialOrd)] +enum E1 { + Pos2 = 2, + Neg1 = -1, + Pos1 = 1, +} + +#[derive(PartialEq, PartialOrd)] +#[repr(u8)] +enum E2 { + Pos2 = 2, + PosMax = !0 as u8, + Pos1 = 1, +} + +#[derive(PartialEq, PartialOrd)] +#[repr(i8)] +enum E3 { + Pos2 = 2, + Neg1 = -1_i8, + Pos1 = 1, +} + +fn main() { + assert!(E1::Pos2 > E1::Pos1); + assert!(E1::Pos1 > E1::Neg1); + assert!(E1::Pos2 > E1::Neg1); + + assert!(E2::Pos2 > E2::Pos1); + assert!(E2::Pos1 < E2::PosMax); + assert!(E2::Pos2 < E2::PosMax); + + assert!(E3::Pos2 > E3::Pos1); + assert!(E3::Pos1 > E3::Neg1); + assert!(E3::Pos2 > E3::Neg1); +} From afb7acff57cf301f6229eb9a07060d694ed2b3ed Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 10 Apr 2015 16:26:11 +0200 Subject: [PATCH 06/10] Re-add a fixme after some investigation into what's going on. --- src/libsyntax/ext/deriving/generic/mod.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs index c3478266db278..de77baa0ef21f 100644 --- a/src/libsyntax/ext/deriving/generic/mod.rs +++ b/src/libsyntax/ext/deriving/generic/mod.rs @@ -1181,6 +1181,17 @@ impl<'a> MethodDef<'a> { rules: ast::UnsafeBlock(ast::CompilerGenerated), span: sp })); + // FIXME: This unconditionally casts to `isize`. However: + // + // 1. On 32-bit platforms, that will truncate 64-bit enums + // that are making use of the upper 32 bits, and + // + // 2. On all platforms, it will misinterpret the sign bit + // of a 64-bit enum. + // + // What it should do is lookup whether the enum has an + // repr-attribute and cast to that if necessary. But + // attributes are not yet available to this function. let target_ty = cx.ty_ident(sp, cx.ident_of("isize")); let variant_disr = cx.expr_cast(sp, variant_value, target_ty); let let_stmt = cx.stmt_let(sp, false, ident, variant_disr); From 781fc902a40001f23d24d76eb799551c308a5900 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 10 Apr 2015 19:00:38 +0200 Subject: [PATCH 07/10] Incorporate repr-attr into deriving(PartialOrd) to avoid truncation errors. remove out of date fixme. --- src/libsyntax/ext/deriving/generic/mod.rs | 51 +++++++++++++++++------ 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs index de77baa0ef21f..6a85297b6580f 100644 --- a/src/libsyntax/ext/deriving/generic/mod.rs +++ b/src/libsyntax/ext/deriving/generic/mod.rs @@ -201,6 +201,7 @@ use ext::base::ExtCtxt; use ext::build::AstBuilder; use codemap::{self, DUMMY_SP}; use codemap::Span; +use diagnostic::SpanHandler; use fold::MoveMap; use owned_slice::OwnedSlice; use parse::token::InternedString; @@ -391,6 +392,7 @@ impl<'a> TraitDef<'a> { ast::ItemEnum(ref enum_def, ref generics) => { self.expand_enum_def(cx, enum_def, + &item.attrs[..], item.ident, generics) } @@ -653,6 +655,7 @@ impl<'a> TraitDef<'a> { fn expand_enum_def(&self, cx: &mut ExtCtxt, enum_def: &EnumDef, + type_attrs: &[ast::Attribute], type_ident: Ident, generics: &Generics) -> P { let mut field_tys = Vec::new(); @@ -687,6 +690,7 @@ impl<'a> TraitDef<'a> { method_def.expand_enum_method_body(cx, self, enum_def, + type_attrs, type_ident, self_args, &nonself_args[..]) @@ -706,6 +710,32 @@ impl<'a> TraitDef<'a> { } } +fn find_repr_type_name(diagnostic: &SpanHandler, + type_attrs: &[ast::Attribute]) -> &'static str { + let mut repr_type_name = "i32"; + for a in type_attrs { + for r in &attr::find_repr_attrs(diagnostic, a) { + repr_type_name = match *r { + attr::ReprAny | attr::ReprPacked => continue, + attr::ReprExtern => "i32", + + attr::ReprInt(_, attr::SignedInt(ast::TyIs)) => "isize", + attr::ReprInt(_, attr::SignedInt(ast::TyI8)) => "i8", + attr::ReprInt(_, attr::SignedInt(ast::TyI16)) => "i16", + attr::ReprInt(_, attr::SignedInt(ast::TyI32)) => "i32", + attr::ReprInt(_, attr::SignedInt(ast::TyI64)) => "i64", + + attr::ReprInt(_, attr::UnsignedInt(ast::TyUs)) => "usize", + attr::ReprInt(_, attr::UnsignedInt(ast::TyU8)) => "u8", + attr::ReprInt(_, attr::UnsignedInt(ast::TyU16)) => "u16", + attr::ReprInt(_, attr::UnsignedInt(ast::TyU32)) => "u32", + attr::ReprInt(_, attr::UnsignedInt(ast::TyU64)) => "u64", + } + } + } + repr_type_name +} + impl<'a> MethodDef<'a> { fn call_substructure_method(&self, cx: &mut ExtCtxt, @@ -974,12 +1004,13 @@ impl<'a> MethodDef<'a> { cx: &mut ExtCtxt, trait_: &TraitDef, enum_def: &EnumDef, + type_attrs: &[ast::Attribute], type_ident: Ident, self_args: Vec>, nonself_args: &[P]) -> P { self.build_enum_match_tuple( - cx, trait_, enum_def, type_ident, self_args, nonself_args) + cx, trait_, enum_def, type_attrs, type_ident, self_args, nonself_args) } @@ -1013,6 +1044,7 @@ impl<'a> MethodDef<'a> { cx: &mut ExtCtxt, trait_: &TraitDef, enum_def: &EnumDef, + type_attrs: &[ast::Attribute], type_ident: Ident, self_args: Vec>, nonself_args: &[P]) -> P { @@ -1168,6 +1200,10 @@ impl<'a> MethodDef<'a> { // std::intrinsics::discriminant_value(&__arg2) } as isize; // ``` let mut index_let_stmts: Vec> = Vec::new(); + + let target_type_name = + find_repr_type_name(&cx.parse_sess.span_diagnostic, type_attrs); + for (&ident, self_arg) in vi_idents.iter().zip(self_args.iter()) { let path = vec![cx.ident_of_std("core"), cx.ident_of("intrinsics"), @@ -1181,18 +1217,7 @@ impl<'a> MethodDef<'a> { rules: ast::UnsafeBlock(ast::CompilerGenerated), span: sp })); - // FIXME: This unconditionally casts to `isize`. However: - // - // 1. On 32-bit platforms, that will truncate 64-bit enums - // that are making use of the upper 32 bits, and - // - // 2. On all platforms, it will misinterpret the sign bit - // of a 64-bit enum. - // - // What it should do is lookup whether the enum has an - // repr-attribute and cast to that if necessary. But - // attributes are not yet available to this function. - let target_ty = cx.ty_ident(sp, cx.ident_of("isize")); + let target_ty = cx.ty_ident(sp, cx.ident_of(target_type_name)); let variant_disr = cx.expr_cast(sp, variant_value, target_ty); let let_stmt = cx.stmt_let(sp, false, ident, variant_disr); index_let_stmts.push(let_stmt); From 47016f9ce514fd5975a4412259ce3022b877ad3d Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 10 Apr 2015 19:02:01 +0200 Subject: [PATCH 08/10] Test case for 64-bit corner cases where truncation occurred before prior commit. --- src/test/run-pass/issue-15523-big.rs | 48 ++++++++++++++++++++++++++++ src/test/run-pass/issue-15523.rs | 2 ++ 2 files changed, 50 insertions(+) create mode 100644 src/test/run-pass/issue-15523-big.rs diff --git a/src/test/run-pass/issue-15523-big.rs b/src/test/run-pass/issue-15523-big.rs new file mode 100644 index 0000000000000..33c81cab3817b --- /dev/null +++ b/src/test/run-pass/issue-15523-big.rs @@ -0,0 +1,48 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Issue 15523: derive(PartialOrd) should use the provided +// discriminant values for the derived ordering. +// +// This test is checking corner cases that arise when you have +// 64-bit values in the variants. + +#[derive(PartialEq, PartialOrd)] +#[repr(u64)] +enum Eu64 { + Pos2 = 2, + PosMax = !0, + Pos1 = 1, +} + +#[derive(PartialEq, PartialOrd)] +#[repr(i64)] +enum Ei64 { + Pos2 = 2, + Neg1 = -1, + NegMin = 1 << 63, + PosMax = !(1 << 63), + Pos1 = 1, +} + +fn main() { + assert!(Eu64::Pos2 > Eu64::Pos1); + assert!(Eu64::Pos2 < Eu64::PosMax); + assert!(Eu64::Pos1 < Eu64::PosMax); + + + assert!(Ei64::Pos2 > Ei64::Pos1); + assert!(Ei64::Pos2 > Ei64::Neg1); + assert!(Ei64::Pos1 > Ei64::Neg1); + assert!(Ei64::Pos2 > Ei64::NegMin); + assert!(Ei64::Pos1 > Ei64::NegMin); + assert!(Ei64::Pos2 < Ei64::PosMax); + assert!(Ei64::Pos1 < Ei64::PosMax); +} diff --git a/src/test/run-pass/issue-15523.rs b/src/test/run-pass/issue-15523.rs index 8edf360c98563..bb8fa6791a5c4 100644 --- a/src/test/run-pass/issue-15523.rs +++ b/src/test/run-pass/issue-15523.rs @@ -10,6 +10,8 @@ // Issue 15523: derive(PartialOrd) should use the provided // discriminant values for the derived ordering. +// +// This is checking the basic functionality. #[derive(PartialEq, PartialOrd)] enum E1 { From 847a897fb33cb035d0311d717b094cad5e137787 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 10 Apr 2015 19:13:34 +0200 Subject: [PATCH 09/10] fix some comments. --- src/libsyntax/ext/deriving/generic/mod.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs index 6a85297b6580f..ac96375095e14 100644 --- a/src/libsyntax/ext/deriving/generic/mod.rs +++ b/src/libsyntax/ext/deriving/generic/mod.rs @@ -1067,8 +1067,8 @@ impl<'a> MethodDef<'a> { .collect::>(); // The `vi_idents` will be bound, solely in the catch-all, to - // a series of let statements mapping each self_arg to an isize - // corresponding to its discriminant value. + // a series of let statements mapping each self_arg to an int + // value corresponding to its discriminant. let vi_idents: Vec = self_arg_names.iter() .map(|name| { let vi_suffix = format!("{}_vi", &name[..]); cx.ident_of(&vi_suffix[..]) }) @@ -1186,18 +1186,19 @@ impl<'a> MethodDef<'a> { // Build a series of let statements mapping each self_arg // to its discriminant value. If this is a C-style enum // with a specific repr type, then casts the values to - // that type. Otherwise casts to `isize`. + // that type. Otherwise casts to `i32` (the default repr + // type). // // i.e. for `enum E { A, B(1), C(T, T) }`, and a deriving // with three Self args, builds three statements: // // ``` // let __self0_vi = unsafe { - // std::intrinsics::discriminant_value(&self) } as isize; + // std::intrinsics::discriminant_value(&self) } as i32; // let __self1_vi = unsafe { - // std::intrinsics::discriminant_value(&__arg1) } as isize; + // std::intrinsics::discriminant_value(&__arg1) } as i32; // let __self2_vi = unsafe { - // std::intrinsics::discriminant_value(&__arg2) } as isize; + // std::intrinsics::discriminant_value(&__arg2) } as i32; // ``` let mut index_let_stmts: Vec> = Vec::new(); From 05aaad114f343ab6d484aa193b99e221089f4a8b Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Sat, 11 Apr 2015 00:50:59 +0200 Subject: [PATCH 10/10] Remove pretty-expanded from 2 tests; deriving(Ord) uses unstable intrinsic. --- src/test/run-pass/issue-18738.rs | 2 -- src/test/run-pass/while-prelude-drop.rs | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/test/run-pass/issue-18738.rs b/src/test/run-pass/issue-18738.rs index a92fcb01f5b30..819ec532ed2ce 100644 --- a/src/test/run-pass/issue-18738.rs +++ b/src/test/run-pass/issue-18738.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// pretty-expanded FIXME #23616 - #[derive(Eq, PartialEq, PartialOrd, Ord)] enum Test<'a> { Int(&'a isize), diff --git a/src/test/run-pass/while-prelude-drop.rs b/src/test/run-pass/while-prelude-drop.rs index 88d5314a96ac5..7ff770327742b 100644 --- a/src/test/run-pass/while-prelude-drop.rs +++ b/src/test/run-pass/while-prelude-drop.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// pretty-expanded FIXME #23616 - #![feature(collections)] use std::string::String;