66use cfg:: { CfgExpr , CfgOptions } ;
77use either:: Either ;
88use hir_def:: {
9+ body:: ExprOrPatPtr ,
910 hir:: ExprOrPatId ,
1011 path:: { hir_segment_to_ast_segment, ModPath } ,
1112 type_ref:: TypesSourceMap ,
@@ -115,14 +116,14 @@ diagnostics![
115116
116117#[ derive( Debug ) ]
117118pub struct BreakOutsideOfLoop {
118- pub expr : InFile < AstPtr < ast:: Expr > > ,
119+ pub expr : InFile < AstPtr < Either < ast:: Expr , ast :: Pat > > > ,
119120 pub is_break : bool ,
120121 pub bad_value_break : bool ,
121122}
122123
123124#[ derive( Debug ) ]
124125pub struct TypedHole {
125- pub expr : InFile < AstPtr < ast:: Expr > > ,
126+ pub expr : InFile < AstPtr < Either < ast:: Expr , ast :: Pat > > > ,
126127 pub expected : Type ,
127128}
128129
@@ -234,21 +235,21 @@ pub struct MismatchedTupleStructPatArgCount {
234235
235236#[ derive( Debug ) ]
236237pub struct ExpectedFunction {
237- pub call : InFile < AstPtr < ast:: Expr > > ,
238+ pub call : InFile < AstPtr < Either < ast:: Expr , ast :: Pat > > > ,
238239 pub found : Type ,
239240}
240241
241242#[ derive( Debug ) ]
242243pub struct UnresolvedField {
243- pub expr : InFile < AstPtr < ast:: Expr > > ,
244+ pub expr : InFile < AstPtr < Either < ast:: Expr , ast :: Pat > > > ,
244245 pub receiver : Type ,
245246 pub name : Name ,
246247 pub method_with_same_name_exists : bool ,
247248}
248249
249250#[ derive( Debug ) ]
250251pub struct UnresolvedMethodCall {
251- pub expr : InFile < AstPtr < ast:: Expr > > ,
252+ pub expr : InFile < AstPtr < Either < ast:: Expr , ast :: Pat > > > ,
252253 pub receiver : Type ,
253254 pub name : Name ,
254255 pub field_with_same_name : Option < Type > ,
@@ -267,7 +268,7 @@ pub struct UnresolvedIdent {
267268
268269#[ derive( Debug ) ]
269270pub struct PrivateField {
270- pub expr : InFile < AstPtr < ast:: Expr > > ,
271+ pub expr : InFile < AstPtr < Either < ast:: Expr , ast :: Pat > > > ,
271272 pub field : Field ,
272273}
273274
@@ -302,7 +303,7 @@ pub struct ReplaceFilterMapNextWithFindMap {
302303
303304#[ derive( Debug ) ]
304305pub struct MismatchedArgCount {
305- pub call_expr : InFile < AstPtr < ast :: Expr > > ,
306+ pub call_expr : InFile < ExprOrPatPtr > ,
306307 pub expected : usize ,
307308 pub found : usize ,
308309}
@@ -395,13 +396,13 @@ pub struct RemoveUnnecessaryElse {
395396
396397#[ derive( Debug ) ]
397398pub struct CastToUnsized {
398- pub expr : InFile < AstPtr < ast:: Expr > > ,
399+ pub expr : InFile < AstPtr < Either < ast:: Expr , ast :: Pat > > > ,
399400 pub cast_ty : Type ,
400401}
401402
402403#[ derive( Debug ) ]
403404pub struct InvalidCast {
404- pub expr : InFile < AstPtr < ast:: Expr > > ,
405+ pub expr : InFile < AstPtr < Either < ast:: Expr , ast :: Pat > > > ,
405406 pub error : CastError ,
406407 pub expr_ty : Type ,
407408 pub cast_ty : Type ,
@@ -428,9 +429,7 @@ impl AnyDiagnostic {
428429 . collect ( ) ;
429430
430431 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 ( ) ?,
434433 Either :: Right ( record_pat) => source_map. pat_syntax ( record_pat) . ok ( ) ?,
435434 } ;
436435 let file = record. file_id ;
@@ -474,7 +473,7 @@ impl AnyDiagnostic {
474473 return Some (
475474 ReplaceFilterMapNextWithFindMap {
476475 file : next_source_ptr. file_id ,
477- next_expr : next_source_ptr. value ,
476+ next_expr : next_source_ptr. value . cast ( ) ? ,
478477 }
479478 . into ( ) ,
480479 ) ;
@@ -484,7 +483,9 @@ impl AnyDiagnostic {
484483 match source_map. expr_syntax ( match_expr) {
485484 Ok ( source_ptr) => {
486485 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+ {
488489 match match_expr. expr ( ) {
489490 Some ( scrut_expr) if match_expr. match_arm_list ( ) . is_some ( ) => {
490491 return Some (
@@ -561,7 +562,7 @@ impl AnyDiagnostic {
561562 let pat_syntax =
562563 |pat| source_map. pat_syntax ( pat) . inspect_err ( |_| stdx:: never!( "synthetic syntax" ) ) . ok ( ) ;
563564 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) ,
565566 ExprOrPatId :: PatId ( pat) => pat_syntax ( pat) ,
566567 } ;
567568 Some ( match d {
@@ -633,7 +634,7 @@ impl AnyDiagnostic {
633634 & InferenceDiagnostic :: UnresolvedIdent { id } => {
634635 let node = match id {
635636 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 ) ) ,
637638 Err ( SyntheticSyntax ) => source_map
638639 . format_args_implicit_capture ( id) ?
639640 . map ( |( node, range) | ( node. wrap_left ( ) , Some ( range) ) ) ,
@@ -652,7 +653,7 @@ impl AnyDiagnostic {
652653 }
653654 & InferenceDiagnostic :: MismatchedTupleStructPatArgCount { pat, expected, found } => {
654655 let expr_or_pat = match pat {
655- ExprOrPatId :: ExprId ( expr) => expr_syntax ( expr) ?. map ( AstPtr :: wrap_left ) ,
656+ ExprOrPatId :: ExprId ( expr) => expr_syntax ( expr) ?,
656657 ExprOrPatId :: PatId ( pat) => {
657658 let InFile { file_id, value } = pat_syntax ( pat) ?;
658659
0 commit comments