about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libcore/lib.rs1
-rw-r--r--src/librustc_i128/lib.rs1
-rw-r--r--src/librustc_resolve/lib.rs15
-rw-r--r--src/librustc_typeck/check/mod.rs7
-rw-r--r--src/libsyntax/feature_gate.rs15
-rw-r--r--src/test/compile-fail/i128-feature-2.rs20
-rw-r--r--src/test/compile-fail/i128-feature.rs8
-rw-r--r--src/test/run-pass/i128.rs2
-rw-r--r--src/test/run-pass/u128.rs9
9 files changed, 77 insertions, 1 deletions
diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs
index 443f4b2ea8e..2cb2f81fcff 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 14604fc66ba..5b50c2b493a 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 53fa87b5225..f27a5c80b9c 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 7275fbd1203..051a4200235 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 625af803458..a3f2cd3a0cd 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 00000000000..b450ba33fdf
--- /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 00000000000..640cda1469d
--- /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 34a90aa4bc5..85a3f00e946 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 0debc57a8a0..57e1ea282e0 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);