1
1
use either:: Either ;
2
2
use hir:: { db:: ExpandDatabase , ClosureStyle , HirDisplay , InFile , Type } ;
3
3
use ide_db:: { famous_defs:: FamousDefs , source_change:: SourceChange } ;
4
- use stdx:: never;
5
4
use syntax:: {
6
5
ast:: { self , BlockExpr , ExprStmt } ,
7
6
AstNode , AstPtr ,
@@ -18,24 +17,20 @@ pub(crate) fn type_mismatch(ctx: &DiagnosticsContext<'_>, d: &hir::TypeMismatch)
18
17
let display_range = match & d. expr_or_pat {
19
18
Either :: Left ( expr) => {
20
19
adjusted_display_range :: < ast:: Expr > ( ctx, expr. clone ( ) . map ( |it| it. into ( ) ) , & |expr| {
21
- if !expr. is_block_like ( ) {
22
- return None ;
23
- }
24
-
25
20
let salient_token_range = match expr {
26
21
ast:: Expr :: IfExpr ( it) => it. if_token ( ) ?. text_range ( ) ,
27
22
ast:: Expr :: LoopExpr ( it) => it. loop_token ( ) ?. text_range ( ) ,
28
23
ast:: Expr :: ForExpr ( it) => it. for_token ( ) ?. text_range ( ) ,
29
24
ast:: Expr :: WhileExpr ( it) => it. while_token ( ) ?. text_range ( ) ,
30
25
ast:: Expr :: BlockExpr ( it) => it. stmt_list ( ) ?. r_curly_token ( ) ?. text_range ( ) ,
31
26
ast:: Expr :: MatchExpr ( it) => it. match_token ( ) ?. text_range ( ) ,
32
- _ => {
33
- never ! ( ) ;
34
- return None ;
35
- }
27
+ ast :: Expr :: MethodCallExpr ( it ) => it . name_ref ( ) ? . ident_token ( ) ? . text_range ( ) ,
28
+ ast :: Expr :: FieldExpr ( it ) => it . name_ref ( ) ? . ident_token ( ) ? . text_range ( ) ,
29
+ ast :: Expr :: AwaitExpr ( it ) => it . await_token ( ) ? . text_range ( ) ,
30
+ _ => return None ,
36
31
} ;
37
32
38
- cov_mark:: hit!( type_mismatch_on_block ) ;
33
+ cov_mark:: hit!( type_mismatch_range_adjustment ) ;
39
34
Some ( salient_token_range)
40
35
} )
41
36
}
@@ -625,8 +620,8 @@ fn f() {
625
620
}
626
621
627
622
#[ test]
628
- fn type_mismatch_on_block ( ) {
629
- cov_mark:: check!( type_mismatch_on_block ) ;
623
+ fn type_mismatch_range_adjustment ( ) {
624
+ cov_mark:: check!( type_mismatch_range_adjustment ) ;
630
625
check_diagnostics (
631
626
r#"
632
627
fn f() -> i32 {
@@ -636,9 +631,15 @@ fn f() -> i32 {
636
631
}
637
632
//^ error: expected i32, found ()
638
633
639
- fn h () -> i32 {
634
+ fn g () -> i32 {
640
635
while true {}
641
636
} //^^^^^ error: expected i32, found ()
637
+
638
+ struct S;
639
+ impl S { fn foo(&self) -> &S { self } }
640
+ fn h() {
641
+ let _: i32 = S.foo().foo().foo();
642
+ } //^^^ error: expected i32, found &S
642
643
"# ,
643
644
) ;
644
645
}
0 commit comments