File tree Expand file tree Collapse file tree 5 files changed +32
-14
lines changed Expand file tree Collapse file tree 5 files changed +32
-14
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ use ptr::Ptr;
22
22
use to_str:: ToStr ;
23
23
24
24
export Path , WindowsPath , PosixPath , GenericPath ;
25
- export Option , Some , None , unreachable ;
25
+ export Option , Some , None ;
26
26
export Result , Ok , Err ;
27
27
export extensions;
28
28
// The following exports are the extension impls for numeric types
@@ -96,13 +96,3 @@ mod std {
96
96
extern mod std( vers = "0.4" ) ;
97
97
use std:: test;
98
98
}
99
-
100
- /**
101
- * A standard function to use to indicate unreachable code. Because the
102
- * function is guaranteed to fail typestate will correctly identify
103
- * any code paths following the appearance of this function as unreachable.
104
- */
105
- fn unreachable ( ) -> ! {
106
- fail ~"Internal error: entered unreachable code";
107
- }
108
-
Original file line number Diff line number Diff line change @@ -206,7 +206,7 @@ impl Rng {
206
206
return Some ( item. item ) ;
207
207
}
208
208
}
209
- unreachable ( ) ;
209
+ util :: unreachable ( ) ;
210
210
}
211
211
212
212
/**
Original file line number Diff line number Diff line change @@ -64,6 +64,34 @@ struct NonCopyable {
64
64
65
65
fn NonCopyable ( ) -> NonCopyable { NonCopyable { i : ( ) } }
66
66
67
+ /**
68
+ A utility function for indicating unreachable code. It will fail if
69
+ executed. This is occasionally useful to put after loops that never
70
+ terminate normally, but instead directly return from a function.
71
+
72
+ # Example
73
+
74
+ ~~~
75
+ fn choose_weighted_item(v: &[Item]) -> Item {
76
+ assert v.is_not_empty();
77
+ let mut so_far = 0u;
78
+ for v.each |item| {
79
+ so_far += item.weight;
80
+ if so_far > 100 {
81
+ return item;
82
+ }
83
+ }
84
+ // The above loop always returns, so we must hint to the
85
+ // type checker that it isn't possible to get down here
86
+ util::unreachable();
87
+ }
88
+ ~~~
89
+
90
+ */
91
+ fn unreachable( ) -> ! {
92
+ fail ~"internal error: entered unreachable code";
93
+ }
94
+
67
95
mod tests {
68
96
#[ test ]
69
97
fn identity_crisis ( ) {
Original file line number Diff line number Diff line change @@ -106,7 +106,7 @@ fn get_rpath_relative_to_output(os: session::os,
106
106
let prefix = match os {
107
107
session:: os_linux | session:: os_freebsd => "$ORIGIN" ,
108
108
session:: os_macos => "@executable_path" ,
109
- session:: os_win32 => core:: unreachable ( )
109
+ session:: os_win32 => core:: util :: unreachable ( )
110
110
} ;
111
111
112
112
Path ( prefix) . push_rel ( & get_relative_to ( & os:: make_absolute ( output) ,
Original file line number Diff line number Diff line change @@ -170,7 +170,7 @@ fn variant_opt(tcx: ty::ctxt, pat_id: ast::node_id) -> Opt {
170
170
for vec:: each( * variants) |v| {
171
171
if vdef. var == v. id { return var ( v. disr_val , vdef) ; }
172
172
}
173
- core:: unreachable ( ) ;
173
+ core:: util :: unreachable ( ) ;
174
174
}
175
175
176
176
enum TransBindingMode {
You can’t perform that action at this time.
0 commit comments