Skip to content

Commit d041919

Browse files
---
yaml --- r: 223256 b: refs/heads/auto c: 5aa6c15 h: refs/heads/master v: v3
1 parent d23de19 commit d041919

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
88
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
99
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1010
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
11-
refs/heads/auto: 2a08cff97c94160ddd06cdec380bbde8bd4f1d1b
11+
refs/heads/auto: 5aa6c155a3a5de2aa5a358e3d4f8ca212dece98f
1212
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1313
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336
1414
refs/tags/0.2: 1754d02027f2924bed83b0160ee340c7f41d5ea1

branches/auto/src/librustc_typeck/diagnostics.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,27 +1123,39 @@ You hit this error because the compiler lacks information to
11231123
determine a type for this variable. Erroneous code example:
11241124
11251125
```
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+
11261133
fn main() {
1127-
let x: &_; // error: cannot determine a type for this local variable
1134+
demo(oh_no);
11281135
}
11291136
```
11301137
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.
11351139
Examples:
11361140
11371141
```
1138-
fn some_func(x: u32) {
1142+
fn some_func(x: &u32) {
11391143
// some code
11401144
}
11411145
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();
11461151
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);
11471159
}
11481160
```
11491161
"##,

0 commit comments

Comments
 (0)