File tree 6 files changed +59
-28
lines changed
6 files changed +59
-28
lines changed Original file line number Diff line number Diff line change @@ -341,10 +341,8 @@ pub fn ty_to_str(cx: &ctxt, typ: t) -> ~str {
341
341
ty_bot => ~"!",
342
342
ty_bool => ~"bool",
343
343
ty_char => ~"char",
344
- ty_int( ast:: TyI ) => ~"int",
345
- ty_int( t) => ast_util:: int_ty_to_str ( t) ,
346
- ty_uint( ast:: TyU ) => ~"uint",
347
- ty_uint( t) => ast_util:: uint_ty_to_str ( t) ,
344
+ ty_int( t) => ast_util:: int_ty_to_str ( t, None ) ,
345
+ ty_uint( t) => ast_util:: uint_ty_to_str ( t, None ) ,
348
346
ty_float( t) => ast_util:: float_ty_to_str ( t) ,
349
347
ty_box( typ) => ~"@" + ty_to_str ( cx, typ) ,
350
348
ty_uniq( typ) => ~"~" + ty_to_str ( cx, typ) ,
Original file line number Diff line number Diff line change @@ -707,7 +707,7 @@ pub enum IntTy {
707
707
708
708
impl fmt:: Show for IntTy {
709
709
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
710
- write ! ( f. buf, "{}" , ast_util:: int_ty_to_str( * self ) )
710
+ write ! ( f. buf, "{}" , ast_util:: int_ty_to_str( * self , None ) )
711
711
}
712
712
}
713
713
@@ -722,7 +722,7 @@ pub enum UintTy {
722
722
723
723
impl fmt:: Show for UintTy {
724
724
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
725
- write ! ( f. buf, "{}" , ast_util:: uint_ty_to_str( * self ) )
725
+ write ! ( f. buf, "{}" , ast_util:: uint_ty_to_str( * self , None ) )
726
726
}
727
727
}
728
728
Original file line number Diff line number Diff line change @@ -132,13 +132,21 @@ pub fn is_path(e: @Expr) -> bool {
132
132
return match e. node { ExprPath ( _) => true , _ => false } ;
133
133
}
134
134
135
- pub fn int_ty_to_str ( t : IntTy ) -> ~str {
136
- match t {
137
- TyI => ~"",
138
- TyI8 => ~"i8",
139
- TyI16 => ~"i16",
140
- TyI32 => ~"i32",
141
- TyI64 => ~"i64"
135
+ // Get a string representation of a signed int type, with its value.
136
+ // We want to avoid "45int" and "-3int" in favor of "45" and "-3"
137
+ pub fn int_ty_to_str ( t : IntTy , val : Option < i64 > ) -> ~str {
138
+ let s = match t {
139
+ TyI if val. is_some ( ) => "" ,
140
+ TyI => "int" ,
141
+ TyI8 => "i8" ,
142
+ TyI16 => "i16" ,
143
+ TyI32 => "i32" ,
144
+ TyI64 => "i64"
145
+ } ;
146
+
147
+ match val {
148
+ Some ( n) => format ! ( "{}{}" , n, s) ,
149
+ None => s. to_owned ( )
142
150
}
143
151
}
144
152
@@ -151,13 +159,21 @@ pub fn int_ty_max(t: IntTy) -> u64 {
151
159
}
152
160
}
153
161
154
- pub fn uint_ty_to_str ( t : UintTy ) -> ~str {
155
- match t {
156
- TyU => ~"u",
157
- TyU8 => ~"u8",
158
- TyU16 => ~"u16",
159
- TyU32 => ~"u32",
160
- TyU64 => ~"u64"
162
+ // Get a string representation of an unsigned int type, with its value.
163
+ // We want to avoid "42uint" in favor of "42u"
164
+ pub fn uint_ty_to_str ( t : UintTy , val : Option < u64 > ) -> ~str {
165
+ let s = match t {
166
+ TyU if val. is_some ( ) => "u" ,
167
+ TyU => "uint" ,
168
+ TyU8 => "u8" ,
169
+ TyU16 => "u16" ,
170
+ TyU32 => "u32" ,
171
+ TyU64 => "u64"
172
+ } ;
173
+
174
+ match val {
175
+ Some ( n) => format ! ( "{}{}" , n, s) ,
176
+ None => s. to_owned ( )
161
177
}
162
178
}
163
179
Original file line number Diff line number Diff line change @@ -201,12 +201,8 @@ pub fn to_str(t: &Token) -> ~str {
201
201
res. push_char ( '\'' ) ;
202
202
res. into_owned ( )
203
203
}
204
- LIT_INT ( i, t) => {
205
- i. to_str ( ) + ast_util:: int_ty_to_str ( t)
206
- }
207
- LIT_UINT ( u, t) => {
208
- u. to_str ( ) + ast_util:: uint_ty_to_str ( t)
209
- }
204
+ LIT_INT ( i, t) => ast_util:: int_ty_to_str ( t, Some ( i) ) ,
205
+ LIT_UINT ( u, t) => ast_util:: uint_ty_to_str ( t, Some ( u) ) ,
210
206
LIT_INT_UNSUFFIXED ( i) => { i. to_str ( ) }
211
207
LIT_FLOAT ( s, t) => {
212
208
let mut body = StrBuf :: from_str ( get_ident ( s) . get ( ) ) ;
Original file line number Diff line number Diff line change @@ -2171,10 +2171,10 @@ impl<'a> State<'a> {
2171
2171
word ( & mut self . s , res. into_owned ( ) )
2172
2172
}
2173
2173
ast:: LitInt ( i, t) => {
2174
- word ( & mut self . s , format ! ( "{}{}" , i , ast_util:: int_ty_to_str( t) ) )
2174
+ word ( & mut self . s , ast_util:: int_ty_to_str ( t, Some ( i ) ) )
2175
2175
}
2176
2176
ast:: LitUint ( u, t) => {
2177
- word ( & mut self . s , format ! ( "{}{}" , u , ast_util:: uint_ty_to_str( t) ) )
2177
+ word ( & mut self . s , ast_util:: uint_ty_to_str ( t, Some ( u ) ) )
2178
2178
}
2179
2179
ast:: LitIntUnsuffixed ( i) => {
2180
2180
word ( & mut self . s , format ! ( "{}" , i) )
Original file line number Diff line number Diff line change
1
+ // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2
+ // file at the top-level directory of this distribution and at
3
+ // http://rust-lang.org/COPYRIGHT.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6
+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7
+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8
+ // option. This file may not be copied, modified, or distributed
9
+ // except according to those terms.
10
+
11
+ fn foo ( _s : i16 ) { }
12
+
13
+ fn bar ( _s : u32 ) { }
14
+
15
+ fn main ( ) {
16
+ foo ( 1 * ( 1 as int ) ) ;
17
+ //~^ ERROR: mismatched types: expected `i16` but found `int` (expected `i16` but found `int`)
18
+
19
+ bar ( 1 * ( 1 as uint ) ) ;
20
+ //~^ ERROR: mismatched types: expected `u32` but found `uint` (expected `u32` but found `uint`)
21
+ }
You can’t perform that action at this time.
0 commit comments