diff options
| author | bors <bors@rust-lang.org> | 2023-04-29 16:35:37 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-04-29 16:35:37 +0000 |
| commit | 83cc5ef4c1c455b42ebbdac877a657f15c70b5fa (patch) | |
| tree | b30c21fa58a549e13b6cfd2c2614170ee5ca2625 | |
| parent | 07e535b6df9877bf2493bcf9411df479f03bd84e (diff) | |
| parent | f3de9d8f540ec3c5d6aefec5884cb4638e9d5588 (diff) | |
| download | rust-83cc5ef4c1c455b42ebbdac877a657f15c70b5fa.tar.gz rust-83cc5ef4c1c455b42ebbdac877a657f15c70b5fa.zip | |
Auto merge of #14686 - matklad:matklad/angry-chain, r=Veykril
fix: don't wavy-underline iterator chains
| -rw-r--r-- | crates/ide-diagnostics/src/handlers/type_mismatch.rs | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/crates/ide-diagnostics/src/handlers/type_mismatch.rs b/crates/ide-diagnostics/src/handlers/type_mismatch.rs index d240ca13e60..b49141b55b7 100644 --- a/crates/ide-diagnostics/src/handlers/type_mismatch.rs +++ b/crates/ide-diagnostics/src/handlers/type_mismatch.rs @@ -1,7 +1,6 @@ use either::Either; use hir::{db::ExpandDatabase, ClosureStyle, HirDisplay, InFile, Type}; use ide_db::{famous_defs::FamousDefs, source_change::SourceChange}; -use stdx::never; use syntax::{ ast::{self, BlockExpr, ExprStmt}, AstNode, AstPtr, @@ -18,10 +17,6 @@ pub(crate) fn type_mismatch(ctx: &DiagnosticsContext<'_>, d: &hir::TypeMismatch) let display_range = match &d.expr_or_pat { Either::Left(expr) => { adjusted_display_range::<ast::Expr>(ctx, expr.clone().map(|it| it.into()), &|expr| { - if !expr.is_block_like() { - return None; - } - let salient_token_range = match expr { ast::Expr::IfExpr(it) => it.if_token()?.text_range(), ast::Expr::LoopExpr(it) => it.loop_token()?.text_range(), @@ -29,13 +24,13 @@ pub(crate) fn type_mismatch(ctx: &DiagnosticsContext<'_>, d: &hir::TypeMismatch) ast::Expr::WhileExpr(it) => it.while_token()?.text_range(), ast::Expr::BlockExpr(it) => it.stmt_list()?.r_curly_token()?.text_range(), ast::Expr::MatchExpr(it) => it.match_token()?.text_range(), - _ => { - never!(); - return None; - } + ast::Expr::MethodCallExpr(it) => it.name_ref()?.ident_token()?.text_range(), + ast::Expr::FieldExpr(it) => it.name_ref()?.ident_token()?.text_range(), + ast::Expr::AwaitExpr(it) => it.await_token()?.text_range(), + _ => return None, }; - cov_mark::hit!(type_mismatch_on_block); + cov_mark::hit!(type_mismatch_range_adjustment); Some(salient_token_range) }) } @@ -625,8 +620,8 @@ fn f() { } #[test] - fn type_mismatch_on_block() { - cov_mark::check!(type_mismatch_on_block); + fn type_mismatch_range_adjustment() { + cov_mark::check!(type_mismatch_range_adjustment); check_diagnostics( r#" fn f() -> i32 { @@ -636,9 +631,15 @@ fn f() -> i32 { } //^ error: expected i32, found () -fn h() -> i32 { +fn g() -> i32 { while true {} } //^^^^^ error: expected i32, found () + +struct S; +impl S { fn foo(&self) -> &S { self } } +fn h() { + let _: i32 = S.foo().foo().foo(); +} //^^^ error: expected i32, found &S "#, ); } |
