6
6
use cfg:: { CfgExpr , CfgOptions } ;
7
7
use either:: Either ;
8
8
use hir_def:: {
9
+ body:: ExprOrPatPtr ,
9
10
hir:: ExprOrPatId ,
10
11
path:: { hir_segment_to_ast_segment, ModPath } ,
11
12
type_ref:: TypesSourceMap ,
@@ -115,14 +116,14 @@ diagnostics![
115
116
116
117
#[ derive( Debug ) ]
117
118
pub struct BreakOutsideOfLoop {
118
- pub expr : InFile < AstPtr < ast:: Expr > > ,
119
+ pub expr : InFile < AstPtr < Either < ast:: Expr , ast :: Pat > > > ,
119
120
pub is_break : bool ,
120
121
pub bad_value_break : bool ,
121
122
}
122
123
123
124
#[ derive( Debug ) ]
124
125
pub struct TypedHole {
125
- pub expr : InFile < AstPtr < ast:: Expr > > ,
126
+ pub expr : InFile < AstPtr < Either < ast:: Expr , ast :: Pat > > > ,
126
127
pub expected : Type ,
127
128
}
128
129
@@ -234,21 +235,21 @@ pub struct MismatchedTupleStructPatArgCount {
234
235
235
236
#[ derive( Debug ) ]
236
237
pub struct ExpectedFunction {
237
- pub call : InFile < AstPtr < ast:: Expr > > ,
238
+ pub call : InFile < AstPtr < Either < ast:: Expr , ast :: Pat > > > ,
238
239
pub found : Type ,
239
240
}
240
241
241
242
#[ derive( Debug ) ]
242
243
pub struct UnresolvedField {
243
- pub expr : InFile < AstPtr < ast:: Expr > > ,
244
+ pub expr : InFile < AstPtr < Either < ast:: Expr , ast :: Pat > > > ,
244
245
pub receiver : Type ,
245
246
pub name : Name ,
246
247
pub method_with_same_name_exists : bool ,
247
248
}
248
249
249
250
#[ derive( Debug ) ]
250
251
pub struct UnresolvedMethodCall {
251
- pub expr : InFile < AstPtr < ast:: Expr > > ,
252
+ pub expr : InFile < AstPtr < Either < ast:: Expr , ast :: Pat > > > ,
252
253
pub receiver : Type ,
253
254
pub name : Name ,
254
255
pub field_with_same_name : Option < Type > ,
@@ -267,7 +268,7 @@ pub struct UnresolvedIdent {
267
268
268
269
#[ derive( Debug ) ]
269
270
pub struct PrivateField {
270
- pub expr : InFile < AstPtr < ast:: Expr > > ,
271
+ pub expr : InFile < AstPtr < Either < ast:: Expr , ast :: Pat > > > ,
271
272
pub field : Field ,
272
273
}
273
274
@@ -302,7 +303,7 @@ pub struct ReplaceFilterMapNextWithFindMap {
302
303
303
304
#[ derive( Debug ) ]
304
305
pub struct MismatchedArgCount {
305
- pub call_expr : InFile < AstPtr < ast :: Expr > > ,
306
+ pub call_expr : InFile < ExprOrPatPtr > ,
306
307
pub expected : usize ,
307
308
pub found : usize ,
308
309
}
@@ -395,13 +396,13 @@ pub struct RemoveUnnecessaryElse {
395
396
396
397
#[ derive( Debug ) ]
397
398
pub struct CastToUnsized {
398
- pub expr : InFile < AstPtr < ast:: Expr > > ,
399
+ pub expr : InFile < AstPtr < Either < ast:: Expr , ast :: Pat > > > ,
399
400
pub cast_ty : Type ,
400
401
}
401
402
402
403
#[ derive( Debug ) ]
403
404
pub struct InvalidCast {
404
- pub expr : InFile < AstPtr < ast:: Expr > > ,
405
+ pub expr : InFile < AstPtr < Either < ast:: Expr , ast :: Pat > > > ,
405
406
pub error : CastError ,
406
407
pub expr_ty : Type ,
407
408
pub cast_ty : Type ,
@@ -428,9 +429,7 @@ impl AnyDiagnostic {
428
429
. collect ( ) ;
429
430
430
431
let record = match record {
431
- Either :: Left ( record_expr) => {
432
- source_map. expr_syntax ( record_expr) . ok ( ) ?. map ( AstPtr :: wrap_left)
433
- }
432
+ Either :: Left ( record_expr) => source_map. expr_syntax ( record_expr) . ok ( ) ?,
434
433
Either :: Right ( record_pat) => source_map. pat_syntax ( record_pat) . ok ( ) ?,
435
434
} ;
436
435
let file = record. file_id ;
@@ -474,7 +473,7 @@ impl AnyDiagnostic {
474
473
return Some (
475
474
ReplaceFilterMapNextWithFindMap {
476
475
file : next_source_ptr. file_id ,
477
- next_expr : next_source_ptr. value ,
476
+ next_expr : next_source_ptr. value . cast ( ) ? ,
478
477
}
479
478
. into ( ) ,
480
479
) ;
@@ -484,7 +483,9 @@ impl AnyDiagnostic {
484
483
match source_map. expr_syntax ( match_expr) {
485
484
Ok ( source_ptr) => {
486
485
let root = source_ptr. file_syntax ( db. upcast ( ) ) ;
487
- if let ast:: Expr :: MatchExpr ( match_expr) = & source_ptr. value . to_node ( & root) {
486
+ if let Either :: Left ( ast:: Expr :: MatchExpr ( match_expr) ) =
487
+ & source_ptr. value . to_node ( & root)
488
+ {
488
489
match match_expr. expr ( ) {
489
490
Some ( scrut_expr) if match_expr. match_arm_list ( ) . is_some ( ) => {
490
491
return Some (
@@ -561,7 +562,7 @@ impl AnyDiagnostic {
561
562
let pat_syntax =
562
563
|pat| source_map. pat_syntax ( pat) . inspect_err ( |_| stdx:: never!( "synthetic syntax" ) ) . ok ( ) ;
563
564
let expr_or_pat_syntax = |id| match id {
564
- ExprOrPatId :: ExprId ( expr) => expr_syntax ( expr) . map ( |it| it . map ( AstPtr :: wrap_left ) ) ,
565
+ ExprOrPatId :: ExprId ( expr) => expr_syntax ( expr) ,
565
566
ExprOrPatId :: PatId ( pat) => pat_syntax ( pat) ,
566
567
} ;
567
568
Some ( match d {
@@ -633,7 +634,7 @@ impl AnyDiagnostic {
633
634
& InferenceDiagnostic :: UnresolvedIdent { id } => {
634
635
let node = match id {
635
636
ExprOrPatId :: ExprId ( id) => match source_map. expr_syntax ( id) {
636
- Ok ( syntax) => syntax. map ( |it| ( it. wrap_left ( ) , None ) ) ,
637
+ Ok ( syntax) => syntax. map ( |it| ( it, None ) ) ,
637
638
Err ( SyntheticSyntax ) => source_map
638
639
. format_args_implicit_capture ( id) ?
639
640
. map ( |( node, range) | ( node. wrap_left ( ) , Some ( range) ) ) ,
@@ -652,7 +653,7 @@ impl AnyDiagnostic {
652
653
}
653
654
& InferenceDiagnostic :: MismatchedTupleStructPatArgCount { pat, expected, found } => {
654
655
let expr_or_pat = match pat {
655
- ExprOrPatId :: ExprId ( expr) => expr_syntax ( expr) ?. map ( AstPtr :: wrap_left ) ,
656
+ ExprOrPatId :: ExprId ( expr) => expr_syntax ( expr) ?,
656
657
ExprOrPatId :: PatId ( pat) => {
657
658
let InFile { file_id, value } = pat_syntax ( pat) ?;
658
659
0 commit comments