aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-09-02 15:07:17 +0100
committerGitHub <[email protected]>2019-09-02 15:07:17 +0100
commitf39f72db57a78b7f92f99377be0e05ec3db6dc98 (patch)
tree789f733506520663e6cb5f99eec7d56c1a443831 /crates/ra_hir/src/code_model.rs
parent6ecb36740a81445cf103577c3f9e9e6f831d0a1b (diff)
parentf92177cfb5088809892455262841e24cf1ecf5b6 (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.rs')
-rw-r--r--crates/ra_hir/src/code_model.rs49
1 files changed, 37 insertions, 12 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 66a58efed..f7efc1b66 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -510,18 +510,6 @@ pub enum DefWithBody {
510impl_froms!(DefWithBody: Function, Const, Static); 510impl_froms!(DefWithBody: Function, Const, Static);
511 511
512impl DefWithBody { 512impl DefWithBody {
513 pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> {
514 db.infer(self)
515 }
516
517 pub fn body(self, db: &impl HirDatabase) -> Arc<Body> {
518 db.body_hir(self)
519 }
520
521 pub fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> {
522 db.body_with_source_map(self).1
523 }
524
525 /// Builds a resolver for code inside this item. 513 /// Builds a resolver for code inside this item.
526 pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver { 514 pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver {
527 match self { 515 match self {
@@ -532,6 +520,43 @@ impl DefWithBody {
532 } 520 }
533} 521}
534 522
523pub trait HasBody: Copy {
524 fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult>;
525 fn body(self, db: &impl HirDatabase) -> Arc<Body>;
526 fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap>;
527}
528
529impl<T> HasBody for T
530where
531 T: Into<DefWithBody> + Copy + HasSource,
532{
533 fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> {
534 db.infer(self.into())
535 }
536
537 fn body(self, db: &impl HirDatabase) -> Arc<Body> {
538 db.body_hir(self.into())
539 }
540
541 fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> {
542 db.body_with_source_map(self.into()).1
543 }
544}
545
546impl HasBody for DefWithBody {
547 fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> {
548 db.infer(self)
549 }
550
551 fn body(self, db: &impl HirDatabase) -> Arc<Body> {
552 db.body_hir(self)
553 }
554
555 fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> {
556 db.body_with_source_map(self).1
557 }
558}
559
535#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 560#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
536pub struct Function { 561pub struct Function {
537 pub(crate) id: FunctionId, 562 pub(crate) id: FunctionId,