Skip to content

Commit 2db97b2

Browse files
Account for .yield in illegal postfix operator message
1 parent 9ba00e0 commit 2db97b2

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,9 +785,13 @@ impl<'a> Parser<'a> {
785785
ExprKind::Call(_, _) => "a function call",
786786
ExprKind::Await(_, _) => "`.await`",
787787
ExprKind::Use(_, _) => "`.use`",
788+
ExprKind::Yield(YieldKind::Postfix(_)) => "`.yield`",
788789
ExprKind::Match(_, _, MatchKind::Postfix) => "a postfix match",
789790
ExprKind::Err(_) => return Ok(with_postfix),
790-
_ => unreachable!("parse_dot_or_call_expr_with_ shouldn't produce this"),
791+
_ => unreachable!(
792+
"did not expect {:?} as an illegal postfix operator following cast",
793+
with_postfix.kind
794+
),
791795
}
792796
);
793797
let mut err = self.dcx().struct_span_err(span, msg);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Regression test for <https://github.com/rust-lang/rust/issues/144527>.
2+
3+
#![feature(yield_expr, coroutines)]
4+
5+
fn main() {
6+
#[coroutine] || {
7+
0 as u8.yield
8+
//~^ ERROR cast cannot be followed by `.yield`
9+
};
10+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error: cast cannot be followed by `.yield`
2+
--> $DIR/postfix-yield-after-cast.rs:7:9
3+
|
4+
LL | 0 as u8.yield
5+
| ^^^^^^^
6+
|
7+
help: try surrounding the expression in parentheses
8+
|
9+
LL | (0 as u8).yield
10+
| + +
11+
12+
error: aborting due to 1 previous error
13+

0 commit comments

Comments
 (0)