mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-21 11:23:03 +00:00
Rollup merge of #67551 - ldm0:E0627, r=Dylan-DPC
Add long error code explanation message for E0627 Part of #61137. r? @GuillaumeGomez
This commit is contained in:
commit
a75968a782
@ -346,6 +346,7 @@ E0622: include_str!("./error_codes/E0622.md"),
|
||||
E0623: include_str!("./error_codes/E0623.md"),
|
||||
E0624: include_str!("./error_codes/E0624.md"),
|
||||
E0626: include_str!("./error_codes/E0626.md"),
|
||||
E0627: include_str!("./error_codes/E0627.md"),
|
||||
E0631: include_str!("./error_codes/E0631.md"),
|
||||
E0633: include_str!("./error_codes/E0633.md"),
|
||||
E0635: include_str!("./error_codes/E0635.md"),
|
||||
@ -574,7 +575,6 @@ E0745: include_str!("./error_codes/E0745.md"),
|
||||
// E0612, // merged into E0609
|
||||
// E0613, // Removed (merged with E0609)
|
||||
E0625, // thread-local statics cannot be accessed at compile-time
|
||||
E0627, // yield statement outside of generator literal
|
||||
E0628, // generators cannot have explicit parameters
|
||||
E0629, // missing 'feature' (rustc_const_unstable)
|
||||
// rustc_const_unstable attribute must be paired with stable/unstable
|
||||
|
30
src/librustc_error_codes/error_codes/E0627.md
Normal file
30
src/librustc_error_codes/error_codes/E0627.md
Normal file
@ -0,0 +1,30 @@
|
||||
A yield expression was used outside of the generator literal.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0627
|
||||
#![feature(generators, generator_trait)]
|
||||
|
||||
fn fake_generator() -> &'static str {
|
||||
yield 1;
|
||||
return "foo"
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut generator = fake_generator;
|
||||
}
|
||||
```
|
||||
|
||||
The error occurs because keyword `yield` can only be used inside the generator
|
||||
literal. This can be fixed by constructing the generator correctly.
|
||||
|
||||
```
|
||||
#![feature(generators, generator_trait)]
|
||||
|
||||
fn main() {
|
||||
let mut generator = || {
|
||||
yield 1;
|
||||
return "foo"
|
||||
};
|
||||
}
|
||||
```
|
@ -1424,7 +1424,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
}
|
||||
|
||||
/// Reports an error if this is a borrow of local data.
|
||||
/// This is called for all Yield statements on movable generators
|
||||
/// This is called for all Yield expressions on movable generators
|
||||
fn check_for_local_borrow(&mut self, borrow: &BorrowData<'tcx>, yield_span: Span) {
|
||||
debug!("check_for_local_borrow({:?})", borrow);
|
||||
|
||||
|
@ -131,7 +131,7 @@ pub(super) fn is_active<'tcx>(
|
||||
}
|
||||
|
||||
/// Determines if a given borrow is borrowing local data
|
||||
/// This is called for all Yield statements on movable generators
|
||||
/// This is called for all Yield expressions on movable generators
|
||||
pub(super) fn borrow_of_local_data(place: &Place<'_>) -> bool {
|
||||
match place.base {
|
||||
PlaceBase::Static(_) => false,
|
||||
|
@ -1810,7 +1810,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
self.tcx.sess,
|
||||
expr.span,
|
||||
E0627,
|
||||
"yield statement outside of generator literal"
|
||||
"yield expression outside of generator literal"
|
||||
)
|
||||
.emit();
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
fn main() {
|
||||
yield true; //~ ERROR yield syntax is experimental
|
||||
//~^ ERROR yield statement outside of generator literal
|
||||
//~^ ERROR yield expression outside of generator literal
|
||||
}
|
||||
|
||||
#[cfg(FALSE)]
|
||||
|
@ -25,7 +25,7 @@ LL | yield 0;
|
||||
= note: for more information, see https://github.com/rust-lang/rust/issues/43122
|
||||
= help: add `#![feature(generators)]` to the crate attributes to enable
|
||||
|
||||
error[E0627]: yield statement outside of generator literal
|
||||
error[E0627]: yield expression outside of generator literal
|
||||
--> $DIR/feature-gate-generators.rs:2:5
|
||||
|
|
||||
LL | yield true;
|
||||
@ -33,4 +33,5 @@ LL | yield true;
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
Some errors have detailed explanations: E0627, E0658.
|
||||
For more information about an error, try `rustc --explain E0627`.
|
||||
|
@ -1,6 +1,6 @@
|
||||
#![feature(generators)]
|
||||
|
||||
const A: u8 = { yield 3u8; 3u8};
|
||||
//~^ ERROR yield statement outside
|
||||
//~^ ERROR yield expression outside
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,4 +1,4 @@
|
||||
error[E0627]: yield statement outside of generator literal
|
||||
error[E0627]: yield expression outside of generator literal
|
||||
--> $DIR/yield-in-const.rs:3:17
|
||||
|
|
||||
LL | const A: u8 = { yield 3u8; 3u8};
|
||||
@ -6,3 +6,4 @@ LL | const A: u8 = { yield 3u8; 3u8};
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0627`.
|
||||
|
@ -1,4 +1,4 @@
|
||||
#![feature(generators)]
|
||||
|
||||
fn main() { yield; }
|
||||
//~^ ERROR yield statement outside
|
||||
//~^ ERROR yield expression outside
|
||||
|
@ -1,4 +1,4 @@
|
||||
error[E0627]: yield statement outside of generator literal
|
||||
error[E0627]: yield expression outside of generator literal
|
||||
--> $DIR/yield-in-function.rs:3:13
|
||||
|
|
||||
LL | fn main() { yield; }
|
||||
@ -6,3 +6,4 @@ LL | fn main() { yield; }
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0627`.
|
||||
|
@ -1,6 +1,6 @@
|
||||
#![feature(generators)]
|
||||
|
||||
static B: u8 = { yield 3u8; 3u8};
|
||||
//~^ ERROR yield statement outside
|
||||
//~^ ERROR yield expression outside
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,4 +1,4 @@
|
||||
error[E0627]: yield statement outside of generator literal
|
||||
error[E0627]: yield expression outside of generator literal
|
||||
--> $DIR/yield-in-static.rs:3:18
|
||||
|
|
||||
LL | static B: u8 = { yield 3u8; 3u8};
|
||||
@ -6,3 +6,4 @@ LL | static B: u8 = { yield 3u8; 3u8};
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0627`.
|
||||
|
Loading…
Reference in New Issue
Block a user