File tree Expand file tree Collapse file tree 6 files changed +56
-5
lines changed
librustc/middle/typeck/check Expand file tree Collapse file tree 6 files changed +56
-5
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ refs/heads/try: 0983ebe5310d4eb6d289f636f7ed0536c08bbc0e
6
6
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
7
7
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8
8
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9
- refs/heads/dist-snap: 0450cde37b70e7c32a2d5d359836b737c5fdc657
9
+ refs/heads/dist-snap: 109274426a7cd676b9aa1bb06afd9f86b44f6e9b
10
10
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
11
11
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
12
12
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
Original file line number Diff line number Diff line change @@ -942,7 +942,15 @@ impl FnCtxt {
942
942
if ty:: type_is_error ( e) || ty:: type_is_error ( a) {
943
943
return ;
944
944
}
945
- self . infcx ( ) . report_mismatched_types ( sp, e, a, err)
945
+ match self . fn_kind {
946
+ DoBlock if ty:: type_is_bool ( e) && ty:: type_is_nil ( a) =>
947
+ // If we expected bool and got ()...
948
+ self . tcx ( ) . sess . span_err ( sp, fmt ! ( "Do-block body must \
949
+ return %s, but returns () here. Perhaps you meant \
950
+ to write a `for`-loop?",
951
+ ppaux:: ty_to_str( self . tcx( ) , e) ) ) ,
952
+ _ => self . infcx ( ) . report_mismatched_types ( sp, e, a, err)
953
+ }
946
954
}
947
955
948
956
pub fn report_mismatched_types ( & self ,
Original file line number Diff line number Diff line change @@ -726,9 +726,9 @@ impl Bool for bool {
726
726
}
727
727
}
728
728
729
- impl < ' self > String for & ' self str {
730
- fn fmt ( s : & & ' self str , f : & mut Formatter ) {
731
- f. pad ( * s ) ;
729
+ impl < ' self , T : str :: Str > String for T {
730
+ fn fmt ( s : & T , f : & mut Formatter ) {
731
+ f. pad ( s . as_slice ( ) ) ;
732
732
}
733
733
}
734
734
Original file line number Diff line number Diff line change
1
+ // Copyright 2012 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
+ use std:: uint;
12
+
13
+ fn uuid ( ) -> uint { fail ! ( ) ; }
14
+
15
+ fn from_str ( s : ~str ) -> uint { fail ! ( ) ; }
16
+ fn to_str ( u : uint ) -> ~str { fail ! ( ) ; }
17
+ fn uuid_random ( ) -> uint { fail ! ( ) ; }
18
+
19
+ fn main ( ) {
20
+ do range ( 0 u, 100000 ) . advance |_i| { //~ ERROR Do-block body must return bool, but
21
+ } ;
22
+ // should get a more general message if the callback
23
+ // doesn't return nil
24
+ do range ( 0 u, 100000 ) . advance |_i| { //~ ERROR mismatched types
25
+ ~"str"
26
+ } ;
27
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2012 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 main ( ) {
12
+ fn take_block ( f : & fn ( ) -> bool ) -> bool { f ( ) }
13
+ do take_block { } ; //~ ERROR Do-block body must return bool, but returns () here. Perhaps
14
+ }
Original file line number Diff line number Diff line change @@ -45,6 +45,8 @@ pub fn main() {
45
45
t ! ( ifmt!( "{:x}" , 10 u) , "a" ) ;
46
46
t ! ( ifmt!( "{:X}" , 10 u) , "A" ) ;
47
47
t ! ( ifmt!( "{:s}" , "foo" ) , "foo" ) ;
48
+ t ! ( ifmt!( "{:s}" , ~"foo"), " foo");
49
+ t!(ifmt!(" { : s} ", @" foo"), " foo");
48
50
t!(ifmt!(" { : p} ", 0x1234 as *int), " 0x1234 ");
49
51
t!(ifmt!(" { : p} ", 0x1234 as *mut int), " 0x1234 ");
50
52
t!(ifmt!(" { : d} ", A), " aloha");
You can’t perform that action at this time.
0 commit comments