Skip to content

Commit 2d9188a

Browse files
---
yaml --- r: 229303 b: refs/heads/try c: 5aa6c15 h: refs/heads/master i: 229301: bbf7d83 229299: 19adffa 229295: 3df7705 v: v3
1 parent 37469c5 commit 2d9188a

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
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: aca2057ed5fb7af3f8905b2bc01f72fa001c35c8
33
refs/heads/snap-stage3: 1af31d4974e33027a68126fa5a5a3c2c6491824f
4-
refs/heads/try: 2a08cff97c94160ddd06cdec380bbde8bd4f1d1b
4+
refs/heads/try: 5aa6c155a3a5de2aa5a358e3d4f8ca212dece98f
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
77
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try/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)