]> git.lizzy.rs Git - rust.git/commitdiff
For now, accept the `i`, `u`, `is`, and `us` suffixes, but warn when
authorNiko Matsakis <niko@alum.mit.edu>
Wed, 18 Feb 2015 19:13:38 +0000 (14:13 -0500)
committerNiko Matsakis <niko@alum.mit.edu>
Wed, 18 Feb 2015 20:08:40 +0000 (15:08 -0500)
they are used without a feature-gate. This is both kinder to existing
code and should make it easier to land this PR, since we don't
have to catch EVERY SINGLE SUFFIX.

src/libsyntax/feature_gate.rs
src/libsyntax/parse/mod.rs
src/test/compile-fail/feature-gate-int-uint.rs

index 3bebba15a572b2e307231dd6c1a48cfade2e8ddb..0110823ae98c1df2ffa9fc69437d55e09d7cd88d 100644 (file)
@@ -588,11 +588,11 @@ fn visit_expr(&mut self, e: &ast::Expr) {
                 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")
+                            Some("the `i` and `is` suffixes on integers are deprecated; \
+                                  use `isize` 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")
+                            Some("the `u` and `us` suffixes on integers are deprecated; \
+                                  use `usize` or one of the fixed-sized suffixes")
                         } else {
                             None
                         };
index e3bed496647cf04cd65009cce41c0286141acd5c..6ea23cf3f04a5791410a1cc54fdcfa8dd90c84ce 100644 (file)
@@ -711,6 +711,8 @@ pub fn integer_lit(s: &str, suffix: Option<&str>, sd: &SpanHandler, sp: Span) ->
             "u16" => ast::UnsignedIntLit(ast::TyU16),
             "u32" => ast::UnsignedIntLit(ast::TyU32),
             "u64" => ast::UnsignedIntLit(ast::TyU64),
+            "i" | "is" => ast::SignedIntLit(ast::TyIs(true), ast::Plus),
+            "u" | "us" => ast::UnsignedIntLit(ast::TyUs(true)),
             _ => {
                 // i<digits> and u<digits> look like widths, so lets
                 // give an error message along those lines
@@ -720,17 +722,8 @@ pub fn integer_lit(s: &str, suffix: Option<&str>, sd: &SpanHandler, sp: Span) ->
                                               &suf[1..]));
                 } else {
                     sd.span_err(sp, &*format!("illegal suffix `{}` for numeric literal", suf));
-
-                    if suf == "i" || suf == "is" {
-                        sd.span_help(sp, "per RFC 544/573, the suffix \
-                                          for `isize` literals is now `isize`");
-                    } else if suf == "u" || suf == "us" {
-                        sd.span_help(sp, "per RFC 544/573, the suffix \
-                                          for `usize` literals is now `usize`");
-                    } else {
-                        sd.span_help(sp, "the suffix must be one of the integral types \
-                                          (`u32`, `isize`, etc)");
-                    }
+                    sd.span_help(sp, "the suffix must be one of the integral types \
+                                      (`u32`, `isize`, etc)");
                 }
 
                 ty
index 344afa3479932fb2bfc34d88fbcb1c35b6bf0857..948e485ccf5148effb18b51c60ee5f2f08f2c3dc 100644 (file)
@@ -8,7 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![allow(dead_code)]
+#![allow(dead_code, unused_variables)]
+#![feature(rustc_attrs)]
 
 mod u {
     type X = uint; //~ WARN the `uint` type is deprecated
@@ -16,7 +17,8 @@ struct Foo {
         x: uint //~ WARN the `uint` type is deprecated
     }
     fn bar(x: uint) { //~ WARN the `uint` type is deprecated
-        1_usize;
+        1_u; //~ WARN the `u` and `us` suffixes on integers are deprecated
+        1_us; //~ WARN the `u` and `us` suffixes on integers are deprecated
     }
 }
 mod i {
@@ -25,11 +27,11 @@ struct Foo {
         x: int //~ WARN the `int` type is deprecated
     }
     fn bar(x: int) { //~ WARN the `int` type is deprecated
-        1_isize;
+        1_i; //~ WARN the `i` and `is` suffixes on integers are deprecated
+        1_is; //~ WARN the `i` and `is` suffixes on integers are deprecated
     }
 }
 
-fn main() {
-    // make compilation fail, after feature gating
-    let () = 1u8; //~ ERROR
+#[rustc_error]
+fn main() { //~ ERROR compilation successful
 }