Skip to content

Commit

Permalink
Feature gate the 128 bit types
Browse files Browse the repository at this point in the history
Dangling a carrot in front of a donkey.

This commit includes manual merge conflict resolution changes from a rebase by @est31.
  • Loading branch information
nagisa authored and est31 committed Dec 30, 2016
1 parent b526064 commit d4d5be1
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/libcore/lib.rs
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions src/librustc_i128/lib.rs
@@ -1,4 +1,5 @@
#![allow(non_camel_case_types)]
#![feature(i128_type)]

#[cfg(stage0)]
pub type i128 = i64;
Expand Down
15 changes: 14 additions & 1 deletion src/librustc_resolve/lib.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/librustc_typeck/check/mod.rs
Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions src/libsyntax/feature_gate.rs
Expand Up @@ -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! (
Expand Down Expand Up @@ -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);
Expand Down
20 changes: 20 additions & 0 deletions 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)
}
8 changes: 8 additions & 0 deletions 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
}

2 changes: 2 additions & 0 deletions src/test/run-pass/i128.rs
@@ -1,3 +1,5 @@
#![feature(i128_type)]

fn main() {
let x: i128 = -1;
assert_eq!(0, !x);
Expand Down
9 changes: 9 additions & 0 deletions 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);
Expand All @@ -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);
Expand Down

0 comments on commit d4d5be1

Please sign in to comment.