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 @@ -367,10 +367,8 @@ pub fn ty_to_str(cx: &ctxt, typ: t) -> ~str {
367
367
ty_bot => ~"!",
368
368
ty_bool => ~"bool",
369
369
ty_char => ~"char",
370
- ty_int( ast:: TyI ) => ~"int",
371
- ty_int( t) => ast_util:: int_ty_to_str ( t) ,
372
- ty_uint( ast:: TyU ) => ~"uint",
373
- ty_uint( t) => ast_util:: uint_ty_to_str ( t) ,
370
+ ty_int( t) => ast_util:: int_ty_to_str ( t, None ) ,
371
+ ty_uint( t) => ast_util:: uint_ty_to_str ( t, None ) ,
374
372
ty_float( t) => ast_util:: float_ty_to_str ( t) ,
375
373
ty_box( typ) => ~"@" + ty_to_str ( cx, typ) ,
376
374
ty_uniq( typ) => ~"~" + ty_to_str ( cx, typ) ,
Original file line number Diff line number Diff line change @@ -724,7 +724,7 @@ pub enum IntTy {
724
724
725
725
impl fmt:: Show for IntTy {
726
726
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
727
- write ! ( f. buf, "{}" , ast_util:: int_ty_to_str( * self ) )
727
+ write ! ( f. buf, "{}" , ast_util:: int_ty_to_str( * self , None ) )
728
728
}
729
729
}
730
730
@@ -739,7 +739,7 @@ pub enum UintTy {
739
739
740
740
impl fmt:: Show for UintTy {
741
741
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
742
- write ! ( f. buf, "{}" , ast_util:: uint_ty_to_str( * self ) )
742
+ write ! ( f. buf, "{}" , ast_util:: uint_ty_to_str( * self , None ) )
743
743
}
744
744
}
745
745
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 @@ -2163,10 +2163,10 @@ impl<'a> State<'a> {
2163
2163
word ( & mut self . s , res. into_owned ( ) )
2164
2164
}
2165
2165
ast:: LitInt ( i, t) => {
2166
- word ( & mut self . s , format ! ( "{}{}" , i , ast_util:: int_ty_to_str( t) ) )
2166
+ word ( & mut self . s , ast_util:: int_ty_to_str ( t, Some ( i ) ) )
2167
2167
}
2168
2168
ast:: LitUint ( u, t) => {
2169
- word ( & mut self . s , format ! ( "{}{}" , u , ast_util:: uint_ty_to_str( t) ) )
2169
+ word ( & mut self . s , ast_util:: uint_ty_to_str ( t, Some ( u ) ) )
2170
2170
}
2171
2171
ast:: LitIntUnsuffixed ( i) => {
2172
2172
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