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.
This commit is contained in:
parent
b5260644af
commit
d4d5be18b7
9 changed files with 77 additions and 1 deletions
|
@ -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]
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#![allow(non_camel_case_types)]
|
||||
#![feature(i128_type)]
|
||||
|
||||
#[cfg(stage0)]
|
||||
pub type i128 = i64;
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
20
src/test/compile-fail/i128-feature-2.rs
Normal file
20
src/test/compile-fail/i128-feature-2.rs
Normal file
|
@ -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
src/test/compile-fail/i128-feature.rs
Normal file
8
src/test/compile-fail/i128-feature.rs
Normal file
|
@ -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
|
||||
}
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
#![feature(i128_type)]
|
||||
|
||||
fn main() {
|
||||
let x: i128 = -1;
|
||||
assert_eq!(0, !x);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue