Skip to content

Commit 811c48f

Browse files
committed
For now, accept the i, u, is, and us suffixes, but warn when
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.
1 parent 362d713 commit 811c48f

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

src/libsyntax/feature_gate.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -588,11 +588,11 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
588588
match lit.node {
589589
ast::LitInt(_, ty) => {
590590
let msg = if let ast::SignedIntLit(ast::TyIs(true), _) = ty {
591-
Some("the `i` suffix on integers is deprecated; use `is` \
592-
or one of the fixed-sized suffixes")
591+
Some("the `i` and `is` suffixes on integers are deprecated; \
592+
use `isize` or one of the fixed-sized suffixes")
593593
} else if let ast::UnsignedIntLit(ast::TyUs(true)) = ty {
594-
Some("the `u` suffix on integers is deprecated; use `us` \
595-
or one of the fixed-sized suffixes")
594+
Some("the `u` and `us` suffixes on integers are deprecated; \
595+
use `usize` or one of the fixed-sized suffixes")
596596
} else {
597597
None
598598
};

src/libsyntax/parse/mod.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,8 @@ pub fn integer_lit(s: &str, suffix: Option<&str>, sd: &SpanHandler, sp: Span) ->
711711
"u16" => ast::UnsignedIntLit(ast::TyU16),
712712
"u32" => ast::UnsignedIntLit(ast::TyU32),
713713
"u64" => ast::UnsignedIntLit(ast::TyU64),
714+
"i" | "is" => ast::SignedIntLit(ast::TyIs(true), ast::Plus),
715+
"u" | "us" => ast::UnsignedIntLit(ast::TyUs(true)),
714716
_ => {
715717
// i<digits> and u<digits> look like widths, so lets
716718
// give an error message along those lines
@@ -720,17 +722,8 @@ pub fn integer_lit(s: &str, suffix: Option<&str>, sd: &SpanHandler, sp: Span) ->
720722
&suf[1..]));
721723
} else {
722724
sd.span_err(sp, &*format!("illegal suffix `{}` for numeric literal", suf));
723-
724-
if suf == "i" || suf == "is" {
725-
sd.span_help(sp, "per RFC 544/573, the suffix \
726-
for `isize` literals is now `isize`");
727-
} else if suf == "u" || suf == "us" {
728-
sd.span_help(sp, "per RFC 544/573, the suffix \
729-
for `usize` literals is now `usize`");
730-
} else {
731-
sd.span_help(sp, "the suffix must be one of the integral types \
732-
(`u32`, `isize`, etc)");
733-
}
725+
sd.span_help(sp, "the suffix must be one of the integral types \
726+
(`u32`, `isize`, etc)");
734727
}
735728

736729
ty

src/test/compile-fail/feature-gate-int-uint.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![allow(dead_code)]
11+
#![allow(dead_code, unused_variables)]
12+
#![feature(rustc_attrs)]
1213

1314
mod u {
1415
type X = uint; //~ WARN the `uint` type is deprecated
1516
struct Foo {
1617
x: uint //~ WARN the `uint` type is deprecated
1718
}
1819
fn bar(x: uint) { //~ WARN the `uint` type is deprecated
19-
1_usize;
20+
1_u; //~ WARN the `u` and `us` suffixes on integers are deprecated
21+
1_us; //~ WARN the `u` and `us` suffixes on integers are deprecated
2022
}
2123
}
2224
mod i {
@@ -25,11 +27,11 @@ mod i {
2527
x: int //~ WARN the `int` type is deprecated
2628
}
2729
fn bar(x: int) { //~ WARN the `int` type is deprecated
28-
1_isize;
30+
1_i; //~ WARN the `i` and `is` suffixes on integers are deprecated
31+
1_is; //~ WARN the `i` and `is` suffixes on integers are deprecated
2932
}
3033
}
3134

32-
fn main() {
33-
// make compilation fail, after feature gating
34-
let () = 1u8; //~ ERROR
35+
#[rustc_error]
36+
fn main() { //~ ERROR compilation successful
3537
}

0 commit comments

Comments
 (0)