about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-01-08 09:24:08 -0800
committerAlex Crichton <alex@alexcrichton.com>2015-01-08 09:24:08 -0800
commit4281bd1932bf185e1154f7a79832bbd2d9155e41 (patch)
tree27263299612651b57cb595a2cebf4830dc113904 /src/libsyntax
parent8ed88c11af9495e7119da4ac59f329a33cedac59 (diff)
parenta661bd6575dd3fac17cf77fdea8b76ca790ac212 (diff)
downloadrust-4281bd1932bf185e1154f7a79832bbd2d9155e41.tar.gz
rust-4281bd1932bf185e1154f7a79832bbd2d9155e41.zip
rollup merge of #20754: nikomatsakis/int-feature
Conflicts:
	src/test/compile-fail/borrowck-move-out-of-overloaded-auto-deref.rs
	src/test/compile-fail/issue-2590.rs
	src/test/compile-fail/lint-stability.rs
	src/test/compile-fail/slice-mut-2.rs
	src/test/compile-fail/std-uncopyable-atomics.rs
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast.rs44
-rw-r--r--src/libsyntax/ast_util.rs16
-rw-r--r--src/libsyntax/attr.rs10
-rw-r--r--src/libsyntax/ext/build.rs5
-rw-r--r--src/libsyntax/ext/deriving/generic/mod.rs2
-rw-r--r--src/libsyntax/ext/deriving/rand.rs6
-rw-r--r--src/libsyntax/ext/quote.rs28
-rw-r--r--src/libsyntax/feature_gate.rs55
-rw-r--r--src/libsyntax/lib.rs1
-rw-r--r--src/libsyntax/parse/mod.rs8
10 files changed, 132 insertions, 43 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index 0a9e0aedd3d..630f7768885 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -1075,15 +1075,29 @@ pub struct Typedef {
     pub typ: P<Ty>,
 }
 
-#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
+#[derive(Clone, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
 pub enum IntTy {
-    TyIs,
+    TyIs(bool /* is this deprecated `int`? */),
     TyI8,
     TyI16,
     TyI32,
     TyI64,
 }
 
