File tree Expand file tree Collapse file tree 2 files changed +23
-11
lines changed
branches/try/src/librustc_typeck Expand file tree Collapse file tree 2 files changed +23
-11
lines changed Original file line number Diff line number Diff line change 1
1
---
2
2
refs/heads/master: aca2057ed5fb7af3f8905b2bc01f72fa001c35c8
3
3
refs/heads/snap-stage3: 1af31d4974e33027a68126fa5a5a3c2c6491824f
4
- refs/heads/try: 2a08cff97c94160ddd06cdec380bbde8bd4f1d1b
4
+ refs/heads/try: 5aa6c155a3a5de2aa5a358e3d4f8ca212dece98f
5
5
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
6
6
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
7
7
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
Original file line number Diff line number Diff line change @@ -1123,27 +1123,39 @@ You hit this error because the compiler lacks information to
1123
1123
determine a type for this variable. Erroneous code example:
1124
1124
1125
1125
```
1126
+ fn demo(devil: fn () -> !) {
1127
+ let x: &_ = devil();
1128
+ // error: cannot determine a type for this local variable
1129
+ }
1130
+
1131
+ fn oh_no() -> ! { panic!("the devil is in the details") }
1132
+
1126
1133
fn main() {
1127
- let x: &_; // error: cannot determine a type for this local variable
1134
+ demo(oh_no);
1128
1135
}
1129
1136
```
1130
1137
1131
- You have two possibilities to solve this situation:
1132
- * Give an explicit definition of the variable
1133
- * Infer the variable
1134
-
1138
+ To solve this situation, constrain the type of the variable.
1135
1139
Examples:
1136
1140
1137
1141
```
1138
- fn some_func(x: u32) {
1142
+ fn some_func(x: & u32) {
1139
1143
// some code
1140
1144
}
1141
1145
1142
- fn main() {
1143
- let x = 0u32; // ok!
1144
- // or:
1145
- let x = 0;
1146
+ fn demo(devil: fn () -> !) {
1147
+ let x: &u32 = devil();
1148
+ // Here we defined the type at the variable creation
1149
+
1150
+ let x: &_ = devil();
1146
1151
some_func(x);
1152
+ // Here, the type is determined by the function argument type
1153
+ }
1154
+
1155
+ fn oh_no() -> ! { panic!("the devil is in the details") }
1156
+
1157
+ fn main() {
1158
+ demo(oh_no);
1147
1159
}
1148
1160
```
1149
1161
"## ,
You can’t perform that action at this time.
0 commit comments