Skip to content

Commit 8a1015f

Browse files
Rollup merge of rust-lang#67551 - ldm0:E0627, r=Dylan-DPC
Add long error code explanation message for E0627 Part of rust-lang#61137. r? @GuillaumeGomez
2 parents 93116b2 + 587d03b commit 8a1015f

File tree

13 files changed

+47
-13
lines changed

13 files changed

+47
-13
lines changed

src/librustc_error_codes/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ E0622: include_str!("./error_codes/E0622.md"),
346346
E0623: include_str!("./error_codes/E0623.md"),
347347
E0624: include_str!("./error_codes/E0624.md"),
348348
E0626: include_str!("./error_codes/E0626.md"),
349+
E0627: include_str!("./error_codes/E0627.md"),
349350
E0631: include_str!("./error_codes/E0631.md"),
350351
E0633: include_str!("./error_codes/E0633.md"),
351352
E0635: include_str!("./error_codes/E0635.md"),
@@ -574,7 +575,6 @@ E0745: include_str!("./error_codes/E0745.md"),
574575
// E0612, // merged into E0609
575576
// E0613, // Removed (merged with E0609)
576577
E0625, // thread-local statics cannot be accessed at compile-time
577-
E0627, // yield statement outside of generator literal
578578
E0628, // generators cannot have explicit parameters
579579
E0629, // missing 'feature' (rustc_const_unstable)
580580
// rustc_const_unstable attribute must be paired with stable/unstable
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
A yield expression was used outside of the generator literal.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0627
6+
#![feature(generators, generator_trait)]
7+
8+
fn fake_generator() -> &'static str {
9+
yield 1;
10+
return "foo"
11+
}
12+
13+
fn main() {
14+
let mut generator = fake_generator;
15+
}
16+
```
17+
18+
The error occurs because keyword `yield` can only be used inside the generator
19+
literal. This can be fixed by constructing the generator correctly.
20+
21+
```
22+
#![feature(generators, generator_trait)]
23+
24+
fn main() {
25+
let mut generator = || {
26+
yield 1;
27+
return "foo"
28+
};
29+
}
30+
```

src/librustc_mir/borrow_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
14241424
}
14251425

14261426
/// Reports an error if this is a borrow of local data.
1427-
/// This is called for all Yield statements on movable generators
1427+
/// This is called for all Yield expressions on movable generators
14281428
fn check_for_local_borrow(&mut self, borrow: &BorrowData<'tcx>, yield_span: Span) {
14291429
debug!("check_for_local_borrow({:?})", borrow);
14301430

src/librustc_mir/borrow_check/path_utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub(super) fn is_active<'tcx>(
131131
}
132132

133133
/// Determines if a given borrow is borrowing local data
134-
/// This is called for all Yield statements on movable generators
134+
/// This is called for all Yield expressions on movable generators
135135
pub(super) fn borrow_of_local_data(place: &Place<'_>) -> bool {
136136
match place.base {
137137
PlaceBase::Static(_) => false,

src/librustc_typeck/check/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1810,7 +1810,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18101810
self.tcx.sess,
18111811
expr.span,
18121812
E0627,
1813-
"yield statement outside of generator literal"
1813+
"yield expression outside of generator literal"
18141814
)
18151815
.emit();
18161816
}

src/test/ui/feature-gates/feature-gate-generators.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fn main() {
22
yield true; //~ ERROR yield syntax is experimental
3-
//~^ ERROR yield statement outside of generator literal
3+
//~^ ERROR yield expression outside of generator literal
44
}
55

66
#[cfg(FALSE)]

src/test/ui/feature-gates/feature-gate-generators.stderr

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ LL | yield 0;
2525
= note: for more information, see https://github.com/rust-lang/rust/issues/43122
2626
= help: add `#![feature(generators)]` to the crate attributes to enable
2727

28-
error[E0627]: yield statement outside of generator literal
28+
error[E0627]: yield expression outside of generator literal
2929
--> $DIR/feature-gate-generators.rs:2:5
3030
|
3131
LL | yield true;
3232
| ^^^^^^^^^^
3333

3434
error: aborting due to 4 previous errors
3535

36-
For more information about this error, try `rustc --explain E0658`.
36+
Some errors have detailed explanations: E0627, E0658.
37+
For more information about an error, try `rustc --explain E0627`.
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![feature(generators)]
22

33
const A: u8 = { yield 3u8; 3u8};
4-
//~^ ERROR yield statement outside
4+
//~^ ERROR yield expression outside
55

66
fn main() {}
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
error[E0627]: yield statement outside of generator literal
1+
error[E0627]: yield expression outside of generator literal
22
--> $DIR/yield-in-const.rs:3:17
33
|
44
LL | const A: u8 = { yield 3u8; 3u8};
55
| ^^^^^^^^^
66

77
error: aborting due to previous error
88

9+
For more information about this error, try `rustc --explain E0627`.
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#![feature(generators)]
22

33
fn main() { yield; }
4-
//~^ ERROR yield statement outside
4+
//~^ ERROR yield expression outside
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
error[E0627]: yield statement outside of generator literal
1+
error[E0627]: yield expression outside of generator literal
22
--> $DIR/yield-in-function.rs:3:13
33
|
44
LL | fn main() { yield; }
55
| ^^^^^
66

77
error: aborting due to previous error
88

9+
For more information about this error, try `rustc --explain E0627`.
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![feature(generators)]
22

33
static B: u8 = { yield 3u8; 3u8};
4-
//~^ ERROR yield statement outside
4+
//~^ ERROR yield expression outside
55

66
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
error[E0627]: yield statement outside of generator literal
1+
error[E0627]: yield expression outside of generator literal
22
--> $DIR/yield-in-static.rs:3:18
33
|
44
LL | static B: u8 = { yield 3u8; 3u8};
55
| ^^^^^^^^^
66

77
error: aborting due to previous error
88

9+
For more information about this error, try `rustc --explain E0627`.

0 commit comments

Comments
 (0)