+impl PartialEq for IntTy {
+    fn eq(&self, other: &IntTy) -> bool {
+        match (*self, *other) {
+            // true/false need to compare the same, so this can't be derived
+            (TyIs(_), TyIs(_)) |
+            (TyI8, TyI8) |
+            (TyI16, TyI16) |
+            (TyI32, TyI32) |
+            (TyI64, TyI64) => true,
+            _ => false
+        }
+    }
+}
+
 impl fmt::Show for IntTy {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         fmt::String::fmt(self, f)
@@ -1099,27 +1113,41 @@ impl fmt::String for IntTy {
 impl IntTy {
     pub fn suffix_len(&self) -> uint {
         match *self {
-            TyIs => 1,
-            TyI8 => 2,
+            TyIs(true) /* i */ => 1,
+            TyIs(false) /* is */ | TyI8 => 2,
             TyI16 | TyI32 | TyI64  => 3,
         }
     }
 }
 
-#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
+#[derive(Clone, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
 pub enum UintTy {
-    TyUs,
+    TyUs(bool /* is this deprecated uint? */),
     TyU8,
     TyU16,
     TyU32,
     TyU64,
 }
 
+impl PartialEq for UintTy {
+    fn eq(&self, other: &UintTy) -> bool {
+        match (*self, *other) {
+            // true/false need to compare the same, so this can't be derived
+            (TyUs(_), TyUs(_)) |
+            (TyU8, TyU8) |
+            (TyU16, TyU16) |
+            (TyU32, TyU32) |
+            (TyU64, TyU64) => true,
+            _ => false
+        }
+    }
+}
+
 impl UintTy {
     pub fn suffix_len(&self) -> uint {
         match *self {
-            TyUs => 1,
-            TyU8 => 2,
+            TyUs(true) /* u */ => 1,
+            TyUs(false) /* us */ | TyU8 => 2,
             TyU16 | TyU32 | TyU64  => 3,
         }
     }
diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs
index b4e917e28cb..bc7fbd46fd8 100644
--- a/src/libsyntax/ast_util.rs
+++ b/src/libsyntax/ast_util.rs
@@ -127,8 +127,10 @@ pub fn is_path(e: P<Expr>) -> bool {
 /// We want to avoid "45int" and "-3int" in favor of "45" and "-3"
 pub fn int_ty_to_string(t: IntTy, val: Option<i64>) -> String {
     let s = match t {
-        TyIs if val.is_some() => "is",
-        TyIs => "isize",
+        TyIs(true) if val.is_some() => "i",
+        TyIs(true) => "int",
+        TyIs(false) if val.is_some() => "is",
+        TyIs(false) => "isize",
         TyI8 => "i8",
         TyI16 => "i16",
         TyI32 => "i32",
@@ -148,7 +150,7 @@ pub fn int_ty_max(t: IntTy) -> u64 {
     match t {
         TyI8 => 0x80u64,
         TyI16 => 0x8000u64,
-        TyIs | TyI32 => 0x80000000u64, // actually ni about TyIs
+        TyIs(_) | TyI32 => 0x80000000u64, // actually ni about TyIs
         TyI64 => 0x8000000000000000u64
     }
 }
@@ -157,8 +159,10 @@ pub fn int_ty_max(t: IntTy) -> u64 {
 /// We want to avoid "42uint" in favor of "42u"
 pub fn uint_ty_to_string(t: UintTy, val: Option<u64>) -> String {
     let s = match t {
-        TyUs if val.is_some() => "us",
-        TyUs => "usize",
+        TyUs(true) if val.is_some() => "u",
+        TyUs(true) => "uint",
+        TyUs(false) if val.is_some() => "us",
+        TyUs(false) => "usize",
         TyU8 => "u8",
         TyU16 => "u16",
         TyU32 => "u32",
@@ -175,7 +179,7 @@ pub fn uint_ty_max(t: UintTy) -> u64 {
     match t {
         TyU8 => 0xffu64,
         TyU16 => 0xffffu64,
-        TyUs | TyU32 => 0xffffffffu64, // actually ni about TyUs
+        TyUs(_) | TyU32 => 0xffffffffu64, // actually ni about TyUs
         TyU64 => 0xffffffffffffffffu64
     }
 }
diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs
index 2cea55dfc55..6f57c06d33e 100644
--- a/src/libsyntax/attr.rs
+++ b/src/libsyntax/attr.rs
@@ -464,10 +464,10 @@ fn int_type_of_word(s: &str) -> Option<IntType> {
         "u32" => Some(UnsignedInt(ast::TyU32)),
         "i64" => Some(SignedInt(ast::TyI64)),
         "u64" => Some(UnsignedInt(ast::TyU64)),
-        "int" => Some(SignedInt(ast::TyIs)),
-        "uint" => Some(UnsignedInt(ast::TyUs)),
-        "isize" => Some(SignedInt(ast::TyIs)),
-        "usize" => Some(UnsignedInt(ast::TyUs)),
+        "int" => Some(SignedInt(ast::TyIs(true))),
+        "uint" => Some(UnsignedInt(ast::TyUs(true))),
+        "isize" => Some(SignedInt(ast::TyIs(false))),
+        "usize" => Some(UnsignedInt(ast::TyUs(false))),
         _ => None
     }
 }
@@ -511,7 +511,7 @@ impl IntType {
             SignedInt(ast::TyI16) | UnsignedInt(ast::TyU16) |
             SignedInt(ast::TyI32) | UnsignedInt(ast::TyU32) |
             SignedInt(ast::TyI64) | UnsignedInt(ast::TyU64) => true,
-            SignedInt(ast::TyIs) | UnsignedInt(ast::TyUs) => false
+            SignedInt(ast::TyIs(_)) | UnsignedInt(ast::TyUs(_)) => false
         }
     }
 }
diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs
index 27523ea4535..c34142aec39 100644
--- a/src/libsyntax/ext/build.rs
+++ b/src/libsyntax/ext/build.rs
@@ -642,10 +642,11 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
         self.expr(sp, ast::ExprLit(P(respan(sp, lit))))
     }
     fn expr_uint(&self, span: Span, i: uint) -> P<ast::Expr> {
-        self.expr_lit(span, ast::LitInt(i as u64, ast::UnsignedIntLit(ast::TyUs)))
+        self.expr_lit(span, ast::LitInt(i as u64, ast::UnsignedIntLit(ast::TyUs(false))))
     }
     fn expr_int(&self, sp: Span, i: int) -> P<ast::Expr> {
-        self.expr_lit(sp, ast::LitInt(i as u64, ast::SignedIntLit(ast::TyIs, ast::Sign::new(i))))
+        self.expr_lit(sp, ast::LitInt(i as u64, ast::SignedIntLit(ast::TyIs(false),
+                                                                  ast::Sign::new(i))))
     }
     fn expr_u8(&self, sp: Span, u: u8) -> P<ast::Expr> {
         self.expr_lit(sp, ast::LitInt(u as u64, ast::UnsignedIntLit(ast::TyU8)))
diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs
index 47b29a4db3e..e6b6f7bbd49 100644
--- a/src/libsyntax/ext/deriving/generic/mod.rs
+++ b/src/libsyntax/ext/deriving/generic/mod.rs
@@ -1031,7 +1031,7 @@ impl<'a> MethodDef<'a> {
             let arms: Vec<ast::Arm> = variants.iter().enumerate()
                 .map(|(index, variant)| {
                     let pat = variant_to_pat(cx, sp, type_ident, &**variant);
-                    let lit = ast::LitInt(index as u64, ast::UnsignedIntLit(ast::TyUs));
+                    let lit = ast::LitInt(index as u64, ast::UnsignedIntLit(ast::TyUs(false)));
                     cx.arm(sp, vec![pat], cx.expr_lit(sp, lit))
                 }).collect();
 
diff --git a/src/libsyntax/ext/deriving/rand.rs b/src/libsyntax/ext/deriving/rand.rs
index 5517019f804..1359cada673 100644
--- a/src/libsyntax/ext/deriving/rand.rs
+++ b/src/libsyntax/ext/deriving/rand.rs
@@ -98,13 +98,13 @@ fn rand_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure)
                                        rand_name,
                                        vec!(rng.clone()));
 
-            // need to specify the uint-ness of the random number
-            let uint_ty = cx.ty_ident(trait_span, cx.ident_of("uint"));
+            // need to specify the usize-ness of the random number
+            let usize_ty = cx.ty_ident(trait_span, cx.ident_of("usize"));
             let value_ident = cx.ident_of("__value");
             let let_statement = cx.stmt_let_typed(trait_span,
                                                   false,
                                                   value_ident,
-                                                  uint_ty,
+                                                  usize_ty,
                                                   rv_call);
 
             // rand() % variants.len()
diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs
index 2dbf29c145c..c42b188302c 100644
--- a/src/libsyntax/ext/quote.rs
+++ b/src/libsyntax/ext/quote.rs
@@ -244,10 +244,10 @@ pub mod rt {
     }
 
     macro_rules! impl_to_source_int {
-        (signed, $t:ty, $tag:ident) => (
+        (signed, $t:ty, $tag:expr) => (
             impl ToSource for $t {
                 fn to_source(&self) -> String {
-                    let lit = ast::LitInt(*self as u64, ast::SignedIntLit(ast::$tag,
+                    let lit = ast::LitInt(*self as u64, ast::SignedIntLit($tag,
                                                                           ast::Sign::new(*self)));
                     pprust::lit_to_string(&dummy_spanned(lit))
                 }
@@ -258,10 +258,10 @@ pub mod rt {
                 }
             }
         );
-        (unsigned, $t:ty, $tag:ident) => (
+        (unsigned, $t:ty, $tag:expr) => (
             impl ToSource for $t {
                 fn to_source(&self) -> String {
-                    let lit = ast::LitInt(*self as u64, ast::UnsignedIntLit(ast::$tag));
+                    let lit = ast::LitInt(*self as u64, ast::UnsignedIntLit($tag));
                     pprust::lit_to_string(&dummy_spanned(lit))
                 }
             }
@@ -273,17 +273,17 @@ pub mod rt {
         );
     }
 
-    impl_to_source_int! { signed, int, TyIs }
-    impl_to_source_int! { signed, i8,  TyI8 }
-    impl_to_source_int! { signed, i16, TyI16 }
-    impl_to_source_int! { signed, i32, TyI32 }
-    impl_to_source_int! { signed, i64, TyI64 }
+    impl_to_source_int! { signed, int, ast::TyIs(false) }
+    impl_to_source_int! { signed, i8,  ast::TyI8 }
+    impl_to_source_int! { signed, i16, ast::TyI16 }
+    impl_to_source_int! { signed, i32, ast::TyI32 }
+    impl_to_source_int! { signed, i64, ast::TyI64 }
 
-    impl_to_source_int! { unsigned, uint, TyUs }
-    impl_to_source_int! { unsigned, u8,   TyU8 }
-    impl_to_source_int! { unsigned, u16,  TyU16 }
-    impl_to_source_int! { unsigned, u32,  TyU32 }
-    impl_to_source_int! { unsigned, u64,  TyU64 }
+    impl_to_source_int! { unsigned, uint, ast::TyUs(false) }
+    impl_to_source_int! { unsigned, u8,   ast::TyU8 }
+    impl_to_source_int! { unsigned, u16,  ast::TyU16 }
+    impl_to_source_int! { unsigned, u32,  ast::TyU32 }
+    impl_to_source_int! { unsigned, u64,  ast::TyU64 }
 
     // Alas ... we write these out instead. All redundant.
 
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs
index 9f023be4a53..8175c0a9eec 100644
--- a/src/libsyntax/feature_gate.rs
+++ b/src/libsyntax/feature_gate.rs
@@ -93,6 +93,9 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[
     // OIBIT specific features
     ("optin_builtin_traits", Active),
 
+    // int and uint are now deprecated
+    ("int_uint", Active),
+
     // These are used to test this portion of the compiler, they don't actually
     // mean anything
     ("test_accepted_feature", Accepted),
@@ -155,6 +158,14 @@ impl<'a> Context<'a> {
         }
     }
 
+    fn warn_feature(&self, feature: &str, span: Span, explain: &str) {
+        if !self.has_feature(feature) {
+            self.span_handler.span_warn(span, explain);
+            self.span_handler.span_help(span, &format!("add #![feature({})] to the \
+                                                       crate attributes to silence this warning",
+                                                      feature)[]);
+        }
+    }
     fn has_feature(&self, feature: &str) -> bool {
         self.features.iter().any(|&n| n == feature)
     }
@@ -332,6 +343,31 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
     }
 
     fn visit_ty(&mut self, t: &ast::Ty) {
+        match t.node {
+            ast::TyPath(ref p, _) => {
+                match &*p.segments {
+
+                    [ast::PathSegment { identifier, .. }] => {
+                        let name = token::get_ident(identifier);
+                        let msg = if name == "int" {
+                            Some("the `int` type is deprecated; \
+                                  use `isize` or a fixed-sized integer")
+                        } else if name == "uint" {
+                            Some("the `uint` type is deprecated; \
+                                  use `usize` or a fixed-sized integer")
+                        } else {
+                            None
+                        };
+
+                        if let Some(msg) = msg {
+                            self.context.warn_feature("int_uint", t.span, msg)
+                        }
+                    }
+                    _ => {}
+                }
+            }
+            _ => {}
+        }
         visit::walk_ty(self, t);
     }
 
@@ -343,6 +379,25 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
                                   "box expression syntax is experimental in alpha release; \
                                    you can call `Box::new` instead.");
             }
+            ast::ExprLit(ref lit) => {
+                match lit.node {
+                    ast::LitInt(_, ty) => {
+                        let msg = if let ast::SignedIntLit(ast::TyIs(true), _) = ty {
+                            Some("the `i` suffix on integers is deprecated; use `is` \
+                                  or one of the fixed-sized suffixes")
+                        } else if let ast::UnsignedIntLit(ast::TyUs(true)) = ty {
+                            Some("the `u` suffix on integers is deprecated; use `us` \
+                                 or one of the fixed-sized suffixes")
+                        } else {
+                            None
+                        };
+                        if let Some(msg) = msg {
+                            self.context.warn_feature("int_uint", e.span, msg);
+                        }
+                    }
+                    _ => {}
+                }
+            }
             _ => {}
         }
         visit::walk_expr(self, e);
diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs
index eb6a2a43d43..9c947f422e9 100644
--- a/src/libsyntax/lib.rs
+++ b/src/libsyntax/lib.rs
@@ -27,6 +27,7 @@
 #![feature(slicing_syntax)]
 #![feature(box_syntax)]
 #![feature(quote, unsafe_destructor)]
+#![allow(unknown_features)] #![feature(int_uint)]
 
 extern crate arena;
 extern crate fmt_macros;
diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs
index c42a6beea2d..f1f547ba0c7 100644
--- a/src/libsyntax/parse/mod.rs
+++ b/src/libsyntax/parse/mod.rs
@@ -702,14 +702,14 @@ pub fn integer_lit(s: &str, suffix: Option<&str>, sd: &SpanHandler, sp: Span) ->
     if let Some(suf) = suffix {
         if suf.is_empty() { sd.span_bug(sp, "found empty literal suffix in Some")}
         ty = match suf {
-            "i"   => ast::SignedIntLit(ast::TyIs, ast::Plus),
-            "is"   => ast::SignedIntLit(ast::TyIs, ast::Plus),
+            "i"   => ast::SignedIntLit(ast::TyIs(true), ast::Plus),
+            "is"   => ast::SignedIntLit(ast::TyIs(false), ast::Plus),
             "i8"  => ast::SignedIntLit(ast::TyI8, ast::Plus),
             "i16" => ast::SignedIntLit(ast::TyI16, ast::Plus),
             "i32" => ast::SignedIntLit(ast::TyI32, ast::Plus),
             "i64" => ast::SignedIntLit(ast::TyI64, ast::Plus),
-            "u"   => ast::UnsignedIntLit(ast::TyUs),
-            "us"   => ast::UnsignedIntLit(ast::TyUs),
+            "u"   => ast::UnsignedIntLit(ast::TyUs(true)),
+            "us"   => ast::UnsignedIntLit(ast::TyUs(false)),
             "u8"  => ast::UnsignedIntLit(ast::TyU8),
             "u16" => ast::UnsignedIntLit(ast::TyU16),
             "u32" => ast::UnsignedIntLit(ast::TyU32),