From d4d5be18b702b5fd8b38b67d503860f788a14acd Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Wed, 24 Aug 2016 02:15:15 +0300 Subject: [PATCH] Feature gate the 128 bit types Dangling a carrot in front of a donkey. This commit includes manual merge conflict resolution changes from a rebase by @est31. --- src/libcore/lib.rs | 1 + src/librustc_i128/lib.rs | 1 + src/librustc_resolve/lib.rs | 15 ++++++++++++++- src/librustc_typeck/check/mod.rs | 7 +++++++ src/libsyntax/feature_gate.rs | 15 +++++++++++++++ src/test/compile-fail/i128-feature-2.rs | 20 ++++++++++++++++++++ src/test/compile-fail/i128-feature.rs | 8 ++++++++ src/test/run-pass/i128.rs | 2 ++ src/test/run-pass/u128.rs | 9 +++++++++ 9 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 src/test/compile-fail/i128-feature-2.rs create mode 100644 src/test/compile-fail/i128-feature.rs diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 443f4b2ea8e42..2cb2f81fcffb5 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -90,6 +90,7 @@ #![feature(staged_api)] #![feature(unboxed_closures)] #![feature(never_type)] +#![cfg_attr(not(stage0), feature(i128_type))] #![feature(prelude_import)] #[prelude_import] diff --git a/src/librustc_i128/lib.rs b/src/librustc_i128/lib.rs index 14604fc66ba86..5b50c2b493ab2 100644 --- a/src/librustc_i128/lib.rs +++ b/src/librustc_i128/lib.rs @@ -1,4 +1,5 @@ #![allow(non_camel_case_types)] +#![feature(i128_type)] #[cfg(stage0)] pub type i128 = i64; diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 53fa87b52250d..f27a5c80b9c99 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -61,6 +61,7 @@ use syntax::ast::{FnDecl, ForeignItem, ForeignItemKind, Generics}; use syntax::ast::{Item, ItemKind, ImplItem, ImplItemKind}; use syntax::ast::{Local, Mutability, Pat, PatKind, Path}; use syntax::ast::{QSelf, TraitItemKind, TraitRef, Ty, TyKind}; +use syntax::feature_gate::{emit_feature_err, GateIssue}; use syntax_pos::{Span, DUMMY_SP, MultiSpan}; use errors::DiagnosticBuilder; @@ -2309,8 +2310,20 @@ impl<'a> Resolver<'a> { PathResult::Module(..) | PathResult::Failed(..) if (ns == TypeNS || path.len() > 1) && self.primitive_type_table.primitive_types.contains_key(&path[0].name) => { + let prim = self.primitive_type_table.primitive_types[&path[0].name]; + match prim { + TyUint(UintTy::U128) | TyInt(IntTy::I128) => { + if !this.session.features.borrow().i128_type { + emit_feature_err(&this.session.parse_sess.span_diagnostic, + "i128_type", span, GateIssue::Language, + "128-bit type is unstable"); + + } + } + _ => {} + } PathResolution { - base_def: Def::PrimTy(self.primitive_type_table.primitive_types[&path[0].name]), + base_def: Def::PrimTy(prim), depth: path.len() - 1, } } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 7275fbd12036b..051a4200235ab 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1330,6 +1330,13 @@ pub fn check_enum_variants<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, } let repr_type_ty = ccx.tcx.enum_repr_type(Some(&hint)).to_ty(ccx.tcx); + if repr_type_ty == ccx.tcx.types.i128 || repr_type_ty == ccx.tcx.types.u128 { + if !ccx.tcx.sess.features.borrow().i128_type { + emit_feature_err(&ccx.tcx.sess.parse_sess.span_diagnostic, + "i128_type", sp, GateIssue::Language, "128-bit type is unstable"); + } + } + for v in vs { if let Some(e) = v.node.disr_expr { check_const_with_type(ccx, e, repr_type_ty, e.node_id); diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 625af803458b5..a3f2cd3a0cdb8 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -321,6 +321,9 @@ declare_features! ( // `extern "ptx-*" fn()` (active, abi_ptx, "1.15.0", None), + + // The `i128` type + (active, i128_type, "1.15.0", Some(35118)), ); declare_features! ( @@ -1215,6 +1218,18 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { gate_feature_post!(&self, loop_break_value, e.span, "`break` with a value is experimental"); } + ast::ExprKind::Lit(ref lit) => { + if let ast::LitKind::Int(_, ref ty) = lit.node { + match *ty { + ast::LitIntType::Signed(ast::IntTy::I128) | + ast::LitIntType::Unsigned(ast::UintTy::U128) => { + gate_feature_post!(&self, i128_type, e.span, + "128-bit integers are not stable"); + } + _ => {} + } + } + } _ => {} } visit::walk_expr(self, e); diff --git a/src/test/compile-fail/i128-feature-2.rs b/src/test/compile-fail/i128-feature-2.rs new file mode 100644 index 0000000000000..b450ba33fdf82 --- /dev/null +++ b/src/test/compile-fail/i128-feature-2.rs @@ -0,0 +1,20 @@ +fn test1() -> i128 { //~ ERROR 128-bit type is unstable + 0 +} + +fn test1_2() -> u128 { //~ ERROR 128-bit type is unstable + 0 +} + +fn test3() { + let x: i128 = 0; //~ ERROR 128-bit type is unstable +} + +fn test3_2() { + let x: u128 = 0; //~ ERROR 128-bit type is unstable +} + +#[repr(u128)] +enum A { //~ ERROR 128-bit type is unstable + A(u64) +} diff --git a/src/test/compile-fail/i128-feature.rs b/src/test/compile-fail/i128-feature.rs new file mode 100644 index 0000000000000..640cda1469d28 --- /dev/null +++ b/src/test/compile-fail/i128-feature.rs @@ -0,0 +1,8 @@ +fn test2() { + 0i128; //~ ERROR 128-bit integers are not stable +} + +fn test2_2() { + 0u128; //~ ERROR 128-bit integers are not stable +} + diff --git a/src/test/run-pass/i128.rs b/src/test/run-pass/i128.rs index 34a90aa4bc5de..85a3f00e946bf 100644 --- a/src/test/run-pass/i128.rs +++ b/src/test/run-pass/i128.rs @@ -1,3 +1,5 @@ +#![feature(i128_type)] + fn main() { let x: i128 = -1; assert_eq!(0, !x); diff --git a/src/test/run-pass/u128.rs b/src/test/run-pass/u128.rs index 0debc57a8a089..57e1ea282e03c 100644 --- a/src/test/run-pass/u128.rs +++ b/src/test/run-pass/u128.rs @@ -1,8 +1,15 @@ +#![feature(i128_type)] + fn main() { let x: u128 = 0xFFFF_FFFF_FFFF_FFFF__FFFF_FFFF_FFFF_FFFF; assert_eq!(0, !x); + assert_eq!(0, !x); let y: u128 = 0xFFFF_FFFF_FFFF_FFFF__FFFF_FFFF_FFFF_FFFE; assert_eq!(!1, y); + assert_eq!(x, y | 1); + assert_eq!(0xFAFF_0000_FF8F_0000__FFFF_0000_FFFF_FFFE, + y & + 0xFAFF_0000_FF8F_0000__FFFF_0000_FFFF_FFFF); let z: u128 = 0xABCD_EF; assert_eq!(z * z * z * z, 0x33EE_0E2A_54E2_59DA_A0E7_8E41); assert_eq!(z + z + z + z, 0x2AF3_7BC); @@ -13,6 +20,8 @@ fn main() { assert_eq!(0x1000_0000_0000_0000_0000_0000_0000_000, k - 0x234_5678_9ABC_DEFF_EDCB_A987_6543_210); assert_eq!(0x6EF5_DE4C_D3BC_2AAA_3BB4_CC5D_D6EE_8, k / 42); + assert_eq!(0, k % 42); + assert_eq!(15, z % 42); assert_eq!(0x91A2_B3C4_D5E6_F7, k >> 65); assert_eq!(0xFDB9_7530_ECA8_6420_0000_0000_0000_0000, k << 65); assert!(k > z);