diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-09-02 15:07:17 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-09-02 15:07:17 +0100 |
commit | f39f72db57a78b7f92f99377be0e05ec3db6dc98 (patch) | |
tree | 789f733506520663e6cb5f99eec7d56c1a443831 /crates/ra_hir/src/code_model | |
parent | 6ecb36740a81445cf103577c3f9e9e6f831d0a1b (diff) | |
parent | f92177cfb5088809892455262841e24cf1ecf5b6 (diff) |
Merge #1737
1737: Report type mismatches in analysis-stats r=matklad a=flodiebold
Only the number usually; each one individually when running with `-v`.
Getting the file/line locations for the exprs was really annoying and I had to make some stuff public (that I didn't remember why it would be `pub(crate)`); maybe I missed some easier way? It would be nice to have some general way for mapping locations :thinking:
This reports 1768 mismatches on RA currently; from skimming, this seems to be mostly various kinds of coercions, though there were also some other things.
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/code_model')
-rw-r--r-- | crates/ra_hir/src/code_model/src.rs | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs index 32bd9c661..e5bae16ab 100644 --- a/crates/ra_hir/src/code_model/src.rs +++ b/crates/ra_hir/src/code_model/src.rs | |||
@@ -1,9 +1,9 @@ | |||
1 | use ra_syntax::ast; | 1 | use ra_syntax::ast::{self, AstNode}; |
2 | 2 | ||
3 | use crate::{ | 3 | use crate::{ |
4 | ids::AstItemDef, AstDatabase, Const, DefDatabase, Enum, EnumVariant, FieldSource, Function, | 4 | ids::AstItemDef, AstDatabase, Const, DefDatabase, Enum, EnumVariant, FieldSource, Function, |
5 | HirFileId, MacroDef, Module, ModuleSource, Static, Struct, StructField, Trait, TypeAlias, | 5 | HasBody, HirDatabase, HirFileId, MacroDef, Module, ModuleSource, Static, Struct, StructField, |
6 | Union, | 6 | Trait, TypeAlias, Union, |
7 | }; | 7 | }; |
8 | 8 | ||
9 | pub struct Source<T> { | 9 | pub struct Source<T> { |
@@ -108,3 +108,27 @@ impl HasSource for MacroDef { | |||
108 | Source { file_id: self.id.0.file_id(), ast: self.id.0.to_node(db) } | 108 | Source { file_id: self.id.0.file_id(), ast: self.id.0.to_node(db) } |
109 | } | 109 | } |
110 | } | 110 | } |
111 | |||
112 | pub trait HasBodySource: HasBody + HasSource | ||
113 | where | ||
114 | Self::Ast: AstNode, | ||
115 | { | ||
116 | fn expr_source( | ||
117 | self, | ||
118 | db: &impl HirDatabase, | ||
119 | expr_id: crate::expr::ExprId, | ||
120 | ) -> Option<Source<ast::Expr>> { | ||
121 | let source_map = self.body_source_map(db); | ||
122 | let expr_syntax = source_map.expr_syntax(expr_id)?; | ||
123 | let source = self.source(db); | ||
124 | let node = expr_syntax.to_node(&source.ast.syntax()); | ||
125 | ast::Expr::cast(node).map(|ast| Source { file_id: source.file_id, ast }) | ||
126 | } | ||
127 | } | ||
128 | |||
129 | impl<T> HasBodySource for T | ||
130 | where | ||
131 | T: HasBody + HasSource, | ||
132 | T::Ast: AstNode, | ||
133 | { | ||
134 | } | ||