Skip to content

Commit abff2e0

Browse files
committed
Feature gate the 128 bit types
Dangling a carrot in front of a donkey.
1 parent 1a87d8e commit abff2e0

File tree

9 files changed

+79
-6
lines changed

9 files changed

+79
-6
lines changed

src/libcore/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
#![feature(unboxed_closures)]
9292
#![feature(question_mark)]
9393
#![feature(never_type)]
94+
#![cfg_attr(not(stage0), feature(i128_type))]
9495
#![feature(prelude_import)]
9596

9697
#[prelude_import]

src/librustc_i128/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![allow(non_camel_case_types)]
2+
#![feature(i128_type)]
23

34
#[cfg(stage0)]
45
pub type i128 = i64;

src/librustc_resolve/lib.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ use syntax::ast::{self, FloatTy};
5757
use syntax::ast::{CRATE_NODE_ID, Name, NodeId, CrateNum, IntTy, UintTy};
5858
use syntax::parse::token::{self, keywords};
5959
use syntax::util::lev_distance::find_best_match_for_name;
60+
use syntax::feature_gate::{emit_feature_err, GateIssue};
6061

6162
use syntax::visit::{self, FnKind, Visitor};
6263
use syntax::ast::{Arm, BindingMode, Block, Crate, Expr, ExprKind};
@@ -2457,11 +2458,20 @@ impl<'a> Resolver<'a> {
24572458
let resolve_identifier_with_fallback = |this: &mut Self, record_used| {
24582459
let def = this.resolve_identifier(last_ident, namespace, record_used);
24592460
match def {
2460-
None | Some(LocalDef{def: Def::Mod(..), ..}) if namespace == TypeNS =>
2461-
this.primitive_type_table
2462-
.primitive_types
2463-
.get(&last_ident.name)
2464-
.map_or(def, |prim_ty| Some(LocalDef::from_def(Def::PrimTy(*prim_ty)))),
2461+
None | Some(LocalDef{def: Def::Mod(..), ..}) if namespace == TypeNS => {
2462+
let prim = this.primitive_type_table.primitive_types.get(&last_ident.name);
2463+
match prim {
2464+
Some(&TyUint(UintTy::U128)) | Some(&TyInt(IntTy::I128)) => {
2465+
if !this.session.features.borrow().i128_type {
2466+
emit_feature_err(&this.session.parse_sess.span_diagnostic,
2467+
"i128_type", span, GateIssue::Language,
2468+
"128-bit type is unstable");
2469+
}
2470+
}
2471+
_ => {}
2472+
}
2473+
prim.map_or(def, |prim_ty| Some(LocalDef::from_def(Def::PrimTy(*prim_ty))))
2474+
}
24652475
_ => def
24662476
}
24672477
};

src/librustc_typeck/check/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,13 @@ pub fn check_enum_variants<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
12621262
}
12631263

12641264
let repr_type_ty = ccx.tcx.enum_repr_type(Some(&hint)).to_ty(ccx.tcx);
1265+
if repr_type_ty == ccx.tcx.types.i128 || repr_type_ty == ccx.tcx.types.u128 {
1266+
if !ccx.tcx.sess.features.borrow().i128_type {
1267+
emit_feature_err(&ccx.tcx.sess.parse_sess.span_diagnostic,
1268+
"i128_type", sp, GateIssue::Language, "128-bit type is unstable");
1269+
}
1270+
}
1271+
12651272
for v in vs {
12661273
if let Some(ref e) = v.node.disr_expr {
12671274
check_const_with_type(ccx, e, repr_type_ty, e.id);

src/libsyntax/feature_gate.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,10 @@ declare_features! (
283283
(active, relaxed_adts, "1.12.0", Some(35626)),
284284

285285
// The `!` type
286-
(active, never_type, "1.13.0", Some(35121))
286+
(active, never_type, "1.13.0", Some(35121)),
287+
288+
// The `i128` type
289+
(active, i128_type, "1.13.0", Some(35118))
287290
);
288291

289292
declare_features! (
@@ -993,6 +996,18 @@ impl<'a> Visitor for PostExpansionVisitor<'a> {
993996
ast::ExprKind::InPlace(..) => {
994997
gate_feature_post!(&self, placement_in_syntax, e.span, EXPLAIN_PLACEMENT_IN);
995998
}
999+
ast::ExprKind::Lit(ref lit) => {
1000+
if let ast::LitKind::Int(_, ref ty) = lit.node {
1001+
match *ty {
1002+
ast::LitIntType::Signed(ast::IntTy::I128) |
1003+
ast::LitIntType::Unsigned(ast::UintTy::U128) => {
1004+
gate_feature_post!(&self, i128_type, e.span,
1005+
"128-bit integers are not stable");
1006+
}
1007+
_ => {}
1008+
}
1009+
}
1010+
}
9961011
_ => {}
9971012
}
9981013
visit::walk_expr(self, e);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
fn test1() -> i128 { //~ ERROR 128-bit type is unstable
2+
0
3+
}
4+
5+
fn test1_2() -> u128 { //~ ERROR 128-bit type is unstable
6+
0
7+
}
8+
9+
fn test3() {
10+
let x: i128 = 0; //~ ERROR 128-bit type is unstable
11+
}
12+
13+
fn test3_2() {
14+
let x: u128 = 0; //~ ERROR 128-bit type is unstable
15+
}
16+
17+
#[repr(u128)]
18+
enum A { //~ ERROR 128-bit type is unstable
19+
A(u64)
20+
}

src/test/compile-fail/i128-feature.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn test2() {
2+
0i128; //~ ERROR 128-bit integers are not stable
3+
}
4+
5+
fn test2_2() {
6+
0u128; //~ ERROR 128-bit integers are not stable
7+
}
8+

src/test/run-pass/i128.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![feature(i128_type)]
2+
13
fn main() {
24
let x: i128 = -1;
35
assert_eq!(0, !x);

src/test/run-pass/u128.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1+
#![feature(i128_type)]
2+
13
fn main() {
24
let x: u128 = 0xFFFF_FFFF_FFFF_FFFF__FFFF_FFFF_FFFF_FFFF;
35
assert_eq!(0, !x);
6+
assert_eq!(0, !x);
47
let y: u128 = 0xFFFF_FFFF_FFFF_FFFF__FFFF_FFFF_FFFF_FFFE;
58
assert_eq!(!1, y);
9+
assert_eq!(x, y | 1);
10+
assert_eq!(0xFAFF_0000_FF8F_0000__FFFF_0000_FFFF_FFFE,
11+
y &
12+
0xFAFF_0000_FF8F_0000__FFFF_0000_FFFF_FFFF);
613
let z: u128 = 0xABCD_EF;
714
assert_eq!(z * z * z * z, 0x33EE_0E2A_54E2_59DA_A0E7_8E41);
815
assert_eq!(z + z + z + z, 0x2AF3_7BC);
@@ -13,6 +20,8 @@ fn main() {
1320
assert_eq!(0x1000_0000_0000_0000_0000_0000_0000_000,
1421
k - 0x234_5678_9ABC_DEFF_EDCB_A987_6543_210);
1522
assert_eq!(0x6EF5_DE4C_D3BC_2AAA_3BB4_CC5D_D6EE_8, k / 42);
23+
assert_eq!(0, k % 42);
24+
assert_eq!(15, z % 42);
1625
assert_eq!(0x91A2_B3C4_D5E6_F7, k >> 65);
1726
assert_eq!(0xFDB9_7530_ECA8_6420_0000_0000_0000_0000, k << 65);
1827
assert!(k > z);

0 commit comments

Comments
 (0)