aboutsummaryrefslogtreecommitdiff
path: root/crates/rust-analyzer
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2020-02-29 14:31:07 +0000
committerFlorian Diebold <[email protected]>2020-02-29 14:31:07 +0000
commit5fe220b9873d587188adae63fa205481a9aae9ce (patch)
tree51599b3664e16cd5f0ef288dac924330c5cd0af0 /crates/rust-analyzer
parent0ec7f760fcd8bb9c2273e004468faa2a8cbeb29d (diff)
Fix a common false-positive type mismatch
E.g. for `&{ some_string() }` in a context where a `&str` is expected, we reported a mismatch inside the block. The problem is that we're passing an expectation of `str` down, but the expectation is more of a hint in this case. There's a long comment in rustc about this, which I just copied. Also, fix reported location for type mismatches in macros.
Diffstat (limited to 'crates/rust-analyzer')
-rw-r--r--crates/rust-analyzer/src/cli/analysis_stats.rs24
1 files changed, 15 insertions, 9 deletions
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs
index 4d59db1ee..d70d34bdc 100644
--- a/crates/rust-analyzer/src/cli/analysis_stats.rs
+++ b/crates/rust-analyzer/src/cli/analysis_stats.rs
@@ -4,8 +4,8 @@
4use std::{collections::HashSet, fmt::Write, path::Path, time::Instant}; 4use std::{collections::HashSet, fmt::Write, path::Path, time::Instant};
5 5
6use hir::{ 6use hir::{
7 db::{DefDatabase, HirDatabase}, 7 db::{AstDatabase, DefDatabase, HirDatabase},
8 AssocItem, Crate, HasSource, HirDisplay, ModuleDef, 8 original_range, AssocItem, Crate, HasSource, HirDisplay, ModuleDef,
9}; 9};
10use hir_def::FunctionId; 10use hir_def::FunctionId;
11use hir_ty::{Ty, TypeWalk}; 11use hir_ty::{Ty, TypeWalk};
@@ -188,13 +188,19 @@ pub fn analysis_stats(
188 let src = sm.expr_syntax(expr_id); 188 let src = sm.expr_syntax(expr_id);
189 if let Some(src) = src { 189 if let Some(src) = src {
190 // FIXME: it might be nice to have a function (on Analysis?) that goes from Source<T> -> (LineCol, LineCol) directly 190 // FIXME: it might be nice to have a function (on Analysis?) that goes from Source<T> -> (LineCol, LineCol) directly
191 let original_file = src.file_id.original_file(db); 191 // But also, we should just turn the type mismatches into diagnostics and provide these
192 let path = db.file_relative_path(original_file); 192 let root = db.parse_or_expand(src.file_id).unwrap();
193 let line_index = host.analysis().file_line_index(original_file).unwrap(); 193 let node = src.map(|e| {
194 let text_range = src.value.either( 194 e.either(
195 |it| it.syntax_node_ptr().range(), 195 |p| p.to_node(&root).syntax().clone(),
196 |it| it.syntax_node_ptr().range(), 196 |p| p.to_node(&root).syntax().clone(),
197 ); 197 )
198 });
199 let original_range = original_range(db, node.as_ref());
200 let path = db.file_relative_path(original_range.file_id);
201 let line_index =
202 host.analysis().file_line_index(original_range.file_id).unwrap();
203 let text_range = original_range.range;
198 let (start, end) = ( 204 let (start, end) = (
199 line_index.line_col(text_range.start()), 205 line_index.line_col(text_range.start()),
200 line_index.line_col(text_range.end()), 206 line_index.line_col(text_range.end()),