@@ -164,6 +164,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
164
164
ExprKind :: Range ( ref e1, ref e2, lims) => {
165
165
self . lower_expr_range ( e. span , e1. as_deref ( ) , e2. as_deref ( ) , lims)
166
166
}
167
+ ExprKind :: Underscore => {
168
+ self . sess
169
+ . struct_span_err (
170
+ e. span ,
171
+ "in expressions, `_` can only be used on the left-hand side of an assignment" ,
172
+ )
173
+ . span_label ( e. span , "`_` not allowed here" )
174
+ . emit ( ) ;
175
+ hir:: ExprKind :: Err
176
+ }
167
177
ExprKind :: Path ( ref qself, ref path) => {
168
178
let qpath = self . lower_qpath (
169
179
e. id ,
@@ -863,7 +873,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
863
873
// Return early in case of an ordinary assignment.
864
874
fn is_ordinary ( lower_ctx : & mut LoweringContext < ' _ , ' _ > , lhs : & Expr ) -> bool {
865
875
match & lhs. kind {
866
- ExprKind :: Array ( ..) | ExprKind :: Struct ( ..) | ExprKind :: Tup ( ..) => false ,
876
+ ExprKind :: Array ( ..)
877
+ | ExprKind :: Struct ( ..)
878
+ | ExprKind :: Tup ( ..)
879
+ | ExprKind :: Underscore => false ,
867
880
// Check for tuple struct constructor.
868
881
ExprKind :: Call ( callee, ..) => lower_ctx. extract_tuple_struct_path ( callee) . is_none ( ) ,
869
882
ExprKind :: Paren ( e) => {
@@ -943,6 +956,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
943
956
assignments : & mut Vec < hir:: Stmt < ' hir > > ,
944
957
) -> & ' hir hir:: Pat < ' hir > {
945
958
match & lhs. kind {
959
+ // Underscore pattern.
960
+ ExprKind :: Underscore => {
961
+ return self . pat_without_dbm ( lhs. span , hir:: PatKind :: Wild ) ;
962
+ }
946
963
// Slice patterns.
947
964
ExprKind :: Array ( elements) => {
948
965
let ( pats, rest) =
0 commit comments