Skip to content

Commit 83cc5ef

Browse files
committed
Auto merge of rust-lang#14686 - matklad:matklad/angry-chain, r=Veykril
fix: don't wavy-underline iterator chains
2 parents 07e535b + f3de9d8 commit 83cc5ef

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

crates/ide-diagnostics/src/handlers/type_mismatch.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use either::Either;
22
use hir::{db::ExpandDatabase, ClosureStyle, HirDisplay, InFile, Type};
33
use ide_db::{famous_defs::FamousDefs, source_change::SourceChange};
4-
use stdx::never;
54
use syntax::{
65
ast::{self, BlockExpr, ExprStmt},
76
AstNode, AstPtr,
@@ -18,24 +17,20 @@ pub(crate) fn type_mismatch(ctx: &DiagnosticsContext<'_>, d: &hir::TypeMismatch)
1817
let display_range = match &d.expr_or_pat {
1918
Either::Left(expr) => {
2019
adjusted_display_range::<ast::Expr>(ctx, expr.clone().map(|it| it.into()), &|expr| {
21-
if !expr.is_block_like() {
22-
return None;
23-
}
24-
2520
let salient_token_range = match expr {
2621
ast::Expr::IfExpr(it) => it.if_token()?.text_range(),
2722
ast::Expr::LoopExpr(it) => it.loop_token()?.text_range(),
2823
ast::Expr::ForExpr(it) => it.for_token()?.text_range(),
2924
ast::Expr::WhileExpr(it) => it.while_token()?.text_range(),
3025
ast::Expr::BlockExpr(it) => it.stmt_list()?.r_curly_token()?.text_range(),
3126
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,
3631
};
3732

38-
cov_mark::hit!(type_mismatch_on_block);
33+
cov_mark::hit!(type_mismatch_range_adjustment);
3934
Some(salient_token_range)
4035
})
4136
}
@@ -625,8 +620,8 @@ fn f() {
625620
}
626621

627622
#[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);
630625
check_diagnostics(
631626
r#"
632627
fn f() -> i32 {
@@ -636,9 +631,15 @@ fn f() -> i32 {
636631
}
637632
//^ error: expected i32, found ()
638633
639-
fn h() -> i32 {
634+
fn g() -> i32 {
640635
while true {}
641636
} //^^^^^ 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
642643
"#,
643644
);
644645
}

0 commit comments

Comments
 (0)