aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_assists/src/fill_match_arms.rs4
-rw-r--r--crates/ra_hir/src/code_model_api.rs16
-rw-r--r--crates/ra_hir/src/code_model_impl/module.rs2
-rw-r--r--crates/ra_hir/src/db.rs25
-rw-r--r--crates/ra_hir/src/expr.rs93
-rw-r--r--crates/ra_hir/src/expr/scope.rs36
-rw-r--r--crates/ra_hir/src/lib.rs2
-rw-r--r--crates/ra_hir/src/nameres.rs2
-rw-r--r--crates/ra_hir/src/nameres/lower.rs13
-rw-r--r--crates/ra_hir/src/source_binder.rs2
-rw-r--r--crates/ra_hir/src/ty.rs31
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__bug_484.snap12
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__bug_585.snap15
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__bug_651.snap13
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_adt_pattern.snap32
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_array.snap65
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_associated_const.snap14
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_associated_method_enum.snap20
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_associated_method_generics.snap16
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_associated_method_struct.snap16
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_associated_method_with_modules.snap23
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_backwards.snap27
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_basics.snap20
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_binary_op.snap57
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_const.snap14
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_enum.snap11
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_field_autoderef.snap50
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_function_generics.snap21
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_generic_chain.snap36
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_generics_in_patterns.snap24
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_impl_generics.snap39
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_impl_generics_with_autoderef.snap16
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_in_elseif.snap17
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_inherent_method.snap25
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_let.snap14
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_literals.snap19
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_nested_generics_crash.snap12
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_paths.snap16
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_pattern.snap54
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_refs.snap30
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_self.snap17
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_static.snap16
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_1.snap13
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_2.snap14
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_3.snap13
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_4.snap16
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_5.snap30
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_struct.snap23
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_struct_generics.snap22
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_tuple.snap34
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_tuple_struct_generics.snap23
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_type_alias.snap23
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_type_param.snap26
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_unary_op.snap48
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__no_panic_on_field_of_enum.snap11
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__recursive_vars.snap14
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__recursive_vars_2.snap21
-rw-r--r--crates/ra_hir/src/ty/tests.rs1489
-rw-r--r--crates/ra_ide_api/src/change.rs5
-rw-r--r--crates/ra_ide_api/src/completion/complete_dot.rs4
-rw-r--r--crates/ra_ide_api/src/completion/complete_struct_literal.rs4
-rw-r--r--crates/ra_ide_api/src/goto_definition.rs17
-rw-r--r--crates/ra_ide_api/src/hover.rs43
-rw-r--r--crates/ra_ide_api/src/lib.rs7
-rw-r--r--crates/ra_ide_api/src/syntax_tree.rs87
-rw-r--r--crates/ra_ide_api/tests/test/main.rs254
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs4
-rw-r--r--crates/ra_lsp_server/src/req.rs1
68 files changed, 1769 insertions, 1464 deletions
diff --git a/crates/ra_assists/src/fill_match_arms.rs b/crates/ra_assists/src/fill_match_arms.rs
index 30020b56e..6a22b0af5 100644
--- a/crates/ra_assists/src/fill_match_arms.rs
+++ b/crates/ra_assists/src/fill_match_arms.rs
@@ -23,8 +23,8 @@ pub(crate) fn fill_match_arms(mut ctx: AssistCtx<impl HirDatabase>) -> Option<As
23 let function = 23 let function =
24 source_binder::function_from_child_node(ctx.db, ctx.frange.file_id, expr.syntax())?; 24 source_binder::function_from_child_node(ctx.db, ctx.frange.file_id, expr.syntax())?;
25 let infer_result = function.infer(ctx.db); 25 let infer_result = function.infer(ctx.db);
26 let syntax_mapping = function.body_syntax_mapping(ctx.db); 26 let source_map = function.body_source_map(ctx.db);
27 let node_expr = syntax_mapping.node_expr(expr)?; 27 let node_expr = source_map.node_expr(expr)?;
28 let match_expr_ty = infer_result[node_expr].clone(); 28 let match_expr_ty = infer_result[node_expr].clone();
29 let enum_def = match match_expr_ty { 29 let enum_def = match match_expr_ty {
30 Ty::Adt { def_id: AdtDef::Enum(e), .. } => e, 30 Ty::Adt { def_id: AdtDef::Enum(e), .. } => e,
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs
index da0f1ec94..3ac146950 100644
--- a/crates/ra_hir/src/code_model_api.rs
+++ b/crates/ra_hir/src/code_model_api.rs
@@ -5,11 +5,11 @@ use ra_db::{CrateId, SourceRootId, Edition};
5use ra_syntax::{ast::self, TreeArc, SyntaxNode}; 5use ra_syntax::{ast::self, TreeArc, SyntaxNode};
6 6
7use crate::{ 7use crate::{
8 Name, ScopesWithSyntaxMapping, Ty, HirFileId, 8 Name, ScopesWithSourceMap, Ty, HirFileId,
9 HirDatabase, PersistentHirDatabase, 9 HirDatabase, PersistentHirDatabase,
10 type_ref::TypeRef, 10 type_ref::TypeRef,
11 nameres::{ModuleScope, Namespace, lower::ImportId}, 11 nameres::{ModuleScope, Namespace, lower::ImportId},
12 expr::{Body, BodySyntaxMapping}, 12 expr::{Body, BodySourceMap},
13 ty::InferenceResult, 13 ty::InferenceResult,
14 adt::{EnumVariantId, StructFieldId, VariantDef}, 14 adt::{EnumVariantId, StructFieldId, VariantDef},
15 generics::GenericParams, 15 generics::GenericParams,
@@ -191,7 +191,7 @@ impl Module {
191 } 191 }
192 192
193 pub fn declarations(self, db: &impl HirDatabase) -> Vec<ModuleDef> { 193 pub fn declarations(self, db: &impl HirDatabase) -> Vec<ModuleDef> {
194 let (lowered_module, _) = db.lower_module(self); 194 let lowered_module = db.lower_module(self);
195 lowered_module 195 lowered_module
196 .declarations 196 .declarations
197 .values() 197 .values()
@@ -483,8 +483,8 @@ impl Function {
483 self.signature(db).name.clone() 483 self.signature(db).name.clone()
484 } 484 }
485 485
486 pub fn body_syntax_mapping(&self, db: &impl HirDatabase) -> Arc<BodySyntaxMapping> { 486 pub fn body_source_map(&self, db: &impl HirDatabase) -> Arc<BodySourceMap> {
487 db.body_syntax_mapping(*self) 487 db.body_with_source_map(*self).1
488 } 488 }
489 489
490 pub fn body(&self, db: &impl HirDatabase) -> Arc<Body> { 490 pub fn body(&self, db: &impl HirDatabase) -> Arc<Body> {
@@ -495,10 +495,10 @@ impl Function {
495 db.type_for_def((*self).into(), Namespace::Values) 495 db.type_for_def((*self).into(), Namespace::Values)
496 } 496 }
497 497
498 pub fn scopes(&self, db: &impl HirDatabase) -> ScopesWithSyntaxMapping { 498 pub fn scopes(&self, db: &impl HirDatabase) -> ScopesWithSourceMap {
499 let scopes = db.expr_scopes(*self); 499 let scopes = db.expr_scopes(*self);
500 let syntax_mapping = db.body_syntax_mapping(*self); 500 let source_map = db.body_with_source_map(*self).1;
501 ScopesWithSyntaxMapping { scopes, syntax_mapping } 501 ScopesWithSourceMap { scopes, source_map }
502 } 502 }
503 503
504 pub fn signature(&self, db: &impl HirDatabase) -> Arc<FnSignature> { 504 pub fn signature(&self, db: &impl HirDatabase) -> Arc<FnSignature> {
diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs
index 2d3058afd..437f96942 100644
--- a/crates/ra_hir/src/code_model_impl/module.rs
+++ b/crates/ra_hir/src/code_model_impl/module.rs
@@ -47,7 +47,7 @@ impl Module {
47 db: &impl HirDatabase, 47 db: &impl HirDatabase,
48 import: ImportId, 48 import: ImportId,
49 ) -> TreeArc<ast::PathSegment> { 49 ) -> TreeArc<ast::PathSegment> {
50 let source_map = db.lower_module_source_map(*self); 50 let (_, source_map) = db.lower_module_with_source_map(*self);
51 let (_, source) = self.definition_source(db); 51 let (_, source) = self.definition_source(db);
52 source_map.get(&source, import) 52 source_map.get(&source, import)
53 } 53 }
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index ec848f1b2..21d22aa7f 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -48,14 +48,14 @@ pub trait PersistentHirDatabase: SourceDatabase + AsRef<HirInterner> {
48 delc_id: Option<SourceFileItemId>, 48 delc_id: Option<SourceFileItemId>,
49 ) -> Arc<Vec<crate::module_tree::Submodule>>; 49 ) -> Arc<Vec<crate::module_tree::Submodule>>;
50 50
51 #[salsa::invoke(crate::nameres::lower::LoweredModule::lower_module_query)] 51 #[salsa::invoke(crate::nameres::lower::LoweredModule::lower_module_with_source_map_query)]
52 fn lower_module(&self, module: Module) -> (Arc<LoweredModule>, Arc<ImportSourceMap>); 52 fn lower_module_with_source_map(
53 53 &self,
54 #[salsa::invoke(crate::nameres::lower::LoweredModule::lower_module_module_query)] 54 module: Module,
55 fn lower_module_module(&self, module: Module) -> Arc<LoweredModule>; 55 ) -> (Arc<LoweredModule>, Arc<ImportSourceMap>);
56 56
57 #[salsa::invoke(crate::nameres::lower::LoweredModule::lower_module_source_map_query)] 57 #[salsa::invoke(crate::nameres::lower::LoweredModule::lower_module_query)]
58 fn lower_module_source_map(&self, module: Module) -> Arc<ImportSourceMap>; 58 fn lower_module(&self, module: Module) -> Arc<LoweredModule>;
59 59
60 #[salsa::invoke(crate::nameres::ItemMap::item_map_query)] 60 #[salsa::invoke(crate::nameres::ItemMap::item_map_query)]
61 fn item_map(&self, krate: Crate) -> Arc<ItemMap>; 61 fn item_map(&self, krate: Crate) -> Arc<ItemMap>;
@@ -105,11 +105,14 @@ pub trait HirDatabase: PersistentHirDatabase {
105 #[salsa::invoke(crate::ty::type_for_field)] 105 #[salsa::invoke(crate::ty::type_for_field)]
106 fn type_for_field(&self, field: StructField) -> Ty; 106 fn type_for_field(&self, field: StructField) -> Ty;
107 107
108 #[salsa::invoke(crate::expr::body_hir)] 108 #[salsa::invoke(crate::expr::body_with_source_map_query)]
109 fn body_hir(&self, func: Function) -> Arc<crate::expr::Body>; 109 fn body_with_source_map(
110 &self,
111 func: Function,
112 ) -> (Arc<crate::expr::Body>, Arc<crate::expr::BodySourceMap>);
110 113
111 #[salsa::invoke(crate::expr::body_syntax_mapping)] 114 #[salsa::invoke(crate::expr::body_hir_query)]
112 fn body_syntax_mapping(&self, func: Function) -> Arc<crate::expr::BodySyntaxMapping>; 115 fn body_hir(&self, func: Function) -> Arc<crate::expr::Body>;
113 116
114 #[salsa::invoke(crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query)] 117 #[salsa::invoke(crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query)]
115 fn impls_in_crate(&self, krate: Crate) -> Arc<CrateImplBlocks>; 118 fn impls_in_crate(&self, krate: Crate) -> Arc<CrateImplBlocks>;
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs
index aa39d28ed..6c7489e63 100644
--- a/crates/ra_hir/src/expr.rs
+++ b/crates/ra_hir/src/expr.rs
@@ -16,7 +16,7 @@ use crate::{
16}; 16};
17use crate::{ path::GenericArgs, ty::primitive::{UintTy, UncertainIntTy, UncertainFloatTy}}; 17use crate::{ path::GenericArgs, ty::primitive::{UintTy, UncertainIntTy, UncertainFloatTy}};
18 18
19pub use self::scope::{ExprScopes, ScopesWithSyntaxMapping, ScopeEntryWithSyntax}; 19pub use self::scope::{ExprScopes, ScopesWithSourceMap, ScopeEntryWithSyntax};
20 20
21pub(crate) mod scope; 21pub(crate) mod scope;
22 22
@@ -48,13 +48,12 @@ pub struct Body {
48/// expression containing it; but for type inference etc., we want to operate on 48/// expression containing it; but for type inference etc., we want to operate on
49/// a structure that is agnostic to the actual positions of expressions in the 49/// a structure that is agnostic to the actual positions of expressions in the
50/// file, so that we don't recompute types whenever some whitespace is typed. 50/// file, so that we don't recompute types whenever some whitespace is typed.
51#[derive(Debug, Eq, PartialEq)] 51#[derive(Default, Debug, Eq, PartialEq)]
52pub struct BodySyntaxMapping { 52pub struct BodySourceMap {
53 body: Arc<Body>, 53 expr_map: FxHashMap<SyntaxNodePtr, ExprId>,
54 expr_syntax_mapping: FxHashMap<SyntaxNodePtr, ExprId>, 54 expr_map_back: ArenaMap<ExprId, SyntaxNodePtr>,
55 expr_syntax_mapping_back: ArenaMap<ExprId, SyntaxNodePtr>, 55 pat_map: FxHashMap<SyntaxNodePtr, PatId>,
56 pat_syntax_mapping: FxHashMap<SyntaxNodePtr, PatId>, 56 pat_map_back: ArenaMap<PatId, SyntaxNodePtr>,
57 pat_syntax_mapping_back: ArenaMap<PatId, SyntaxNodePtr>,
58} 57}
59 58
60impl Body { 59impl Body {
@@ -77,10 +76,6 @@ impl Body {
77 pub fn pats(&self) -> impl Iterator<Item = (PatId, &Pat)> { 76 pub fn pats(&self) -> impl Iterator<Item = (PatId, &Pat)> {
78 self.pats.iter() 77 self.pats.iter()
79 } 78 }
80
81 pub fn syntax_mapping(&self, db: &impl HirDatabase) -> Arc<BodySyntaxMapping> {
82 db.body_syntax_mapping(self.owner)
83 }
84} 79}
85 80
86// needs arbitrary_self_types to be a method... or maybe move to the def? 81// needs arbitrary_self_types to be a method... or maybe move to the def?
@@ -119,33 +114,29 @@ impl Index<PatId> for Body {
119 } 114 }
120} 115}
121 116
122impl BodySyntaxMapping { 117impl BodySourceMap {
123 pub fn expr_syntax(&self, expr: ExprId) -> Option<SyntaxNodePtr> { 118 pub fn expr_syntax(&self, expr: ExprId) -> Option<SyntaxNodePtr> {
124 self.expr_syntax_mapping_back.get(expr).cloned() 119 self.expr_map_back.get(expr).cloned()
125 } 120 }
126 121
127 pub fn syntax_expr(&self, ptr: SyntaxNodePtr) -> Option<ExprId> { 122 pub fn syntax_expr(&self, ptr: SyntaxNodePtr) -> Option<ExprId> {
128 self.expr_syntax_mapping.get(&ptr).cloned() 123 self.expr_map.get(&ptr).cloned()
129 } 124 }
130 125
131 pub fn node_expr(&self, node: &ast::Expr) -> Option<ExprId> { 126 pub fn node_expr(&self, node: &ast::Expr) -> Option<ExprId> {
132 self.expr_syntax_mapping.get(&SyntaxNodePtr::new(node.syntax())).cloned() 127 self.expr_map.get(&SyntaxNodePtr::new(node.syntax())).cloned()
133 } 128 }
134 129
135 pub fn pat_syntax(&self, pat: PatId) -> Option<SyntaxNodePtr> { 130 pub fn pat_syntax(&self, pat: PatId) -> Option<SyntaxNodePtr> {
136 self.pat_syntax_mapping_back.get(pat).cloned() 131 self.pat_map_back.get(pat).cloned()
137 } 132 }
138 133
139 pub fn syntax_pat(&self, ptr: SyntaxNodePtr) -> Option<PatId> { 134 pub fn syntax_pat(&self, ptr: SyntaxNodePtr) -> Option<PatId> {
140 self.pat_syntax_mapping.get(&ptr).cloned() 135 self.pat_map.get(&ptr).cloned()
141 } 136 }
142 137
143 pub fn node_pat(&self, node: &ast::Pat) -> Option<PatId> { 138 pub fn node_pat(&self, node: &ast::Pat) -> Option<PatId> {
144 self.pat_syntax_mapping.get(&SyntaxNodePtr::new(node.syntax())).cloned() 139 self.pat_map.get(&SyntaxNodePtr::new(node.syntax())).cloned()
145 }
146
147 pub fn body(&self) -> &Arc<Body> {
148 &self.body
149 } 140 }
150} 141}
151 142
@@ -467,18 +458,11 @@ impl Pat {
467 458
468// Queries 459// Queries
469 460
470pub(crate) fn body_hir(db: &impl HirDatabase, func: Function) -> Arc<Body> {
471 Arc::clone(&body_syntax_mapping(db, func).body)
472}
473
474struct ExprCollector { 461struct ExprCollector {
475 owner: Function, 462 owner: Function,
476 exprs: Arena<ExprId, Expr>, 463 exprs: Arena<ExprId, Expr>,
477 pats: Arena<PatId, Pat>, 464 pats: Arena<PatId, Pat>,
478 expr_syntax_mapping: FxHashMap<SyntaxNodePtr, ExprId>, 465 source_map: BodySourceMap,
479 expr_syntax_mapping_back: ArenaMap<ExprId, SyntaxNodePtr>,
480 pat_syntax_mapping: FxHashMap<SyntaxNodePtr, PatId>,
481 pat_syntax_mapping_back: ArenaMap<PatId, SyntaxNodePtr>,
482 params: Vec<PatId>, 466 params: Vec<PatId>,
483 body_expr: Option<ExprId>, 467 body_expr: Option<ExprId>,
484} 468}
@@ -489,10 +473,7 @@ impl ExprCollector {
489 owner, 473 owner,
490 exprs: Arena::default(), 474 exprs: Arena::default(),
491 pats: Arena::default(), 475 pats: Arena::default(),
492 expr_syntax_mapping: FxHashMap::default(), 476 source_map: BodySourceMap::default(),
493 expr_syntax_mapping_back: ArenaMap::default(),
494 pat_syntax_mapping: FxHashMap::default(),
495 pat_syntax_mapping_back: ArenaMap::default(),
496 params: Vec::new(), 477 params: Vec::new(),
497 body_expr: None, 478 body_expr: None,
498 } 479 }
@@ -500,15 +481,15 @@ impl ExprCollector {
500 481
501 fn alloc_expr(&mut self, expr: Expr, syntax_ptr: SyntaxNodePtr) -> ExprId { 482 fn alloc_expr(&mut self, expr: Expr, syntax_ptr: SyntaxNodePtr) -> ExprId {
502 let id = self.exprs.alloc(expr); 483 let id = self.exprs.alloc(expr);
503 self.expr_syntax_mapping.insert(syntax_ptr, id); 484 self.source_map.expr_map.insert(syntax_ptr, id);
504 self.expr_syntax_mapping_back.insert(id, syntax_ptr); 485 self.source_map.expr_map_back.insert(id, syntax_ptr);
505 id 486 id
506 } 487 }
507 488
508 fn alloc_pat(&mut self, pat: Pat, syntax_ptr: SyntaxNodePtr) -> PatId { 489 fn alloc_pat(&mut self, pat: Pat, syntax_ptr: SyntaxNodePtr) -> PatId {
509 let id = self.pats.alloc(pat); 490 let id = self.pats.alloc(pat);
510 self.pat_syntax_mapping.insert(syntax_ptr, id); 491 self.source_map.pat_map.insert(syntax_ptr, id);
511 self.pat_syntax_mapping_back.insert(id, syntax_ptr); 492 self.source_map.pat_map_back.insert(id, syntax_ptr);
512 id 493 id
513 } 494 }
514 495
@@ -639,7 +620,7 @@ impl ExprCollector {
639 ast::ExprKind::ParenExpr(e) => { 620 ast::ExprKind::ParenExpr(e) => {
640 let inner = self.collect_expr_opt(e.expr()); 621 let inner = self.collect_expr_opt(e.expr());
641 // make the paren expr point to the inner expression as well 622 // make the paren expr point to the inner expression as well
642 self.expr_syntax_mapping.insert(syntax_ptr, inner); 623 self.source_map.expr_map.insert(syntax_ptr, inner);
643 inner 624 inner
644 } 625 }
645 ast::ExprKind::ReturnExpr(e) => { 626 ast::ExprKind::ReturnExpr(e) => {
@@ -660,9 +641,11 @@ impl ExprCollector {
660 } else if let Some(nr) = field.name_ref() { 641 } else if let Some(nr) = field.name_ref() {
661 // field shorthand 642 // field shorthand
662 let id = self.exprs.alloc(Expr::Path(Path::from_name_ref(nr))); 643 let id = self.exprs.alloc(Expr::Path(Path::from_name_ref(nr)));
663 self.expr_syntax_mapping 644 self.source_map
645 .expr_map
664 .insert(SyntaxNodePtr::new(nr.syntax()), id); 646 .insert(SyntaxNodePtr::new(nr.syntax()), id);
665 self.expr_syntax_mapping_back 647 self.source_map
648 .expr_map_back
666 .insert(id, SyntaxNodePtr::new(nr.syntax())); 649 .insert(id, SyntaxNodePtr::new(nr.syntax()));
667 id 650 id
668 } else { 651 } else {
@@ -910,7 +893,7 @@ impl ExprCollector {
910 self.body_expr = Some(body); 893 self.body_expr = Some(body);
911 } 894 }
912 895
913 fn into_body_syntax_mapping(self) -> BodySyntaxMapping { 896 fn finish(self) -> (Body, BodySourceMap) {
914 let body = Body { 897 let body = Body {
915 owner: self.owner, 898 owner: self.owner,
916 exprs: self.exprs, 899 exprs: self.exprs,
@@ -918,28 +901,30 @@ impl ExprCollector {
918 params: self.params, 901 params: self.params,
919 body_expr: self.body_expr.expect("A body should have been collected"), 902 body_expr: self.body_expr.expect("A body should have been collected"),
920 }; 903 };
921 BodySyntaxMapping { 904 (body, self.source_map)
922 body: Arc::new(body),
923 expr_syntax_mapping: self.expr_syntax_mapping,
924 expr_syntax_mapping_back: self.expr_syntax_mapping_back,
925 pat_syntax_mapping: self.pat_syntax_mapping,
926 pat_syntax_mapping_back: self.pat_syntax_mapping_back,
927 }
928 } 905 }
929} 906}
930 907
931pub(crate) fn body_syntax_mapping(db: &impl HirDatabase, func: Function) -> Arc<BodySyntaxMapping> { 908pub(crate) fn body_with_source_map_query(
909 db: &impl HirDatabase,
910 func: Function,
911) -> (Arc<Body>, Arc<BodySourceMap>) {
932 let mut collector = ExprCollector::new(func); 912 let mut collector = ExprCollector::new(func);
933 913
934 // TODO: consts, etc. 914 // TODO: consts, etc.
935 collector.collect_fn_body(&func.source(db).1); 915 collector.collect_fn_body(&func.source(db).1);
936 916
937 Arc::new(collector.into_body_syntax_mapping()) 917 let (body, source_map) = collector.finish();
918 (Arc::new(body), Arc::new(source_map))
919}
920
921pub(crate) fn body_hir_query(db: &impl HirDatabase, func: Function) -> Arc<Body> {
922 db.body_with_source_map(func).0
938} 923}
939 924
940#[cfg(test)] 925#[cfg(test)]
941pub(crate) fn collect_fn_body_syntax(function: Function, node: &ast::FnDef) -> BodySyntaxMapping { 926fn collect_fn_body_syntax(function: Function, node: &ast::FnDef) -> (Body, BodySourceMap) {
942 let mut collector = ExprCollector::new(function); 927 let mut collector = ExprCollector::new(function);
943 collector.collect_fn_body(node); 928 collector.collect_fn_body(node);
944 collector.into_body_syntax_mapping() 929 collector.finish()
945} 930}
diff --git a/crates/ra_hir/src/expr/scope.rs b/crates/ra_hir/src/expr/scope.rs
index bb8d50db8..81fbc509e 100644
--- a/crates/ra_hir/src/expr/scope.rs
+++ b/crates/ra_hir/src/expr/scope.rs
@@ -11,7 +11,7 @@ use ra_arena::{Arena, RawId, impl_arena_id};
11 11
12use crate::{ 12use crate::{
13 Name, AsName, Function, 13 Name, AsName, Function,
14 expr::{PatId, ExprId, Pat, Expr, Body, Statement, BodySyntaxMapping}, 14 expr::{PatId, ExprId, Pat, Expr, Body, Statement, BodySourceMap},
15 HirDatabase, 15 HirDatabase,
16}; 16};
17 17
@@ -108,8 +108,8 @@ impl ExprScopes {
108} 108}
109 109
110#[derive(Debug, Clone, PartialEq, Eq)] 110#[derive(Debug, Clone, PartialEq, Eq)]
111pub struct ScopesWithSyntaxMapping { 111pub struct ScopesWithSourceMap {
112 pub syntax_mapping: Arc<BodySyntaxMapping>, 112 pub source_map: Arc<BodySourceMap>,
113 pub scopes: Arc<ExprScopes>, 113 pub scopes: Arc<ExprScopes>,
114} 114}
115 115
@@ -129,7 +129,7 @@ impl ScopeEntryWithSyntax {
129 } 129 }
130} 130}
131 131
132impl ScopesWithSyntaxMapping { 132impl ScopesWithSourceMap {
133 fn scope_chain<'a>(&'a self, node: &SyntaxNode) -> impl Iterator<Item = ScopeId> + 'a { 133 fn scope_chain<'a>(&'a self, node: &SyntaxNode) -> impl Iterator<Item = ScopeId> + 'a {
134 generate(self.scope_for(node), move |&scope| self.scopes.scopes[scope].parent) 134 generate(self.scope_for(node), move |&scope| self.scopes.scopes[scope].parent)
135 } 135 }
@@ -138,7 +138,7 @@ impl ScopesWithSyntaxMapping {
138 self.scopes 138 self.scopes
139 .scope_for 139 .scope_for
140 .iter() 140 .iter()
141 .filter_map(|(id, scope)| Some((self.syntax_mapping.expr_syntax(*id)?, scope))) 141 .filter_map(|(id, scope)| Some((self.source_map.expr_syntax(*id)?, scope)))
142 // find containing scope 142 // find containing scope
143 .min_by_key(|(ptr, _scope)| { 143 .min_by_key(|(ptr, _scope)| {
144 (!(ptr.range().start() <= offset && offset <= ptr.range().end()), ptr.range().len()) 144 (!(ptr.range().start() <= offset && offset <= ptr.range().end()), ptr.range().len())
@@ -155,7 +155,7 @@ impl ScopesWithSyntaxMapping {
155 .scopes 155 .scopes
156 .scope_for 156 .scope_for
157 .iter() 157 .iter()
158 .filter_map(|(id, scope)| Some((self.syntax_mapping.expr_syntax(*id)?, scope))) 158 .filter_map(|(id, scope)| Some((self.source_map.expr_syntax(*id)?, scope)))
159 .map(|(ptr, scope)| (ptr.range(), scope)) 159 .map(|(ptr, scope)| (ptr.range(), scope))
160 .filter(|(range, _)| range.start() <= offset && range.is_subrange(&r) && *range != r); 160 .filter(|(range, _)| range.start() <= offset && range.is_subrange(&r) && *range != r);
161 161
@@ -185,7 +185,7 @@ impl ScopesWithSyntaxMapping {
185 ret.and_then(|entry| { 185 ret.and_then(|entry| {
186 Some(ScopeEntryWithSyntax { 186 Some(ScopeEntryWithSyntax {
187 name: entry.name().clone(), 187 name: entry.name().clone(),
188 ptr: self.syntax_mapping.pat_syntax(entry.pat())?, 188 ptr: self.source_map.pat_syntax(entry.pat())?,
189 }) 189 })
190 }) 190 })
191 } 191 }
@@ -211,7 +211,7 @@ impl ScopesWithSyntaxMapping {
211 pub fn scope_for(&self, node: &SyntaxNode) -> Option<ScopeId> { 211 pub fn scope_for(&self, node: &SyntaxNode) -> Option<ScopeId> {
212 node.ancestors() 212 node.ancestors()
213 .map(SyntaxNodePtr::new) 213 .map(SyntaxNodePtr::new)
214 .filter_map(|ptr| self.syntax_mapping.syntax_expr(ptr)) 214 .filter_map(|ptr| self.source_map.syntax_expr(ptr))
215 .find_map(|it| self.scopes.scope_for(it)) 215 .find_map(|it| self.scopes.scope_for(it))
216 } 216 }
217} 217}
@@ -316,12 +316,10 @@ mod tests {
316 let marker: &ast::PathExpr = find_node_at_offset(file.syntax(), off).unwrap(); 316 let marker: &ast::PathExpr = find_node_at_offset(file.syntax(), off).unwrap();
317 let fn_def: &ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap(); 317 let fn_def: &ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap();
318 let irrelevant_function = Function { id: crate::ids::FunctionId::from_raw(0.into()) }; 318 let irrelevant_function = Function { id: crate::ids::FunctionId::from_raw(0.into()) };
319 let body_hir = expr::collect_fn_body_syntax(irrelevant_function, fn_def); 319 let (body, source_map) = expr::collect_fn_body_syntax(irrelevant_function, fn_def);
320 let scopes = ExprScopes::new(Arc::clone(body_hir.body())); 320 let scopes = ExprScopes::new(Arc::new(body));
321 let scopes = ScopesWithSyntaxMapping { 321 let scopes =
322 scopes: Arc::new(scopes), 322 ScopesWithSourceMap { scopes: Arc::new(scopes), source_map: Arc::new(source_map) };
323 syntax_mapping: Arc::new(body_hir),
324 };
325 let actual = scopes 323 let actual = scopes
326 .scope_chain(marker.syntax()) 324 .scope_chain(marker.syntax())
327 .flat_map(|scope| scopes.scopes.entries(scope)) 325 .flat_map(|scope| scopes.scopes.entries(scope))
@@ -417,12 +415,10 @@ mod tests {
417 let name_ref: &ast::NameRef = find_node_at_offset(file.syntax(), off).unwrap(); 415 let name_ref: &ast::NameRef = find_node_at_offset(file.syntax(), off).unwrap();
418 416
419 let irrelevant_function = Function { id: crate::ids::FunctionId::from_raw(0.into()) }; 417 let irrelevant_function = Function { id: crate::ids::FunctionId::from_raw(0.into()) };
420 let body_hir = expr::collect_fn_body_syntax(irrelevant_function, fn_def); 418 let (body, source_map) = expr::collect_fn_body_syntax(irrelevant_function, fn_def);
421 let scopes = ExprScopes::new(Arc::clone(body_hir.body())); 419 let scopes = ExprScopes::new(Arc::new(body));
422 let scopes = ScopesWithSyntaxMapping { 420 let scopes =
423 scopes: Arc::new(scopes), 421 ScopesWithSourceMap { scopes: Arc::new(scopes), source_map: Arc::new(source_map) };
424 syntax_mapping: Arc::new(body_hir),
425 };
426 let local_name_entry = scopes.resolve_local_name(name_ref).unwrap(); 422 let local_name_entry = scopes.resolve_local_name(name_ref).unwrap();
427 let local_name = local_name_entry.ptr(); 423 let local_name = local_name_entry.ptr();
428 assert_eq!(local_name.range(), expected_name.syntax().range()); 424 assert_eq!(local_name.range(), expected_name.syntax().range());
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index edc1b4f57..a6e744ea7 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -60,7 +60,7 @@ pub use self::{
60 impl_block::{ImplBlock, ImplItem}, 60 impl_block::{ImplBlock, ImplItem},
61 docs::{Docs, Documentation}, 61 docs::{Docs, Documentation},
62 adt::AdtDef, 62 adt::AdtDef,
63 expr::{ExprScopes, ScopesWithSyntaxMapping, ScopeEntryWithSyntax}, 63 expr::{ExprScopes, ScopesWithSourceMap, ScopeEntryWithSyntax},
64 resolve::{Resolver, Resolution}, 64 resolve::{Resolver, Resolution},
65}; 65};
66 66
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs
index ac390c5db..73919ee37 100644
--- a/crates/ra_hir/src/nameres.rs
+++ b/crates/ra_hir/src/nameres.rs
@@ -481,7 +481,7 @@ impl ItemMap {
481 let module_tree = db.module_tree(krate); 481 let module_tree = db.module_tree(krate);
482 let input = module_tree 482 let input = module_tree
483 .modules() 483 .modules()
484 .map(|module_id| (module_id, db.lower_module_module(Module { krate, module_id }))) 484 .map(|module_id| (module_id, db.lower_module(Module { krate, module_id })))
485 .collect::<FxHashMap<_, _>>(); 485 .collect::<FxHashMap<_, _>>();
486 486
487 let resolver = Resolver::new(db, &input, krate); 487 let resolver = Resolver::new(db, &input, krate);
diff --git a/crates/ra_hir/src/nameres/lower.rs b/crates/ra_hir/src/nameres/lower.rs
index 2bc3eb60c..56262ad6d 100644
--- a/crates/ra_hir/src/nameres/lower.rs
+++ b/crates/ra_hir/src/nameres/lower.rs
@@ -60,21 +60,14 @@ impl ImportSourceMap {
60} 60}
61 61
62impl LoweredModule { 62impl LoweredModule {
63 pub(crate) fn lower_module_module_query( 63 pub(crate) fn lower_module_query(
64 db: &impl PersistentHirDatabase, 64 db: &impl PersistentHirDatabase,
65 module: Module, 65 module: Module,
66 ) -> Arc<LoweredModule> { 66 ) -> Arc<LoweredModule> {
67 db.lower_module(module).0 67 db.lower_module_with_source_map(module).0
68 }
69
70 pub(crate) fn lower_module_source_map_query(
71 db: &impl PersistentHirDatabase,
72 module: Module,
73 ) -> Arc<ImportSourceMap> {
74 db.lower_module(module).1
75 } 68 }
76 69
77 pub(crate) fn lower_module_query( 70 pub(crate) fn lower_module_with_source_map_query(
78 db: &impl PersistentHirDatabase, 71 db: &impl PersistentHirDatabase,
79 module: Module, 72 module: Module,
80 ) -> (Arc<LoweredModule>, Arc<ImportSourceMap>) { 73 ) -> (Arc<LoweredModule>, Arc<ImportSourceMap>) {
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index 625a2ce45..ea20cd15a 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -157,7 +157,7 @@ pub fn macro_symbols(db: &impl HirDatabase, file_id: FileId) -> Vec<(SmolStr, Te
157 Some(it) => it, 157 Some(it) => it,
158 None => return Vec::new(), 158 None => return Vec::new(),
159 }; 159 };
160 let items = db.lower_module_module(module); 160 let items = db.lower_module(module);
161 let mut res = Vec::new(); 161 let mut res = Vec::new();
162 162
163 for macro_call_id in items 163 for macro_call_id in items
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index e505c86e3..bad811a56 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -54,7 +54,7 @@ pub enum Ty {
54 /// The pointee of an array slice. Written as `[T]`. 54 /// The pointee of an array slice. Written as `[T]`.
55 Slice(Arc<Ty>), 55 Slice(Arc<Ty>),
56 56
57 // An array with the given length. Written as `[T; n]`. 57 /// An array with the given length. Written as `[T; n]`.
58 Array(Arc<Ty>), 58 Array(Arc<Ty>),
59 59
60 /// A raw pointer. Written as `*mut T` or `*const T` 60 /// A raw pointer. Written as `*mut T` or `*const T`
@@ -97,36 +97,12 @@ pub enum Ty {
97 /// ``` 97 /// ```
98 FnPtr(Arc<FnSig>), 98 FnPtr(Arc<FnSig>),
99 99
100 // rustc has a separate type for each function, which just coerces to the
101 // above function pointer type. Once we implement generics, we will probably
102 // need this as well.
103
104 // A trait, defined with `dyn Trait`.
105 // Dynamic(),
106
107 // The anonymous type of a closure. Used to represent the type of
108 // `|a| a`.
109 // Closure(DefId, ClosureSubsts<'tcx>),
110
111 // The anonymous type of a generator. Used to represent the type of
112 // `|a| yield a`.
113 // Generator(DefId, GeneratorSubsts<'tcx>, hir::GeneratorMovability),
114
115 // A type representing the types stored inside a generator.
116 // This should only appear in GeneratorInteriors.
117 // GeneratorWitness(Binder<&'tcx List<Ty<'tcx>>>),
118 /// The never type `!`. 100 /// The never type `!`.
119 Never, 101 Never,
120 102
121 /// A tuple type. For example, `(i32, bool)`. 103 /// A tuple type. For example, `(i32, bool)`.
122 Tuple(Arc<[Ty]>), 104 Tuple(Arc<[Ty]>),
123 105
124 // The projection of an associated type. For example,
125 // `<T as Trait<..>>::N`.pub
126 // Projection(ProjectionTy),
127
128 // Opaque (`impl Trait`) type found in a return type.
129 // Opaque(DefId, Substs),
130 /// A type parameter; for example, `T` in `fn f<T>(x: T) {} 106 /// A type parameter; for example, `T` in `fn f<T>(x: T) {}
131 Param { 107 Param {
132 /// The index of the parameter (starting with parameters from the 108 /// The index of the parameter (starting with parameters from the
@@ -304,9 +280,6 @@ impl Ty {
304 if (idx as usize) < substs.0.len() { 280 if (idx as usize) < substs.0.len() {
305 substs.0[idx as usize].clone() 281 substs.0[idx as usize].clone()
306 } else { 282 } else {
307 // TODO: does this indicate a bug? i.e. should we always
308 // have substs for all type params? (they might contain the
309 // params themselves again...)
310 Ty::Param { idx, name } 283 Ty::Param { idx, name }
311 } 284 }
312 } 285 }
@@ -366,7 +339,7 @@ impl fmt::Display for Ty {
366 Ok(()) 339 Ok(())
367 } 340 }
368 Ty::Param { name, .. } => write!(f, "{}", name), 341 Ty::Param { name, .. } => write!(f, "{}", name),
369 Ty::Unknown => write!(f, "[unknown]"), 342 Ty::Unknown => write!(f, "{{unknown}}"),
370 Ty::Infer(..) => write!(f, "_"), 343 Ty::Infer(..) => write!(f, "_"),
371 } 344 }
372 } 345 }
diff --git a/crates/ra_hir/src/ty/snapshots/tests__bug_484.snap b/crates/ra_hir/src/ty/snapshots/tests__bug_484.snap
deleted file mode 100644
index 28f57623d..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__bug_484.snap
+++ /dev/null
@@ -1,12 +0,0 @@
1---
2created: "2019-01-22T14:44:59.880187500+00:00"
3creator: [email protected]
4expression: "&result"
5source: "crates\\ra_hir\\src\\ty\\tests.rs"
6---
7[11; 37) '{ l... {}; }': ()
8[20; 21) 'x': ()
9[24; 34) 'if true {}': ()
10[27; 31) 'true': bool
11[32; 34) '{}': ()
12
diff --git a/crates/ra_hir/src/ty/snapshots/tests__bug_585.snap b/crates/ra_hir/src/ty/snapshots/tests__bug_585.snap
deleted file mode 100644
index e7b42e413..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__bug_585.snap
+++ /dev/null
@@ -1,15 +0,0 @@
1---
2created: "2019-01-22T14:44:59.880187500+00:00"
3creator: [email protected]
4expression: "&result"
5source: "crates\\ra_hir\\src\\ty\\tests.rs"
6---
7[11; 89) '{ ... } }': ()
8[17; 21) 'X {}': [unknown]
9[27; 87) 'match ... }': ()
10[33; 34) 'x': [unknown]
11[45; 52) 'A::B {}': [unknown]
12[56; 58) '()': ()
13[68; 74) 'A::Y()': [unknown]
14[78; 80) '()': ()
15
diff --git a/crates/ra_hir/src/ty/snapshots/tests__bug_651.snap b/crates/ra_hir/src/ty/snapshots/tests__bug_651.snap
deleted file mode 100644
index d23d3f139..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__bug_651.snap
+++ /dev/null
@@ -1,13 +0,0 @@
1---
2created: "2019-01-25T20:31:47.275112244+00:00"
3creator: [email protected]
4expression: "&result"
5source: crates/ra_hir/src/ty/tests.rs
6---
7[11; 41) '{ ...+ y; }': ()
8[21; 22) 'y': i32
9[25; 27) '92': i32
10[33; 34) '1': i32
11[33; 38) '1 + y': i32
12[37; 38) 'y': i32
13
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_adt_pattern.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_adt_pattern.snap
deleted file mode 100644
index 48c83cbb2..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_adt_pattern.snap
+++ /dev/null
@@ -1,32 +0,0 @@
1---
2created: "2019-01-28T21:58:55.559331849+00:00"
3creator: [email protected]
4expression: "&result"
5source: crates/ra_hir/src/ty/tests.rs
6---
7[68; 289) '{ ... d; }': ()
8[78; 79) 'e': E
9[82; 95) 'E::A { x: 3 }': E
10[92; 93) '3': usize
11[106; 113) 'S(y, z)': S
12[108; 109) 'y': u32
13[111; 112) 'z': E
14[116; 119) 'foo': S
15[129; 148) 'E::A {..._var }': E
16[139; 146) 'new_var': usize
17[151; 152) 'e': E
18[159; 245) 'match ... }': usize
19[165; 166) 'e': E
20[177; 187) 'E::A { x }': E
21[184; 185) 'x': usize
22[191; 192) 'x': usize
23[202; 206) 'E::B': E
24[210; 213) 'foo': bool
25[217; 218) '1': usize
26[228; 232) 'E::B': E
27[236; 238) '10': usize
28[256; 275) 'ref d ...{ .. }': &E
29[264; 275) 'E::A { .. }': E
30[278; 279) 'e': E
31[285; 286) 'd': &E
32
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_array.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_array.snap
deleted file mode 100644
index 042248c35..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_array.snap
+++ /dev/null
@@ -1,65 +0,0 @@
1---
2created: "2019-01-30T20:08:05.185312835+00:00"
3creator: [email protected]
4expression: "&result"
5source: crates/ra_hir/src/ty/tests.rs
6---
7[9; 10) 'x': &str
8[18; 19) 'y': isize
9[28; 324) '{ ... 3]; }': ()
10[38; 39) 'a': [&str]
11[42; 45) '[x]': [&str]
12[43; 44) 'x': &str
13[55; 56) 'b': [[&str]]
14[59; 65) '[a, a]': [[&str]]
15[60; 61) 'a': [&str]
16[63; 64) 'a': [&str]
17[75; 76) 'c': [[[&str]]]
18[79; 85) '[b, b]': [[[&str]]]
19[80; 81) 'b': [[&str]]
20[83; 84) 'b': [[&str]]
21[96; 97) 'd': [isize]
22[100; 112) '[y, 1, 2, 3]': [isize]
23[101; 102) 'y': isize
24[104; 105) '1': isize
25[107; 108) '2': isize
26[110; 111) '3': isize
27[122; 123) 'd': [isize]
28[126; 138) '[1, y, 2, 3]': [isize]
29[127; 128) '1': isize
30[130; 131) 'y': isize
31[133; 134) '2': isize
32[136; 137) '3': isize
33[148; 149) 'e': [isize]
34[152; 155) '[y]': [isize]
35[153; 154) 'y': isize
36[165; 166) 'f': [[isize]]
37[169; 175) '[d, d]': [[isize]]
38[170; 171) 'd': [isize]
39[173; 174) 'd': [isize]
40[185; 186) 'g': [[isize]]
41[189; 195) '[e, e]': [[isize]]
42[190; 191) 'e': [isize]
43[193; 194) 'e': [isize]
44[206; 207) 'h': [i32]
45[210; 216) '[1, 2]': [i32]
46[211; 212) '1': i32
47[214; 215) '2': i32
48[226; 227) 'i': [&str]
49[230; 240) '["a", "b"]': [&str]
50[231; 234) '"a"': &str
51[236; 239) '"b"': &str
52[251; 252) 'b': [[&str]]
53[255; 265) '[a, ["b"]]': [[&str]]
54[256; 257) 'a': [&str]
55[259; 264) '["b"]': [&str]
56[260; 263) '"b"': &str
57[275; 276) 'x': [u8]
58[288; 290) '[]': [u8]
59[300; 301) 'z': &[u8]
60[311; 321) '&[1, 2, 3]': &[u8]
61[312; 321) '[1, 2, 3]': [u8]
62[313; 314) '1': u8
63[316; 317) '2': u8
64[319; 320) '3': u8
65
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_associated_const.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_associated_const.snap
deleted file mode 100644
index 51f3fd4c0..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_associated_const.snap
+++ /dev/null
@@ -1,14 +0,0 @@
1---
2created: "2019-02-25T08:36:33.885804400Z"
3creator: [email protected]
4source: crates/ra_hir/src/ty/tests.rs
5expression: "&result"
6---
7[227; 305) '{ ...:ID; }': ()
8[237; 238) 'x': u32
9[241; 252) 'Struct::FOO': u32
10[262; 263) 'y': u32
11[266; 275) 'Enum::BAR': u32
12[285; 286) 'z': u32
13[289; 302) 'TraitTest::ID': u32
14
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_associated_method_enum.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_associated_method_enum.snap
deleted file mode 100644
index 8f27af88c..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_associated_method_enum.snap
+++ /dev/null
@@ -1,20 +0,0 @@
1---
2created: "2019-02-20T11:04:56.553382800Z"
3creator: [email protected]
4source: crates/ra_hir/src/ty/tests.rs
5expression: "&result"
6---
7[48; 68) '{ ... }': A
8[58; 62) 'A::B': A
9[89; 109) '{ ... }': A
10[99; 103) 'A::C': A
11[122; 179) '{ ... c; }': ()
12[132; 133) 'a': A
13[136; 140) 'A::b': fn b() -> A
14[136; 142) 'A::b()': A
15[148; 149) 'a': A
16[159; 160) 'c': A
17[163; 167) 'A::c': fn c() -> A
18[163; 169) 'A::c()': A
19[175; 176) 'c': A
20
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_associated_method_generics.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_associated_method_generics.snap
deleted file mode 100644
index 44694dfdb..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_associated_method_generics.snap
+++ /dev/null
@@ -1,16 +0,0 @@
1---
2created: "2019-02-23T21:58:35.844769207Z"
3creator: [email protected]
4source: crates/ra_hir/src/ty/tests.rs
5expression: "&result"
6---
7[64; 67) 'val': T
8[82; 109) '{ ... }': Gen<T>
9[92; 103) 'Gen { val }': Gen<T>
10[98; 101) 'val': T
11[123; 155) '{ ...32); }': ()
12[133; 134) 'a': Gen<u32>
13[137; 146) 'Gen::make': fn make<u32>(T) -> Gen<T>
14[137; 152) 'Gen::make(0u32)': Gen<u32>
15[147; 151) '0u32': u32
16
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_associated_method_struct.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_associated_method_struct.snap
deleted file mode 100644
index 29ca9b0ea..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_associated_method_struct.snap
+++ /dev/null
@@ -1,16 +0,0 @@
1---
2created: "2019-02-20T11:04:56.553382800Z"
3creator: [email protected]
4source: crates/ra_hir/src/ty/tests.rs
5expression: "&result"
6---
7[50; 76) '{ ... }': A
8[60; 70) 'A { x: 0 }': A
9[67; 68) '0': u32
10[89; 123) '{ ...a.x; }': ()
11[99; 100) 'a': A
12[103; 109) 'A::new': fn new() -> A
13[103; 111) 'A::new()': A
14[117; 118) 'a': A
15[117; 120) 'a.x': u32
16
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_associated_method_with_modules.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_associated_method_with_modules.snap
deleted file mode 100644
index 6584bef39..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_associated_method_with_modules.snap
+++ /dev/null
@@ -1,23 +0,0 @@
1---
2created: "2019-02-21T08:55:53.926725400Z"
3creator: [email protected]
4source: crates/ra_hir/src/ty/tests.rs
5expression: "&result"
6---
7[56; 64) '{ A {} }': A
8[58; 62) 'A {}': A
9[126; 132) '{ 99 }': u32
10[128; 130) '99': u32
11[202; 210) '{ C {} }': C
12[204; 208) 'C {}': C
13[241; 325) '{ ...g(); }': ()
14[251; 252) 'x': A
15[255; 266) 'a::A::thing': fn thing() -> A
16[255; 268) 'a::A::thing()': A
17[278; 279) 'y': u32
18[282; 293) 'b::B::thing': fn thing() -> u32
19[282; 295) 'b::B::thing()': u32
20[305; 306) 'z': C
21[309; 320) 'c::C::thing': fn thing() -> C
22[309; 322) 'c::C::thing()': C
23
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_backwards.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_backwards.snap
deleted file mode 100644
index f5840a934..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_backwards.snap
+++ /dev/null
@@ -1,27 +0,0 @@
1---
2created: "2019-01-26T17:46:03.842478456+00:00"
3creator: [email protected]
4expression: "&result"
5source: crates/ra_hir/src/ty/tests.rs
6---
7[14; 15) 'x': u32
8[22; 24) '{}': ()
9[78; 231) '{ ...t &c }': &mut &f64
10[88; 89) 'a': u32
11[92; 108) 'unknow...nction': [unknown]
12[92; 110) 'unknow...tion()': u32
13[116; 125) 'takes_u32': fn takes_u32(u32) -> ()
14[116; 128) 'takes_u32(a)': ()
15[126; 127) 'a': u32
16[138; 139) 'b': i32
17[142; 158) 'unknow...nction': [unknown]
18[142; 160) 'unknow...tion()': i32
19[166; 184) 'S { i3...d: b }': S
20[181; 182) 'b': i32
21[194; 195) 'c': f64
22[198; 214) 'unknow...nction': [unknown]
23[198; 216) 'unknow...tion()': f64
24[222; 229) '&mut &c': &mut &f64
25[227; 229) '&c': &f64
26[228; 229) 'c': f64
27
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_basics.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_basics.snap
deleted file mode 100644
index 4b0863558..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_basics.snap
+++ /dev/null
@@ -1,20 +0,0 @@
1---
2created: "2019-01-22T14:44:59.880187500+00:00"
3creator: [email protected]
4expression: "&result"
5source: "crates\\ra_hir\\src\\ty\\tests.rs"
6---
7[9; 10) 'a': u32
8[17; 18) 'b': isize
9[27; 28) 'c': !
10[33; 34) 'd': &str
11[42; 121) '{ ...f32; }': ()
12[48; 49) 'a': u32
13[55; 56) 'b': isize
14[62; 63) 'c': !
15[69; 70) 'd': &str
16[76; 82) '1usize': usize
17[88; 94) '1isize': isize
18[100; 106) '"test"': &str
19[112; 118) '1.0f32': f32
20
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_binary_op.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_binary_op.snap
deleted file mode 100644
index 80ffe6e11..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_binary_op.snap
+++ /dev/null
@@ -1,57 +0,0 @@
1---
2created: "2019-02-18T07:03:52.524808301Z"
3creator: [email protected]
4source: crates/ra_hir/src/ty/tests.rs
5expression: "&result"
6---
7[6; 7) 'x': bool
8[22; 34) '{ 0i32 }': i32
9[28; 32) '0i32': i32
10[54; 370) '{ ... < 3 }': bool
11[64; 65) 'x': bool
12[68; 69) 'a': bool
13[68; 74) 'a && b': bool
14[73; 74) 'b': bool
15[84; 85) 'y': bool
16[88; 92) 'true': bool
17[88; 101) 'true || false': bool
18[96; 101) 'false': bool
19[111; 112) 'z': bool
20[115; 116) 'x': bool
21[115; 121) 'x == y': bool
22[120; 121) 'y': bool
23[131; 132) 't': bool
24[135; 136) 'x': bool
25[135; 141) 'x != y': bool
26[140; 141) 'y': bool
27[151; 162) 'minus_forty': isize
28[172; 180) '-40isize': isize
29[173; 180) '40isize': isize
30[190; 191) 'h': bool
31[194; 205) 'minus_forty': isize
32[194; 216) 'minus_...ONST_2': bool
33[209; 216) 'CONST_2': isize
34[226; 227) 'c': i32
35[230; 231) 'f': fn f(bool) -> i32
36[230; 239) 'f(z || y)': i32
37[230; 243) 'f(z || y) + 5': i32
38[232; 233) 'z': bool
39[232; 238) 'z || y': bool
40[237; 238) 'y': bool
41[242; 243) '5': i32
42[253; 254) 'd': [unknown]
43[257; 258) 'b': [unknown]
44[268; 269) 'g': ()
45[272; 283) 'minus_forty': isize
46[272; 288) 'minus_...y ^= i': ()
47[287; 288) 'i': isize
48[298; 301) 'ten': usize
49[311; 313) '10': usize
50[323; 336) 'ten_is_eleven': bool
51[339; 342) 'ten': usize
52[339; 354) 'ten == some_num': bool
53[346; 354) 'some_num': usize
54[361; 364) 'ten': usize
55[361; 368) 'ten < 3': bool
56[367; 368) '3': usize
57
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_const.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_const.snap
deleted file mode 100644
index a5eba3980..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_const.snap
+++ /dev/null
@@ -1,14 +0,0 @@
1---
2created: "2019-02-25T07:26:34.115351100Z"
3creator: [email protected]
4source: crates/ra_hir/src/ty/tests.rs
5expression: "&result"
6---
7[95; 213) '{ ...NST; }': ()
8[138; 139) 'x': [unknown]
9[142; 153) 'LOCAL_CONST': [unknown]
10[163; 164) 'z': u32
11[167; 179) 'GLOBAL_CONST': u32
12[189; 191) 'id': u32
13[194; 210) 'Foo::A..._CONST': u32
14
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_enum.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_enum.snap
deleted file mode 100644
index bc8b84272..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_enum.snap
+++ /dev/null
@@ -1,11 +0,0 @@
1---
2created: "2019-01-22T14:44:59.880187500+00:00"
3creator: [email protected]
4expression: "&result"
5source: "crates\\ra_hir\\src\\ty\\tests.rs"
6---
7[48; 82) '{ E:...:V2; }': ()
8[52; 70) 'E::V1 ...d: 1 }': E
9[67; 68) '1': u32
10[74; 79) 'E::V2': E
11
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_field_autoderef.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_field_autoderef.snap
deleted file mode 100644
index f092fd319..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_field_autoderef.snap
+++ /dev/null
@@ -1,50 +0,0 @@
1---
2created: "2019-01-22T14:44:59.955954900+00:00"
3creator: [email protected]
4expression: "&result"
5source: "crates\\ra_hir\\src\\ty\\tests.rs"
6---
7[44; 45) 'a': A
8[50; 213) '{ ...5.b; }': ()
9[60; 62) 'a1': A
10[65; 66) 'a': A
11[72; 74) 'a1': A
12[72; 76) 'a1.b': B
13[86; 88) 'a2': &A
14[91; 93) '&a': &A
15[92; 93) 'a': A
16[99; 101) 'a2': &A
17[99; 103) 'a2.b': B
18[113; 115) 'a3': &mut A
19[118; 124) '&mut a': &mut A
20[123; 124) 'a': A
21[130; 132) 'a3': &mut A
22[130; 134) 'a3.b': B
23[144; 146) 'a4': &&&&&&&A
24[149; 157) '&&&&&&&a': &&&&&&&A
25[150; 157) '&&&&&&a': &&&&&&A
26[151; 157) '&&&&&a': &&&&&A
27[152; 157) '&&&&a': &&&&A
28[153; 157) '&&&a': &&&A
29[154; 157) '&&a': &&A
30[155; 157) '&a': &A
31[156; 157) 'a': A
32[163; 165) 'a4': &&&&&&&A
33[163; 167) 'a4.b': B
34[177; 179) 'a5': &mut &&mut &&mut A
35[182; 200) '&mut &...&mut a': &mut &&mut &&mut A
36[187; 200) '&&mut &&mut a': &&mut &&mut A
37[188; 200) '&mut &&mut a': &mut &&mut A
38[193; 200) '&&mut a': &&mut A
39[194; 200) '&mut a': &mut A
40[199; 200) 'a': A
41[206; 208) 'a5': &mut &&mut &&mut A
42[206; 210) 'a5.b': B
43[224; 226) 'a1': *const A
44[238; 240) 'a2': *mut A
45[250; 273) '{ ...2.b; }': ()
46[256; 258) 'a1': *const A
47[256; 260) 'a1.b': B
48[266; 268) 'a2': *mut A
49[266; 270) 'a2.b': B
50
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_function_generics.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_function_generics.snap
deleted file mode 100644
index 91c48897c..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_function_generics.snap
+++ /dev/null
@@ -1,21 +0,0 @@
1---
2created: "2019-01-27T14:52:29.934503829+00:00"
3creator: [email protected]
4expression: "&result"
5source: crates/ra_hir/src/ty/tests.rs
6---
7[10; 11) 't': T
8[21; 26) '{ t }': T
9[23; 24) 't': T
10[38; 98) '{ ...(1); }': ()
11[44; 46) 'id': fn id<u32>(T) -> T
12[44; 52) 'id(1u32)': u32
13[47; 51) '1u32': u32
14[58; 68) 'id::<i128>': fn id<i128>(T) -> T
15[58; 71) 'id::<i128>(1)': i128
16[69; 70) '1': i128
17[81; 82) 'x': u64
18[90; 92) 'id': fn id<u64>(T) -> T
19[90; 95) 'id(1)': u64
20[93; 94) '1': u64
21
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_generic_chain.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_generic_chain.snap
deleted file mode 100644
index d1ce87b0a..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_generic_chain.snap
+++ /dev/null
@@ -1,36 +0,0 @@
1---
2created: "2019-02-16T20:53:59.655361804Z"
3creator: [email protected]
4source: crates/ra_hir/src/ty/tests.rs
5expression: "&result"
6---
7[53; 57) 'self': A<T2>
8[65; 87) '{ ... }': T2
9[75; 79) 'self': A<T2>
10[75; 81) 'self.x': T2
11[99; 100) 't': T
12[110; 115) '{ t }': T
13[112; 113) 't': T
14[135; 261) '{ ....x() }': i128
15[146; 147) 'x': i128
16[150; 151) '1': i128
17[162; 163) 'y': i128
18[166; 168) 'id': fn id<i128>(T) -> T
19[166; 171) 'id(x)': i128
20[169; 170) 'x': i128
21[182; 183) 'a': A<i128>
22[186; 200) 'A { x: id(y) }': A<i128>
23[193; 195) 'id': fn id<i128>(T) -> T
24[193; 198) 'id(y)': i128
25[196; 197) 'y': i128
26[211; 212) 'z': i128
27[215; 217) 'id': fn id<i128>(T) -> T
28[215; 222) 'id(a.x)': i128
29[218; 219) 'a': A<i128>
30[218; 221) 'a.x': i128
31[233; 234) 'b': A<i128>
32[237; 247) 'A { x: z }': A<i128>
33[244; 245) 'z': i128
34[254; 255) 'b': A<i128>
35[254; 259) 'b.x()': i128
36
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_generics_in_patterns.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_generics_in_patterns.snap
deleted file mode 100644
index fae7ab0dd..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_generics_in_patterns.snap
+++ /dev/null
@@ -1,24 +0,0 @@
1---
2created: "2019-01-22T14:44:59.970913200+00:00"
3creator: [email protected]
4expression: "&result"
5source: "crates\\ra_hir\\src\\ty\\tests.rs"
6---
7[79; 81) 'a1': A<u32>
8[91; 92) 'o': Option<u64>
9[107; 244) '{ ... }; }': ()
10[117; 128) 'A { x: x2 }': A<u32>
11[124; 126) 'x2': u32
12[131; 133) 'a1': A<u32>
13[143; 161) 'A::<i6...: x3 }': A<i64>
14[157; 159) 'x3': i64
15[164; 174) 'A { x: 1 }': A<i64>
16[171; 172) '1': i64
17[180; 241) 'match ... }': u64
18[186; 187) 'o': Option<u64>
19[198; 213) 'Option::Some(t)': Option<u64>
20[211; 212) 't': u64
21[217; 218) 't': u64
22[228; 229) '_': Option<u64>
23[233; 234) '1': u64
24
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_impl_generics.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_impl_generics.snap
deleted file mode 100644
index 44f00a52e..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_impl_generics.snap
+++ /dev/null
@@ -1,39 +0,0 @@
1---
2created: "2019-02-16T21:58:14.029368845Z"
3creator: [email protected]
4source: crates/ra_hir/src/ty/tests.rs
5expression: "&result"
6---
7[74; 78) 'self': A<X, Y>
8[85; 107) '{ ... }': X
9[95; 99) 'self': A<X, Y>
10[95; 101) 'self.x': X
11[117; 121) 'self': A<X, Y>
12[128; 150) '{ ... }': Y
13[138; 142) 'self': A<X, Y>
14[138; 144) 'self.y': Y
15[163; 167) 'self': A<X, Y>
16[169; 170) 't': T
17[188; 223) '{ ... }': (X, Y, T)
18[198; 217) '(self.....y, t)': (X, Y, T)
19[199; 203) 'self': A<X, Y>
20[199; 205) 'self.x': X
21[207; 211) 'self': A<X, Y>
22[207; 213) 'self.y': Y
23[215; 216) 't': T
24[245; 342) '{ ...(1); }': ()
25[255; 256) 'a': A<u64, i64>
26[259; 281) 'A { x:...1i64 }': A<u64, i64>
27[266; 270) '1u64': u64
28[275; 279) '1i64': i64
29[287; 288) 'a': A<u64, i64>
30[287; 292) 'a.x()': u64
31[298; 299) 'a': A<u64, i64>
32[298; 303) 'a.y()': i64
33[309; 310) 'a': A<u64, i64>
34[309; 319) 'a.z(1i128)': (u64, i64, i128)
35[313; 318) '1i128': i128
36[325; 326) 'a': A<u64, i64>
37[325; 339) 'a.z::<u128>(1)': (u64, i64, u128)
38[337; 338) '1': u128
39
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_impl_generics_with_autoderef.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_impl_generics_with_autoderef.snap
deleted file mode 100644
index f609eaf7c..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_impl_generics_with_autoderef.snap
+++ /dev/null
@@ -1,16 +0,0 @@
1---
2created: "2019-02-17T13:35:06.385679926Z"
3creator: [email protected]
4source: crates/ra_hir/src/ty/tests.rs
5expression: "&result"
6---
7[78; 82) 'self': &Option<T>
8[98; 100) '{}': ()
9[111; 112) 'o': Option<u32>
10[127; 165) '{ ...f(); }': ()
11[133; 146) '(&o).as_ref()': Option<&u32>
12[134; 136) '&o': &Option<u32>
13[135; 136) 'o': Option<u32>
14[152; 153) 'o': Option<u32>
15[152; 162) 'o.as_ref()': Option<&u32>
16
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_in_elseif.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_in_elseif.snap
deleted file mode 100644
index 6a435e5cf..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_in_elseif.snap
+++ /dev/null
@@ -1,17 +0,0 @@
1---
2created: "2019-01-26T21:36:52.714121185+00:00"
3creator: [email protected]
4expression: "&result"
5source: crates/ra_hir/src/ty/tests.rs
6---
7[35; 38) 'foo': Foo
8[45; 109) '{ ... } }': ()
9[51; 107) 'if tru... }': ()
10[54; 58) 'true': bool
11[59; 67) '{ }': ()
12[73; 107) 'if fal... }': i32
13[76; 81) 'false': bool
14[82; 107) '{ ... }': i32
15[92; 95) 'foo': Foo
16[92; 101) 'foo.field': i32
17
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_inherent_method.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_inherent_method.snap
deleted file mode 100644
index b3c706aca..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_inherent_method.snap
+++ /dev/null
@@ -1,25 +0,0 @@
1---
2created: "2019-01-22T14:44:59.968918800+00:00"
3creator: [email protected]
4expression: "&result"
5source: "crates\\ra_hir\\src\\ty\\tests.rs"
6---
7[32; 36) 'self': A
8[38; 39) 'x': u32
9[53; 55) '{}': ()
10[103; 107) 'self': &A
11[109; 110) 'x': u64
12[124; 126) '{}': ()
13[144; 145) 'a': A
14[150; 198) '{ ...(1); }': ()
15[156; 157) 'a': A
16[156; 164) 'a.foo(1)': i32
17[162; 163) '1': u32
18[170; 181) '(&a).bar(1)': i64
19[171; 173) '&a': &A
20[172; 173) 'a': A
21[179; 180) '1': u64
22[187; 188) 'a': A
23[187; 195) 'a.bar(1)': i64
24[193; 194) '1': u64
25
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_let.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_let.snap
deleted file mode 100644
index 0d085071a..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_let.snap
+++ /dev/null
@@ -1,14 +0,0 @@
1---
2created: "2019-01-22T14:44:59.963931700+00:00"
3creator: [email protected]
4expression: "&result"
5source: "crates\\ra_hir\\src\\ty\\tests.rs"
6---
7[11; 71) '{ ...= b; }': ()
8[21; 22) 'a': isize
9[25; 31) '1isize': isize
10[41; 42) 'b': usize
11[52; 53) '1': usize
12[63; 64) 'c': usize
13[67; 68) 'b': usize
14
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_literals.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_literals.snap
deleted file mode 100644
index e287a100e..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_literals.snap
+++ /dev/null
@@ -1,19 +0,0 @@
1---
2created: "2019-01-22T14:44:59.974903100+00:00"
3creator: [email protected]
4expression: "&result"
5source: "crates\\ra_hir\\src\\ty\\tests.rs"
6---
7[11; 201) '{ ...o"#; }': ()
8[17; 21) '5i32': i32
9[27; 34) '"hello"': &str
10[40; 48) 'b"bytes"': &[u8]
11[54; 57) ''c'': char
12[63; 67) 'b'b'': u8
13[73; 77) '3.14': f64
14[83; 87) '5000': i32
15[93; 98) 'false': bool
16[104; 108) 'true': bool
17[114; 182) 'r#" ... "#': &str
18[188; 198) 'br#"yolo"#': &[u8]
19
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_nested_generics_crash.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_nested_generics_crash.snap
deleted file mode 100644
index 209454a91..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_nested_generics_crash.snap
+++ /dev/null
@@ -1,12 +0,0 @@
1---
2created: "2019-02-11T21:59:04.302375838Z"
3creator: [email protected]
4source: crates/ra_hir/src/ty/tests.rs
5expression: "&result"
6---
7[92; 106) 'query_response': Canonical<QueryResponse<R>>
8[137; 167) '{ ...lue; }': ()
9[143; 164) '&query....value': &QueryResponse<R>
10[144; 158) 'query_response': Canonical<QueryResponse<R>>
11[144; 164) 'query_....value': QueryResponse<R>
12
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_paths.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_paths.snap
deleted file mode 100644
index afbe2f747..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_paths.snap
+++ /dev/null
@@ -1,16 +0,0 @@
1---
2created: "2019-01-26T17:46:03.928773630+00:00"
3creator: [email protected]
4expression: "&result"
5source: crates/ra_hir/src/ty/tests.rs
6---
7[15; 20) '{ 1 }': u32
8[17; 18) '1': u32
9[48; 53) '{ 1 }': u32
10[50; 51) '1': u32
11[67; 91) '{ ...c(); }': ()
12[73; 74) 'a': fn a() -> u32
13[73; 76) 'a()': u32
14[82; 86) 'b::c': fn c() -> u32
15[82; 88) 'b::c()': u32
16
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_pattern.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_pattern.snap
deleted file mode 100644
index 1da46daf8..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_pattern.snap
+++ /dev/null
@@ -1,54 +0,0 @@
1---
2created: "2019-01-22T14:45:00.037734500+00:00"
3creator: [email protected]
4expression: "&result"
5source: "crates\\ra_hir\\src\\ty\\tests.rs"
6---
7[9; 10) 'x': &i32
8[18; 369) '{ ...o_x; }': ()
9[28; 29) 'y': &i32
10[32; 33) 'x': &i32
11[43; 45) '&z': &i32
12[44; 45) 'z': i32
13[48; 49) 'x': &i32
14[59; 60) 'a': i32
15[63; 64) 'z': i32
16[74; 80) '(c, d)': (i32, &str)
17[75; 76) 'c': i32
18[78; 79) 'd': &str
19[83; 95) '(1, "hello")': (i32, &str)
20[84; 85) '1': i32
21[87; 94) '"hello"': &str
22[102; 152) 'for (e... }': ()
23[106; 112) '(e, f)': ([unknown], [unknown])
24[107; 108) 'e': [unknown]
25[110; 111) 'f': [unknown]
26[116; 125) 'some_iter': [unknown]
27[126; 152) '{ ... }': ()
28[140; 141) 'g': [unknown]
29[144; 145) 'e': [unknown]
30[158; 205) 'if let... }': ()
31[165; 170) '[val]': [unknown]
32[173; 176) 'opt': [unknown]
33[177; 205) '{ ... }': ()
34[191; 192) 'h': [unknown]
35[195; 198) 'val': [unknown]
36[215; 221) 'lambda': [unknown]
37[224; 256) '|a: u6...b; c }': [unknown]
38[225; 226) 'a': u64
39[233; 234) 'b': u64
40[236; 237) 'c': i32
41[244; 256) '{ a + b; c }': i32
42[246; 247) 'a': u64
43[246; 251) 'a + b': u64
44[250; 251) 'b': u64
45[253; 254) 'c': i32
46[267; 279) 'ref ref_to_x': &&i32
47[282; 283) 'x': &i32
48[293; 302) 'mut mut_x': &i32
49[305; 306) 'x': &i32
50[316; 336) 'ref mu...f_to_x': &mut &i32
51[339; 340) 'x': &i32
52[350; 351) 'k': &mut &i32
53[354; 366) 'mut_ref_to_x': &mut &i32
54
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_refs.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_refs.snap
deleted file mode 100644
index 56931bb3d..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_refs.snap
+++ /dev/null
@@ -1,30 +0,0 @@
1---
2created: "2019-01-22T14:45:00.053692600+00:00"
3creator: [email protected]
4expression: "&result"
5source: "crates\\ra_hir\\src\\ty\\tests.rs"
6---
7[9; 10) 'a': &u32
8[18; 19) 'b': &mut u32
9[31; 32) 'c': *const u32
10[46; 47) 'd': *mut u32
11[59; 150) '{ ... *d; }': ()
12[65; 66) 'a': &u32
13[72; 74) '*a': u32
14[73; 74) 'a': &u32
15[80; 82) '&a': &&u32
16[81; 82) 'a': &u32
17[88; 94) '&mut a': &mut &u32
18[93; 94) 'a': &u32
19[100; 101) 'b': &mut u32
20[107; 109) '*b': u32
21[108; 109) 'b': &mut u32
22[115; 117) '&b': &&mut u32
23[116; 117) 'b': &mut u32
24[123; 124) 'c': *const u32
25[130; 132) '*c': u32
26[131; 132) 'c': *const u32
27[138; 139) 'd': *mut u32
28[145; 147) '*d': u32
29[146; 147) 'd': *mut u32
30
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_self.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_self.snap
deleted file mode 100644
index 5c927f5c1..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_self.snap
+++ /dev/null
@@ -1,17 +0,0 @@
1---
2created: "2019-02-04T19:40:48.826936500+00:00"
3creator: [email protected]
4expression: "&result"
5source: crates/ra_hir/src/ty/tests.rs
6---
7[34; 38) 'self': &S
8[40; 61) '{ ... }': ()
9[50; 54) 'self': &S
10[75; 79) 'self': &S
11[88; 109) '{ ... }': ()
12[98; 102) 'self': &S
13[133; 153) '{ ... }': S
14[143; 147) 'S {}': S
15[177; 200) '{ ... }': S
16[187; 194) 'Self {}': S
17
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_static.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_static.snap
deleted file mode 100644
index 5d90f56ed..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_static.snap
+++ /dev/null
@@ -1,16 +0,0 @@
1---
2created: "2019-02-25T08:20:17.807316Z"
3creator: [email protected]
4source: crates/ra_hir/src/ty/tests.rs
5expression: "&result"
6---
7[85; 280) '{ ...MUT; }': ()
8[173; 174) 'x': [unknown]
9[177; 189) 'LOCAL_STATIC': [unknown]
10[199; 200) 'y': [unknown]
11[203; 219) 'LOCAL_...IC_MUT': [unknown]
12[229; 230) 'z': u32
13[233; 246) 'GLOBAL_STATIC': u32
14[256; 257) 'w': u32
15[260; 277) 'GLOBAL...IC_MUT': u32
16
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_1.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_1.snap
deleted file mode 100644
index 4b99788e4..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_1.snap
+++ /dev/null
@@ -1,13 +0,0 @@
1---
2created: "2019-02-09T16:56:24.803326529Z"
3creator: [email protected]
4source: crates/ra_hir/src/ty/tests.rs
5expression: "&result"
6---
7[54; 139) '{ ... } }': ()
8[60; 137) 'match ... }': ()
9[66; 83) 'someth...nknown': Maybe<[unknown]>
10[94; 124) 'Maybe:...thing)': Maybe<[unknown]>
11[106; 123) 'ref mu...ething': &mut [unknown]
12[128; 130) '()': ()
13
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_2.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_2.snap
deleted file mode 100644
index fd0b39b7d..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_2.snap
+++ /dev/null
@@ -1,14 +0,0 @@
1---
2created: "2019-02-09T17:03:11.974225590Z"
3creator: [email protected]
4source: crates/ra_hir/src/ty/tests.rs
5expression: "&result"
6---
7[23; 53) '{ ...n']; }': ()
8[29; 50) '&[0, b...b'\n']': &[u8]
9[30; 50) '[0, b'...b'\n']': [u8]
10[31; 32) '0': u8
11[34; 39) 'b'\n'': u8
12[41; 42) '1': u8
13[44; 49) 'b'\n'': u8
14
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_3.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_3.snap
deleted file mode 100644
index d15b77e17..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_3.snap
+++ /dev/null
@@ -1,13 +0,0 @@
1---
2created: "2019-02-09T18:02:37.377591660Z"
3creator: [email protected]
4source: crates/ra_hir/src/ty/tests.rs
5expression: "&result"
6---
7[18; 102) '{ ... } }': ()
8[24; 100) 'match ... }': ()
9[42; 88) 'SizeSk...tail }': [unknown]
10[76; 80) 'true': [unknown]
11[82; 86) 'tail': [unknown]
12[92; 94) '{}': ()
13
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_4.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_4.snap
deleted file mode 100644
index fb31883ce..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_4.snap
+++ /dev/null
@@ -1,16 +0,0 @@
1---
2created: "2019-02-09T19:55:39.712470520Z"
3creator: [email protected]
4source: crates/ra_hir/src/ty/tests.rs
5expression: "&result"
6---
7[25; 110) '{ ... } }': ()
8[31; 108) 'match ... }': ()
9[37; 42) '*self': [unknown]
10[38; 42) 'self': [unknown]
11[53; 95) 'Borrow...), ..}': [unknown]
12[74; 77) 'box': [unknown]
13[78; 87) 'Primitive': [unknown]
14[88; 89) 'p': [unknown]
15[99; 101) '{}': ()
16
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_5.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_5.snap
deleted file mode 100644
index 6bbf59fb6..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_5.snap
+++ /dev/null
@@ -1,30 +0,0 @@
1---
2created: "2019-02-09T20:28:37.294693728Z"
3creator: [email protected]
4source: crates/ra_hir/src/ty/tests.rs
5expression: "&result"
6---
7[27; 323) '{ ... } }': ()
8[33; 321) 'for co... }': ()
9[37; 44) 'content': &[unknown]
10[48; 61) 'doesnt_matter': [unknown]
11[62; 321) '{ ... }': ()
12[76; 80) 'name': &&[unknown]
13[83; 167) 'if doe... }': &&[unknown]
14[86; 99) 'doesnt_matter': bool
15[100; 129) '{ ... }': &&[unknown]
16[114; 119) 'first': &&[unknown]
17[135; 167) '{ ... }': &&[unknown]
18[149; 157) '&content': &&[unknown]
19[150; 157) 'content': &[unknown]
20[182; 189) 'content': &&[unknown]
21[192; 314) 'if ICE... }': &&[unknown]
22[195; 232) 'ICE_RE..._VALUE': [unknown]
23[195; 248) 'ICE_RE...&name)': bool
24[242; 247) '&name': &&&[unknown]
25[243; 247) 'name': &&[unknown]
26[249; 277) '{ ... }': &&[unknown]
27[263; 267) 'name': &&[unknown]
28[283; 314) '{ ... }': &[unknown]
29[297; 304) 'content': &[unknown]
30
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_struct.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_struct.snap
deleted file mode 100644
index 32f1fa108..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_struct.snap
+++ /dev/null
@@ -1,23 +0,0 @@
1---
2created: "2019-02-20T21:31:12.910924715Z"
3creator: [email protected]
4source: crates/ra_hir/src/ty/tests.rs
5expression: "&result"
6---
7[72; 154) '{ ...a.c; }': ()
8[82; 83) 'c': C
9[86; 87) 'C': C(usize) -> C
10[86; 90) 'C(1)': C
11[88; 89) '1': usize
12[96; 97) 'B': B
13[107; 108) 'a': A
14[114; 133) 'A { b:...C(1) }': A
15[121; 122) 'B': B
16[127; 128) 'C': C(usize) -> C
17[127; 131) 'C(1)': C
18[129; 130) '1': usize
19[139; 140) 'a': A
20[139; 142) 'a.b': B
21[148; 149) 'a': A
22[148; 151) 'a.c': C
23
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_struct_generics.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_struct_generics.snap
deleted file mode 100644
index e07c7d36c..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_struct_generics.snap
+++ /dev/null
@@ -1,22 +0,0 @@
1---
2created: "2019-01-22T14:45:00.058678600+00:00"
3creator: [email protected]
4expression: "&result"
5source: "crates\\ra_hir\\src\\ty\\tests.rs"
6---
7[36; 38) 'a1': A<u32>
8[48; 49) 'i': i32
9[56; 147) '{ ...3.x; }': ()
10[62; 64) 'a1': A<u32>
11[62; 66) 'a1.x': u32
12[76; 78) 'a2': A<i32>
13[81; 91) 'A { x: i }': A<i32>
14[88; 89) 'i': i32
15[97; 99) 'a2': A<i32>
16[97; 101) 'a2.x': i32
17[111; 113) 'a3': A<i128>
18[116; 134) 'A::<i1...x: 1 }': A<i128>
19[131; 132) '1': i128
20[140; 142) 'a3': A<i128>
21[140; 144) 'a3.x': i128
22
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_tuple.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_tuple.snap
deleted file mode 100644
index cd11d41d3..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_tuple.snap
+++ /dev/null
@@ -1,34 +0,0 @@
1---
2created: "2019-01-22T14:45:00.058678600+00:00"
3creator: [email protected]
4expression: "&result"
5source: "crates\\ra_hir\\src\\ty\\tests.rs"
6---
7[9; 10) 'x': &str
8[18; 19) 'y': isize
9[28; 170) '{ ...d"); }': ()
10[38; 39) 'a': (u32, &str)
11[55; 63) '(1, "a")': (u32, &str)
12[56; 57) '1': u32
13[59; 62) '"a"': &str
14[73; 74) 'b': ((u32, &str), &str)
15[77; 83) '(a, x)': ((u32, &str), &str)
16[78; 79) 'a': (u32, &str)
17[81; 82) 'x': &str
18[93; 94) 'c': (isize, &str)
19[97; 103) '(y, x)': (isize, &str)
20[98; 99) 'y': isize
21[101; 102) 'x': &str
22[113; 114) 'd': ((isize, &str), &str)
23[117; 123) '(c, x)': ((isize, &str), &str)
24[118; 119) 'c': (isize, &str)
25[121; 122) 'x': &str
26[133; 134) 'e': (i32, &str)
27[137; 145) '(1, "e")': (i32, &str)
28[138; 139) '1': i32
29[141; 144) '"e"': &str
30[155; 156) 'f': ((i32, &str), &str)
31[159; 167) '(e, "d")': ((i32, &str), &str)
32[160; 161) 'e': (i32, &str)
33[163; 166) '"d"': &str
34
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_tuple_struct_generics.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_tuple_struct_generics.snap
deleted file mode 100644
index 783795cfd..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_tuple_struct_generics.snap
+++ /dev/null
@@ -1,23 +0,0 @@
1---
2created: "2019-02-20T21:31:12.911275141Z"
3creator: [email protected]
4source: crates/ra_hir/src/ty/tests.rs
5expression: "&result"
6---
7[77; 185) '{ ...one; }': ()
8[83; 84) 'A': A<i32>(T) -> A<T>
9[83; 88) 'A(42)': A<i32>
10[85; 87) '42': i32
11[94; 95) 'A': A<u128>(T) -> A<T>
12[94; 103) 'A(42u128)': A<u128>
13[96; 102) '42u128': u128
14[109; 113) 'Some': Some<&str>(T) -> Option<T>
15[109; 118) 'Some("x")': Option<&str>
16[114; 117) '"x"': &str
17[124; 136) 'Option::Some': Some<&str>(T) -> Option<T>
18[124; 141) 'Option...e("x")': Option<&str>
19[137; 140) '"x"': &str
20[147; 151) 'None': Option<[unknown]>
21[161; 162) 'x': Option<i64>
22[178; 182) 'None': Option<i64>
23
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_type_alias.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_type_alias.snap
deleted file mode 100644
index 241c08353..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_type_alias.snap
+++ /dev/null
@@ -1,23 +0,0 @@
1---
2created: "2019-02-24T16:13:47.561870283Z"
3creator: [email protected]
4source: crates/ra_hir/src/ty/tests.rs
5expression: "&result"
6---
7[117; 118) 'x': A<u32, i128>
8[125; 126) 'y': A<&str, u128>
9[139; 140) 'z': A<u8, i8>
10[155; 212) '{ ...z.y; }': ()
11[161; 162) 'x': A<u32, i128>
12[161; 164) 'x.x': u32
13[170; 171) 'x': A<u32, i128>
14[170; 173) 'x.y': i128
15[179; 180) 'y': A<&str, u128>
16[179; 182) 'y.x': &str
17[188; 189) 'y': A<&str, u128>
18[188; 191) 'y.y': u128
19[197; 198) 'z': A<u8, i8>
20[197; 200) 'z.x': u8
21[206; 207) 'z': A<u8, i8>
22[206; 209) 'z.y': i8
23
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_type_param.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_type_param.snap
deleted file mode 100644
index 216d1e41f..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_type_param.snap
+++ /dev/null
@@ -1,26 +0,0 @@
1---
2created: "2019-01-27T20:38:32.153717698+00:00"
3creator: [email protected]
4expression: "&result"
5source: crates/ra_hir/src/ty/tests.rs
6---
7[10; 11) 'x': T
8[21; 30) '{ x }': T
9[27; 28) 'x': T
10[44; 45) 'x': &T
11[56; 65) '{ x }': &T
12[62; 63) 'x': &T
13[77; 157) '{ ...(1); }': ()
14[87; 88) 'y': u32
15[91; 96) '10u32': u32
16[102; 104) 'id': fn id<u32>(T) -> T
17[102; 107) 'id(y)': u32
18[105; 106) 'y': u32
19[117; 118) 'x': bool
20[127; 132) 'clone': fn clone<bool>(&T) -> T
21[127; 135) 'clone(z)': bool
22[133; 134) 'z': &bool
23[141; 151) 'id::<i128>': fn id<i128>(T) -> T
24[141; 154) 'id::<i128>(1)': i128
25[152; 153) '1': i128
26
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_unary_op.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_unary_op.snap
deleted file mode 100644
index 5021d0eeb..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_unary_op.snap
+++ /dev/null
@@ -1,48 +0,0 @@
1---
2created: "2019-01-28T14:51:16.185273502+00:00"
3creator: [email protected]
4expression: "&result"
5source: crates/ra_hir/src/ty/tests.rs
6---
7[27; 28) 'x': SomeType
8[40; 272) '{ ...lo"; }': ()
9[50; 51) 'b': bool
10[54; 59) 'false': bool
11[69; 70) 'c': bool
12[73; 75) '!b': bool
13[74; 75) 'b': bool
14[85; 86) 'a': i128
15[89; 92) '100': i128
16[102; 103) 'd': i128
17[112; 114) '-a': i128
18[113; 114) 'a': i128
19[124; 125) 'e': i32
20[128; 132) '-100': i32
21[129; 132) '100': i32
22[142; 143) 'f': bool
23[146; 153) '!!!true': bool
24[147; 153) '!!true': bool
25[148; 153) '!true': bool
26[149; 153) 'true': bool
27[163; 164) 'g': i32
28[167; 170) '!42': i32
29[168; 170) '42': i32
30[180; 181) 'h': u32
31[184; 190) '!10u32': u32
32[185; 190) '10u32': u32
33[200; 201) 'j': i128
34[204; 206) '!a': i128
35[205; 206) 'a': i128
36[212; 217) '-3.14': f64
37[213; 217) '3.14': f64
38[223; 225) '!3': i32
39[224; 225) '3': i32
40[231; 233) '-x': [unknown]
41[232; 233) 'x': SomeType
42[239; 241) '!x': [unknown]
43[240; 241) 'x': SomeType
44[247; 255) '-"hello"': [unknown]
45[248; 255) '"hello"': &str
46[261; 269) '!"hello"': [unknown]
47[262; 269) '"hello"': &str
48
diff --git a/crates/ra_hir/src/ty/snapshots/tests__no_panic_on_field_of_enum.snap b/crates/ra_hir/src/ty/snapshots/tests__no_panic_on_field_of_enum.snap
deleted file mode 100644
index b6f404b4c..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__no_panic_on_field_of_enum.snap
+++ /dev/null
@@ -1,11 +0,0 @@
1---
2created: "2019-01-22T14:45:00.058678600+00:00"
3creator: [email protected]
4expression: "&result"
5source: "crates\\ra_hir\\src\\ty\\tests.rs"
6---
7[20; 21) 'x': X
8[26; 47) '{ ...eld; }': ()
9[32; 33) 'x': X
10[32; 44) 'x.some_field': [unknown]
11
diff --git a/crates/ra_hir/src/ty/snapshots/tests__recursive_vars.snap b/crates/ra_hir/src/ty/snapshots/tests__recursive_vars.snap
deleted file mode 100644
index c3227ff7e..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__recursive_vars.snap
+++ /dev/null
@@ -1,14 +0,0 @@
1---
2created: "2019-01-26T22:42:22.329980185+00:00"
3creator: [email protected]
4expression: "&result"
5source: crates/ra_hir/src/ty/tests.rs
6---
7[11; 48) '{ ...&y]; }': ()
8[21; 22) 'y': &[unknown]
9[25; 32) 'unknown': &[unknown]
10[38; 45) '[y, &y]': [&&[unknown]]
11[39; 40) 'y': &[unknown]
12[42; 44) '&y': &&[unknown]
13[43; 44) 'y': &[unknown]
14
diff --git a/crates/ra_hir/src/ty/snapshots/tests__recursive_vars_2.snap b/crates/ra_hir/src/ty/snapshots/tests__recursive_vars_2.snap
deleted file mode 100644
index de124da5b..000000000
--- a/crates/ra_hir/src/ty/snapshots/tests__recursive_vars_2.snap
+++ /dev/null
@@ -1,21 +0,0 @@
1---
2created: "2019-01-26T22:42:22.331805845+00:00"
3creator: [email protected]
4expression: "&result"
5source: crates/ra_hir/src/ty/tests.rs
6---
7[11; 80) '{ ...x)]; }': ()
8[21; 22) 'x': &&[unknown]
9[25; 32) 'unknown': &&[unknown]
10[42; 43) 'y': &&[unknown]
11[46; 53) 'unknown': &&[unknown]
12[59; 77) '[(x, y..., &x)]': [(&&[unknown], &&[unknown])]
13[60; 66) '(x, y)': (&&[unknown], &&[unknown])
14[61; 62) 'x': &&[unknown]
15[64; 65) 'y': &&[unknown]
16[68; 76) '(&y, &x)': (&&&[unknown], &&&[unknown])
17[69; 71) '&y': &&&[unknown]
18[70; 71) 'y': &&[unknown]
19[73; 75) '&x': &&&[unknown]
20[74; 75) 'x': &&[unknown]
21
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index 8de46a29e..c7d409e6d 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -1,6 +1,8 @@
1use std::sync::Arc; 1use std::sync::Arc;
2use std::fmt::Write; 2use std::fmt::Write;
3 3
4use insta::assert_snapshot_matches;
5
4use ra_db::{SourceDatabase, salsa::Database, FilePosition}; 6use ra_db::{SourceDatabase, salsa::Database, FilePosition};
5use ra_syntax::{algo, ast::{self, AstNode}}; 7use ra_syntax::{algo, ast::{self, AstNode}};
6use test_utils::covers; 8use test_utils::covers;
@@ -11,14 +13,13 @@ use crate::{
11}; 13};
12 14
13// These tests compare the inference results for all expressions in a file 15// These tests compare the inference results for all expressions in a file
14// against snapshots of the expected results using insta. Run the tests with 16// against snapshots of the expected results using insta. Use cargo-insta to
15// INSTA_UPDATE=1 to update the snapshots. 17// update the snapshots.
16 18
17#[test] 19#[test]
18fn infer_basics() { 20fn infer_basics() {
19 check_inference( 21 assert_snapshot_matches!(
20 "infer_basics", 22 infer(r#"
21 r#"
22fn test(a: u32, b: isize, c: !, d: &str) { 23fn test(a: u32, b: isize, c: !, d: &str) {
23 a; 24 a;
24 b; 25 b;
@@ -28,29 +29,49 @@ fn test(a: u32, b: isize, c: !, d: &str) {
28 1isize; 29 1isize;
29 "test"; 30 "test";
30 1.0f32; 31 1.0f32;
31}"#, 32}"#),
33 @r###"
34[9; 10) 'a': u32
35[17; 18) 'b': isize
36[27; 28) 'c': !
37[33; 34) 'd': &str
38[42; 121) '{ ...f32; }': ()
39[48; 49) 'a': u32
40[55; 56) 'b': isize
41[62; 63) 'c': !
42[69; 70) 'd': &str
43[76; 82) '1usize': usize
44[88; 94) '1isize': isize
45[100; 106) '"test"': &str
46[112; 118) '1.0f32': f32"###
32 ); 47 );
33} 48}
34 49
35#[test] 50#[test]
36fn infer_let() { 51fn infer_let() {
37 check_inference( 52 assert_snapshot_matches!(
38 "infer_let", 53 infer(r#"
39 r#"
40fn test() { 54fn test() {
41 let a = 1isize; 55 let a = 1isize;
42 let b: usize = 1; 56 let b: usize = 1;
43 let c = b; 57 let c = b;
44} 58}
45}"#, 59}"#),
60 @r###"
61[11; 71) '{ ...= b; }': ()
62[21; 22) 'a': isize
63[25; 31) '1isize': isize
64[41; 42) 'b': usize
65[52; 53) '1': usize
66[63; 64) 'c': usize
67[67; 68) 'b': usize"###
46 ); 68 );
47} 69}
48 70
49#[test] 71#[test]
50fn infer_paths() { 72fn infer_paths() {
51 check_inference( 73 assert_snapshot_matches!(
52 "infer_paths", 74 infer(r#"
53 r#"
54fn a() -> u32 { 1 } 75fn a() -> u32 { 1 }
55 76
56mod b { 77mod b {
@@ -61,15 +82,24 @@ fn test() {
61 a(); 82 a();
62 b::c(); 83 b::c();
63} 84}
64}"#, 85}"#),
86 @r###"
87[15; 20) '{ 1 }': u32
88[17; 18) '1': u32
89[48; 53) '{ 1 }': u32
90[50; 51) '1': u32
91[67; 91) '{ ...c(); }': ()
92[73; 74) 'a': fn a() -> u32
93[73; 76) 'a()': u32
94[82; 86) 'b::c': fn c() -> u32
95[82; 88) 'b::c()': u32"###
65 ); 96 );
66} 97}
67 98
68#[test] 99#[test]
69fn infer_struct() { 100fn infer_struct() {
70 check_inference( 101 assert_snapshot_matches!(
71 "infer_struct", 102 infer(r#"
72 r#"
73struct A { 103struct A {
74 b: B, 104 b: B,
75 c: C, 105 c: C,
@@ -84,15 +114,31 @@ fn test() {
84 a.b; 114 a.b;
85 a.c; 115 a.c;
86} 116}
87"#, 117"#),
118 @r###"
119[72; 154) '{ ...a.c; }': ()
120[82; 83) 'c': C
121[86; 87) 'C': C(usize) -> C
122[86; 90) 'C(1)': C
123[88; 89) '1': usize
124[96; 97) 'B': B
125[107; 108) 'a': A
126[114; 133) 'A { b:...C(1) }': A
127[121; 122) 'B': B
128[127; 128) 'C': C(usize) -> C
129[127; 131) 'C(1)': C
130[129; 130) '1': usize
131[139; 140) 'a': A
132[139; 142) 'a.b': B
133[148; 149) 'a': A
134[148; 151) 'a.c': C"###
88 ); 135 );
89} 136}
90 137
91#[test] 138#[test]
92fn infer_enum() { 139fn infer_enum() {
93 check_inference( 140 assert_snapshot_matches!(
94 "infer_enum", 141 infer(r#"
95 r#"
96enum E { 142enum E {
97 V1 { field: u32 }, 143 V1 { field: u32 },
98 V2 144 V2
@@ -100,15 +146,19 @@ enum E {
100fn test() { 146fn test() {
101 E::V1 { field: 1 }; 147 E::V1 { field: 1 };
102 E::V2; 148 E::V2;
103}"#, 149}"#),
150 @r###"
151[48; 82) '{ E:...:V2; }': ()
152[52; 70) 'E::V1 ...d: 1 }': E
153[67; 68) '1': u32
154[74; 79) 'E::V2': E"###
104 ); 155 );
105} 156}
106 157
107#[test] 158#[test]
108fn infer_refs() { 159fn infer_refs() {
109 check_inference( 160 assert_snapshot_matches!(
110 "infer_refs", 161 infer(r#"
111 r#"
112fn test(a: &u32, b: &mut u32, c: *const u32, d: *mut u32) { 162fn test(a: &u32, b: &mut u32, c: *const u32, d: *mut u32) {
113 a; 163 a;
114 *a; 164 *a;
@@ -122,15 +172,38 @@ fn test(a: &u32, b: &mut u32, c: *const u32, d: *mut u32) {
122 d; 172 d;
123 *d; 173 *d;
124} 174}
125"#, 175"#),
176 @r###"
177[9; 10) 'a': &u32
178[18; 19) 'b': &mut u32
179[31; 32) 'c': *const u32
180[46; 47) 'd': *mut u32
181[59; 150) '{ ... *d; }': ()
182[65; 66) 'a': &u32
183[72; 74) '*a': u32
184[73; 74) 'a': &u32
185[80; 82) '&a': &&u32
186[81; 82) 'a': &u32
187[88; 94) '&mut a': &mut &u32
188[93; 94) 'a': &u32
189[100; 101) 'b': &mut u32
190[107; 109) '*b': u32
191[108; 109) 'b': &mut u32
192[115; 117) '&b': &&mut u32
193[116; 117) 'b': &mut u32
194[123; 124) 'c': *const u32
195[130; 132) '*c': u32
196[131; 132) 'c': *const u32
197[138; 139) 'd': *mut u32
198[145; 147) '*d': u32
199[146; 147) 'd': *mut u32"###
126 ); 200 );
127} 201}
128 202
129#[test] 203#[test]
130fn infer_literals() { 204fn infer_literals() {
131 check_inference( 205 assert_snapshot_matches!(
132 "infer_literals", 206 infer(r##"
133 r##"
134fn test() { 207fn test() {
135 5i32; 208 5i32;
136 "hello"; 209 "hello";
@@ -148,15 +221,27 @@ fn test() {
148 "#; 221 "#;
149 br#"yolo"#; 222 br#"yolo"#;
150} 223}
151"##, 224"##),
225 @r###"
226[11; 201) '{ ...o"#; }': ()
227[17; 21) '5i32': i32
228[27; 34) '"hello"': &str
229[40; 48) 'b"bytes"': &[u8]
230[54; 57) ''c'': char
231[63; 67) 'b'b'': u8
232[73; 77) '3.14': f64
233[83; 87) '5000': i32
234[93; 98) 'false': bool
235[104; 108) 'true': bool
236[114; 182) 'r#" ... "#': &str
237[188; 198) 'br#"yolo"#': &[u8]"###
152 ); 238 );
153} 239}
154 240
155#[test] 241#[test]
156fn infer_unary_op() { 242fn infer_unary_op() {
157 check_inference( 243 assert_snapshot_matches!(
158 "infer_unary_op", 244 infer(r#"
159 r#"
160enum SomeType {} 245enum SomeType {}
161 246
162fn test(x: SomeType) { 247fn test(x: SomeType) {
@@ -176,15 +261,56 @@ fn test(x: SomeType) {
176 -"hello"; 261 -"hello";
177 !"hello"; 262 !"hello";
178} 263}
179"#, 264"#),
265 @r###"
266[27; 28) 'x': SomeType
267[40; 272) '{ ...lo"; }': ()
268[50; 51) 'b': bool
269[54; 59) 'false': bool
270[69; 70) 'c': bool
271[73; 75) '!b': bool
272[74; 75) 'b': bool
273[85; 86) 'a': i128
274[89; 92) '100': i128
275[102; 103) 'd': i128
276[112; 114) '-a': i128
277[113; 114) 'a': i128
278[124; 125) 'e': i32
279[128; 132) '-100': i32
280[129; 132) '100': i32
281[142; 143) 'f': bool
282[146; 153) '!!!true': bool
283[147; 153) '!!true': bool
284[148; 153) '!true': bool
285[149; 153) 'true': bool
286[163; 164) 'g': i32
287[167; 170) '!42': i32
288[168; 170) '42': i32
289[180; 181) 'h': u32
290[184; 190) '!10u32': u32
291[185; 190) '10u32': u32
292[200; 201) 'j': i128
293[204; 206) '!a': i128
294[205; 206) 'a': i128
295[212; 217) '-3.14': f64
296[213; 217) '3.14': f64
297[223; 225) '!3': i32
298[224; 225) '3': i32
299[231; 233) '-x': {unknown}
300[232; 233) 'x': SomeType
301[239; 241) '!x': {unknown}
302[240; 241) 'x': SomeType
303[247; 255) '-"hello"': {unknown}
304[248; 255) '"hello"': &str
305[261; 269) '!"hello"': {unknown}
306[262; 269) '"hello"': &str"###
180 ); 307 );
181} 308}
182 309
183#[test] 310#[test]
184fn infer_backwards() { 311fn infer_backwards() {
185 check_inference( 312 assert_snapshot_matches!(
186 "infer_backwards", 313 infer(r#"
187 r#"
188fn takes_u32(x: u32) {} 314fn takes_u32(x: u32) {}
189 315
190struct S { i32_field: i32 } 316struct S { i32_field: i32 }
@@ -197,15 +323,35 @@ fn test() -> &mut &f64 {
197 let c = unknown_function(); 323 let c = unknown_function();
198 &mut &c 324 &mut &c
199} 325}
200"#, 326"#),
327 @r###"
328[14; 15) 'x': u32
329[22; 24) '{}': ()
330[78; 231) '{ ...t &c }': &mut &f64
331[88; 89) 'a': u32
332[92; 108) 'unknow...nction': {unknown}
333[92; 110) 'unknow...tion()': u32
334[116; 125) 'takes_u32': fn takes_u32(u32) -> ()
335[116; 128) 'takes_u32(a)': ()
336[126; 127) 'a': u32
337[138; 139) 'b': i32
338[142; 158) 'unknow...nction': {unknown}
339[142; 160) 'unknow...tion()': i32
340[166; 184) 'S { i3...d: b }': S
341[181; 182) 'b': i32
342[194; 195) 'c': f64
343[198; 214) 'unknow...nction': {unknown}
344[198; 216) 'unknow...tion()': f64
345[222; 229) '&mut &c': &mut &f64
346[227; 229) '&c': &f64
347[228; 229) 'c': f64"###
201 ); 348 );
202} 349}
203 350
204#[test] 351#[test]
205fn infer_self() { 352fn infer_self() {
206 check_inference( 353 assert_snapshot_matches!(
207 "infer_self", 354 infer(r#"
208 r#"
209struct S; 355struct S;
210 356
211impl S { 357impl S {
@@ -222,15 +368,25 @@ impl S {
222 Self {} 368 Self {}
223 } 369 }
224} 370}
225"#, 371"#),
372 @r###"
373[34; 38) 'self': &S
374[40; 61) '{ ... }': ()
375[50; 54) 'self': &S
376[75; 79) 'self': &S
377[88; 109) '{ ... }': ()
378[98; 102) 'self': &S
379[133; 153) '{ ... }': S
380[143; 147) 'S {}': S
381[177; 200) '{ ... }': S
382[187; 194) 'Self {}': S"###
226 ); 383 );
227} 384}
228 385
229#[test] 386#[test]
230fn infer_binary_op() { 387fn infer_binary_op() {
231 check_inference( 388 assert_snapshot_matches!(
232 "infer_binary_op", 389 infer(r#"
233 r#"
234fn f(x: bool) -> i32 { 390fn f(x: bool) -> i32 {
235 0i32 391 0i32
236} 392}
@@ -250,15 +406,65 @@ fn test() -> bool {
250 406
251 ten < 3 407 ten < 3
252} 408}
253"#, 409"#),
410 @r###"
411[6; 7) 'x': bool
412[22; 34) '{ 0i32 }': i32
413[28; 32) '0i32': i32
414[54; 370) '{ ... < 3 }': bool
415[64; 65) 'x': bool
416[68; 69) 'a': bool
417[68; 74) 'a && b': bool
418[73; 74) 'b': bool
419[84; 85) 'y': bool
420[88; 92) 'true': bool
421[88; 101) 'true || false': bool
422[96; 101) 'false': bool
423[111; 112) 'z': bool
424[115; 116) 'x': bool
425[115; 121) 'x == y': bool
426[120; 121) 'y': bool
427[131; 132) 't': bool
428[135; 136) 'x': bool
429[135; 141) 'x != y': bool
430[140; 141) 'y': bool
431[151; 162) 'minus_forty': isize
432[172; 180) '-40isize': isize
433[173; 180) '40isize': isize
434[190; 191) 'h': bool
435[194; 205) 'minus_forty': isize
436[194; 216) 'minus_...ONST_2': bool
437[209; 216) 'CONST_2': isize
438[226; 227) 'c': i32
439[230; 231) 'f': fn f(bool) -> i32
440[230; 239) 'f(z || y)': i32
441[230; 243) 'f(z || y) + 5': i32
442[232; 233) 'z': bool
443[232; 238) 'z || y': bool
444[237; 238) 'y': bool
445[242; 243) '5': i32
446[253; 254) 'd': {unknown}
447[257; 258) 'b': {unknown}
448[268; 269) 'g': ()
449[272; 283) 'minus_forty': isize
450[272; 288) 'minus_...y ^= i': ()
451[287; 288) 'i': isize
452[298; 301) 'ten': usize
453[311; 313) '10': usize
454[323; 336) 'ten_is_eleven': bool
455[339; 342) 'ten': usize
456[339; 354) 'ten == some_num': bool
457[346; 354) 'some_num': usize
458[361; 364) 'ten': usize
459[361; 368) 'ten < 3': bool
460[367; 368) '3': usize"###
254 ); 461 );
255} 462}
256 463
257#[test] 464#[test]
258fn infer_field_autoderef() { 465fn infer_field_autoderef() {
259 check_inference( 466 assert_snapshot_matches!(
260 "infer_field_autoderef", 467 infer(r#"
261 r#"
262struct A { 468struct A {
263 b: B, 469 b: B,
264} 470}
@@ -281,27 +487,75 @@ fn test2(a1: *const A, a2: *mut A) {
281 a1.b; 487 a1.b;
282 a2.b; 488 a2.b;
283} 489}
284"#, 490"#),
491 @r###"
492[44; 45) 'a': A
493[50; 213) '{ ...5.b; }': ()
494[60; 62) 'a1': A
495[65; 66) 'a': A
496[72; 74) 'a1': A
497[72; 76) 'a1.b': B
498[86; 88) 'a2': &A
499[91; 93) '&a': &A
500[92; 93) 'a': A
501[99; 101) 'a2': &A
502[99; 103) 'a2.b': B
503[113; 115) 'a3': &mut A
504[118; 124) '&mut a': &mut A
505[123; 124) 'a': A
506[130; 132) 'a3': &mut A
507[130; 134) 'a3.b': B
508[144; 146) 'a4': &&&&&&&A
509[149; 157) '&&&&&&&a': &&&&&&&A
510[150; 157) '&&&&&&a': &&&&&&A
511[151; 157) '&&&&&a': &&&&&A
512[152; 157) '&&&&a': &&&&A
513[153; 157) '&&&a': &&&A
514[154; 157) '&&a': &&A
515[155; 157) '&a': &A
516[156; 157) 'a': A
517[163; 165) 'a4': &&&&&&&A
518[163; 167) 'a4.b': B
519[177; 179) 'a5': &mut &&mut &&mut A
520[182; 200) '&mut &...&mut a': &mut &&mut &&mut A
521[187; 200) '&&mut &&mut a': &&mut &&mut A
522[188; 200) '&mut &&mut a': &mut &&mut A
523[193; 200) '&&mut a': &&mut A
524[194; 200) '&mut a': &mut A
525[199; 200) 'a': A
526[206; 208) 'a5': &mut &&mut &&mut A
527[206; 210) 'a5.b': B
528[224; 226) 'a1': *const A
529[238; 240) 'a2': *mut A
530[250; 273) '{ ...2.b; }': ()
531[256; 258) 'a1': *const A
532[256; 260) 'a1.b': B
533[266; 268) 'a2': *mut A
534[266; 270) 'a2.b': B"###
285 ); 535 );
286} 536}
287 537
288#[test] 538#[test]
289fn bug_484() { 539fn bug_484() {
290 check_inference( 540 assert_snapshot_matches!(
291 "bug_484", 541 infer(r#"
292 r#"
293fn test() { 542fn test() {
294 let x = if true {}; 543 let x = if true {};
295} 544}
296"#, 545"#),
546 @r###"
547[11; 37) '{ l... {}; }': ()
548[20; 21) 'x': ()
549[24; 34) 'if true {}': ()
550[27; 31) 'true': bool
551[32; 34) '{}': ()"###
297 ); 552 );
298} 553}
299 554
300#[test] 555#[test]
301fn infer_in_elseif() { 556fn infer_in_elseif() {
302 check_inference( 557 assert_snapshot_matches!(
303 "infer_in_elseif", 558 infer(r#"
304 r#"
305struct Foo { field: i32 } 559struct Foo { field: i32 }
306fn main(foo: Foo) { 560fn main(foo: Foo) {
307 if true { 561 if true {
@@ -310,15 +564,25 @@ fn main(foo: Foo) {
310 foo.field 564 foo.field
311 } 565 }
312} 566}
313"#, 567"#),
568 @r###"
569[35; 38) 'foo': Foo
570[45; 109) '{ ... } }': ()
571[51; 107) 'if tru... }': ()
572[54; 58) 'true': bool
573[59; 67) '{ }': ()
574[73; 107) 'if fal... }': i32
575[76; 81) 'false': bool
576[82; 107) '{ ... }': i32
577[92; 95) 'foo': Foo
578[92; 101) 'foo.field': i32"###
314 ) 579 )
315} 580}
316 581
317#[test] 582#[test]
318fn infer_inherent_method() { 583fn infer_inherent_method() {
319 check_inference( 584 assert_snapshot_matches!(
320 "infer_inherent_method", 585 infer(r#"
321 r#"
322struct A; 586struct A;
323 587
324impl A { 588impl A {
@@ -336,15 +600,33 @@ fn test(a: A) {
336 (&a).bar(1); 600 (&a).bar(1);
337 a.bar(1); 601 a.bar(1);
338} 602}
339"#, 603"#),
604 @r###"
605[32; 36) 'self': A
606[38; 39) 'x': u32
607[53; 55) '{}': ()
608[103; 107) 'self': &A
609[109; 110) 'x': u64
610[124; 126) '{}': ()
611[144; 145) 'a': A
612[150; 198) '{ ...(1); }': ()
613[156; 157) 'a': A
614[156; 164) 'a.foo(1)': i32
615[162; 163) '1': u32
616[170; 181) '(&a).bar(1)': i64
617[171; 173) '&a': &A
618[172; 173) 'a': A
619[179; 180) '1': u64
620[187; 188) 'a': A
621[187; 195) 'a.bar(1)': i64
622[193; 194) '1': u64"###
340 ); 623 );
341} 624}
342 625
343#[test] 626#[test]
344fn infer_tuple() { 627fn infer_tuple() {
345 check_inference( 628 assert_snapshot_matches!(
346 "infer_tuple", 629 infer(r#"
347 r#"
348fn test(x: &str, y: isize) { 630fn test(x: &str, y: isize) {
349 let a: (u32, &str) = (1, "a"); 631 let a: (u32, &str) = (1, "a");
350 let b = (a, x); 632 let b = (a, x);
@@ -353,15 +635,42 @@ fn test(x: &str, y: isize) {
353 let e = (1, "e"); 635 let e = (1, "e");
354 let f = (e, "d"); 636 let f = (e, "d");
355} 637}
356"#, 638"#),
639 @r###"
640[9; 10) 'x': &str
641[18; 19) 'y': isize
642[28; 170) '{ ...d"); }': ()
643[38; 39) 'a': (u32, &str)
644[55; 63) '(1, "a")': (u32, &str)
645[56; 57) '1': u32
646[59; 62) '"a"': &str
647[73; 74) 'b': ((u32, &str), &str)
648[77; 83) '(a, x)': ((u32, &str), &str)
649[78; 79) 'a': (u32, &str)
650[81; 82) 'x': &str
651[93; 94) 'c': (isize, &str)
652[97; 103) '(y, x)': (isize, &str)
653[98; 99) 'y': isize
654[101; 102) 'x': &str
655[113; 114) 'd': ((isize, &str), &str)
656[117; 123) '(c, x)': ((isize, &str), &str)
657[118; 119) 'c': (isize, &str)
658[121; 122) 'x': &str
659[133; 134) 'e': (i32, &str)
660[137; 145) '(1, "e")': (i32, &str)
661[138; 139) '1': i32
662[141; 144) '"e"': &str
663[155; 156) 'f': ((i32, &str), &str)
664[159; 167) '(e, "d")': ((i32, &str), &str)
665[160; 161) 'e': (i32, &str)
666[163; 166) '"d"': &str"###
357 ); 667 );
358} 668}
359 669
360#[test] 670#[test]
361fn infer_array() { 671fn infer_array() {
362 check_inference( 672 assert_snapshot_matches!(
363 "infer_array", 673 infer(r#"
364 r#"
365fn test(x: &str, y: isize) { 674fn test(x: &str, y: isize) {
366 let a = [x]; 675 let a = [x];
367 let b = [a, a]; 676 let b = [a, a];
@@ -380,15 +689,73 @@ fn test(x: &str, y: isize) {
380 let x: [u8; 0] = []; 689 let x: [u8; 0] = [];
381 let z: &[u8] = &[1, 2, 3]; 690 let z: &[u8] = &[1, 2, 3];
382} 691}
383"#, 692"#),
693 @r###"
694[9; 10) 'x': &str
695[18; 19) 'y': isize
696[28; 324) '{ ... 3]; }': ()
697[38; 39) 'a': [&str]
698[42; 45) '[x]': [&str]
699[43; 44) 'x': &str
700[55; 56) 'b': [[&str]]
701[59; 65) '[a, a]': [[&str]]
702[60; 61) 'a': [&str]
703[63; 64) 'a': [&str]
704[75; 76) 'c': [[[&str]]]
705[79; 85) '[b, b]': [[[&str]]]
706[80; 81) 'b': [[&str]]
707[83; 84) 'b': [[&str]]
708[96; 97) 'd': [isize]
709[100; 112) '[y, 1, 2, 3]': [isize]
710[101; 102) 'y': isize
711[104; 105) '1': isize
712[107; 108) '2': isize
713[110; 111) '3': isize
714[122; 123) 'd': [isize]
715[126; 138) '[1, y, 2, 3]': [isize]
716[127; 128) '1': isize
717[130; 131) 'y': isize
718[133; 134) '2': isize
719[136; 137) '3': isize
720[148; 149) 'e': [isize]
721[152; 155) '[y]': [isize]
722[153; 154) 'y': isize
723[165; 166) 'f': [[isize]]
724[169; 175) '[d, d]': [[isize]]
725[170; 171) 'd': [isize]
726[173; 174) 'd': [isize]
727[185; 186) 'g': [[isize]]
728[189; 195) '[e, e]': [[isize]]
729[190; 191) 'e': [isize]
730[193; 194) 'e': [isize]
731[206; 207) 'h': [i32]
732[210; 216) '[1, 2]': [i32]
733[211; 212) '1': i32
734[214; 215) '2': i32
735[226; 227) 'i': [&str]
736[230; 240) '["a", "b"]': [&str]
737[231; 234) '"a"': &str
738[236; 239) '"b"': &str
739[251; 252) 'b': [[&str]]
740[255; 265) '[a, ["b"]]': [[&str]]
741[256; 257) 'a': [&str]
742[259; 264) '["b"]': [&str]
743[260; 263) '"b"': &str
744[275; 276) 'x': [u8]
745[288; 290) '[]': [u8]
746[300; 301) 'z': &[u8]
747[311; 321) '&[1, 2, 3]': &[u8]
748[312; 321) '[1, 2, 3]': [u8]
749[313; 314) '1': u8
750[316; 317) '2': u8
751[319; 320) '3': u8"###
384 ); 752 );
385} 753}
386 754
387#[test] 755#[test]
388fn infer_pattern() { 756fn infer_pattern() {
389 check_inference( 757 assert_snapshot_matches!(
390 "infer_pattern", 758 infer(r#"
391 r#"
392fn test(x: &i32) { 759fn test(x: &i32) {
393 let y = x; 760 let y = x;
394 let &z = x; 761 let &z = x;
@@ -410,15 +777,62 @@ fn test(x: &i32) {
410 let ref mut mut_ref_to_x = x; 777 let ref mut mut_ref_to_x = x;
411 let k = mut_ref_to_x; 778 let k = mut_ref_to_x;
412} 779}
413"#, 780"#),
781 @r###"
782[9; 10) 'x': &i32
783[18; 369) '{ ...o_x; }': ()
784[28; 29) 'y': &i32
785[32; 33) 'x': &i32
786[43; 45) '&z': &i32
787[44; 45) 'z': i32
788[48; 49) 'x': &i32
789[59; 60) 'a': i32
790[63; 64) 'z': i32
791[74; 80) '(c, d)': (i32, &str)
792[75; 76) 'c': i32
793[78; 79) 'd': &str
794[83; 95) '(1, "hello")': (i32, &str)
795[84; 85) '1': i32
796[87; 94) '"hello"': &str
797[102; 152) 'for (e... }': ()
798[106; 112) '(e, f)': ({unknown}, {unknown})
799[107; 108) 'e': {unknown}
800[110; 111) 'f': {unknown}
801[116; 125) 'some_iter': {unknown}
802[126; 152) '{ ... }': ()
803[140; 141) 'g': {unknown}
804[144; 145) 'e': {unknown}
805[158; 205) 'if let... }': ()
806[165; 170) '[val]': {unknown}
807[173; 176) 'opt': {unknown}
808[177; 205) '{ ... }': ()
809[191; 192) 'h': {unknown}
810[195; 198) 'val': {unknown}
811[215; 221) 'lambda': {unknown}
812[224; 256) '|a: u6...b; c }': {unknown}
813[225; 226) 'a': u64
814[233; 234) 'b': u64
815[236; 237) 'c': i32
816[244; 256) '{ a + b; c }': i32
817[246; 247) 'a': u64
818[246; 251) 'a + b': u64
819[250; 251) 'b': u64
820[253; 254) 'c': i32
821[267; 279) 'ref ref_to_x': &&i32
822[282; 283) 'x': &i32
823[293; 302) 'mut mut_x': &i32
824[305; 306) 'x': &i32
825[316; 336) 'ref mu...f_to_x': &mut &i32
826[339; 340) 'x': &i32
827[350; 351) 'k': &mut &i32
828[354; 366) 'mut_ref_to_x': &mut &i32"###
414 ); 829 );
415} 830}
416 831
417#[test] 832#[test]
418fn infer_adt_pattern() { 833fn infer_adt_pattern() {
419 check_inference( 834 assert_snapshot_matches!(
420 "infer_adt_pattern", 835 infer(r#"
421 r#"
422enum E { 836enum E {
423 A { x: usize }, 837 A { x: usize },
424 B 838 B
@@ -441,15 +855,40 @@ fn test() {
441 let ref d @ E::A { .. } = e; 855 let ref d @ E::A { .. } = e;
442 d; 856 d;
443} 857}
444"#, 858"#),
859 @r###"
860[68; 289) '{ ... d; }': ()
861[78; 79) 'e': E
862[82; 95) 'E::A { x: 3 }': E
863[92; 93) '3': usize
864[106; 113) 'S(y, z)': S
865[108; 109) 'y': u32
866[111; 112) 'z': E
867[116; 119) 'foo': S
868[129; 148) 'E::A {..._var }': E
869[139; 146) 'new_var': usize
870[151; 152) 'e': E
871[159; 245) 'match ... }': usize
872[165; 166) 'e': E
873[177; 187) 'E::A { x }': E
874[184; 185) 'x': usize
875[191; 192) 'x': usize
876[202; 206) 'E::B': E
877[210; 213) 'foo': bool
878[217; 218) '1': usize
879[228; 232) 'E::B': E
880[236; 238) '10': usize
881[256; 275) 'ref d ...{ .. }': &E
882[264; 275) 'E::A { .. }': E
883[278; 279) 'e': E
884[285; 286) 'd': &E"###
445 ); 885 );
446} 886}
447 887
448#[test] 888#[test]
449fn infer_struct_generics() { 889fn infer_struct_generics() {
450 check_inference( 890 assert_snapshot_matches!(
451 "infer_struct_generics", 891 infer(r#"
452 r#"
453struct A<T> { 892struct A<T> {
454 x: T, 893 x: T,
455} 894}
@@ -461,15 +900,30 @@ fn test(a1: A<u32>, i: i32) {
461 let a3 = A::<i128> { x: 1 }; 900 let a3 = A::<i128> { x: 1 };
462 a3.x; 901 a3.x;
463} 902}
464"#, 903"#),
904 @r###"
905[36; 38) 'a1': A<u32>
906[48; 49) 'i': i32
907[56; 147) '{ ...3.x; }': ()
908[62; 64) 'a1': A<u32>
909[62; 66) 'a1.x': u32
910[76; 78) 'a2': A<i32>
911[81; 91) 'A { x: i }': A<i32>
912[88; 89) 'i': i32
913[97; 99) 'a2': A<i32>
914[97; 101) 'a2.x': i32
915[111; 113) 'a3': A<i128>
916[116; 134) 'A::<i1...x: 1 }': A<i128>
917[131; 132) '1': i128
918[140; 142) 'a3': A<i128>
919[140; 144) 'a3.x': i128"###
465 ); 920 );
466} 921}
467 922
468#[test] 923#[test]
469fn infer_tuple_struct_generics() { 924fn infer_tuple_struct_generics() {
470 check_inference( 925 assert_snapshot_matches!(
471 "infer_tuple_struct_generics", 926 infer(r#"
472 r#"
473struct A<T>(T); 927struct A<T>(T);
474enum Option<T> { Some(T), None }; 928enum Option<T> { Some(T), None };
475use Option::*; 929use Option::*;
@@ -482,15 +936,31 @@ fn test() {
482 None; 936 None;
483 let x: Option<i64> = None; 937 let x: Option<i64> = None;
484} 938}
485"#, 939"#),
940 @r###"
941[77; 185) '{ ...one; }': ()
942[83; 84) 'A': A<i32>(T) -> A<T>
943[83; 88) 'A(42)': A<i32>
944[85; 87) '42': i32
945[94; 95) 'A': A<u128>(T) -> A<T>
946[94; 103) 'A(42u128)': A<u128>
947[96; 102) '42u128': u128
948[109; 113) 'Some': Some<&str>(T) -> Option<T>
949[109; 118) 'Some("x")': Option<&str>
950[114; 117) '"x"': &str
951[124; 136) 'Option::Some': Some<&str>(T) -> Option<T>
952[124; 141) 'Option...e("x")': Option<&str>
953[137; 140) '"x"': &str
954[147; 151) 'None': Option<{unknown}>
955[161; 162) 'x': Option<i64>
956[178; 182) 'None': Option<i64>"###
486 ); 957 );
487} 958}
488 959
489#[test] 960#[test]
490fn infer_generics_in_patterns() { 961fn infer_generics_in_patterns() {
491 check_inference( 962 assert_snapshot_matches!(
492 "infer_generics_in_patterns", 963 infer(r#"
493 r#"
494struct A<T> { 964struct A<T> {
495 x: T, 965 x: T,
496} 966}
@@ -508,15 +978,32 @@ fn test(a1: A<u32>, o: Option<u64>) {
508 _ => 1, 978 _ => 1,
509 }; 979 };
510} 980}
511"#, 981"#),
982 @r###"
983[79; 81) 'a1': A<u32>
984[91; 92) 'o': Option<u64>
985[107; 244) '{ ... }; }': ()
986[117; 128) 'A { x: x2 }': A<u32>
987[124; 126) 'x2': u32
988[131; 133) 'a1': A<u32>
989[143; 161) 'A::<i6...: x3 }': A<i64>
990[157; 159) 'x3': i64
991[164; 174) 'A { x: 1 }': A<i64>
992[171; 172) '1': i64
993[180; 241) 'match ... }': u64
994[186; 187) 'o': Option<u64>
995[198; 213) 'Option::Some(t)': Option<u64>
996[211; 212) 't': u64
997[217; 218) 't': u64
998[228; 229) '_': Option<u64>
999[233; 234) '1': u64"###
512 ); 1000 );
513} 1001}
514 1002
515#[test] 1003#[test]
516fn infer_function_generics() { 1004fn infer_function_generics() {
517 check_inference( 1005 assert_snapshot_matches!(
518 "infer_function_generics", 1006 infer(r#"
519 r#"
520fn id<T>(t: T) -> T { t } 1007fn id<T>(t: T) -> T { t }
521 1008
522fn test() { 1009fn test() {
@@ -524,15 +1011,29 @@ fn test() {
524 id::<i128>(1); 1011 id::<i128>(1);
525 let x: u64 = id(1); 1012 let x: u64 = id(1);
526} 1013}
527"#, 1014"#),
1015 @r###"
1016[10; 11) 't': T
1017[21; 26) '{ t }': T
1018[23; 24) 't': T
1019[38; 98) '{ ...(1); }': ()
1020[44; 46) 'id': fn id<u32>(T) -> T
1021[44; 52) 'id(1u32)': u32
1022[47; 51) '1u32': u32
1023[58; 68) 'id::<i128>': fn id<i128>(T) -> T
1024[58; 71) 'id::<i128>(1)': i128
1025[69; 70) '1': i128
1026[81; 82) 'x': u64
1027[90; 92) 'id': fn id<u64>(T) -> T
1028[90; 95) 'id(1)': u64
1029[93; 94) '1': u64"###
528 ); 1030 );
529} 1031}
530 1032
531#[test] 1033#[test]
532fn infer_impl_generics() { 1034fn infer_impl_generics() {
533 check_inference( 1035 assert_snapshot_matches!(
534 "infer_impl_generics", 1036 infer(r#"
535 r#"
536struct A<T1, T2> { 1037struct A<T1, T2> {
537 x: T1, 1038 x: T1,
538 y: T2, 1039 y: T2,
@@ -556,15 +1057,47 @@ fn test() -> i128 {
556 a.z(1i128); 1057 a.z(1i128);
557 a.z::<u128>(1); 1058 a.z::<u128>(1);
558} 1059}
559"#, 1060"#),
1061 @r###"
1062[74; 78) 'self': A<X, Y>
1063[85; 107) '{ ... }': X
1064[95; 99) 'self': A<X, Y>
1065[95; 101) 'self.x': X
1066[117; 121) 'self': A<X, Y>
1067[128; 150) '{ ... }': Y
1068[138; 142) 'self': A<X, Y>
1069[138; 144) 'self.y': Y
1070[163; 167) 'self': A<X, Y>
1071[169; 170) 't': T
1072[188; 223) '{ ... }': (X, Y, T)
1073[198; 217) '(self.....y, t)': (X, Y, T)
1074[199; 203) 'self': A<X, Y>
1075[199; 205) 'self.x': X
1076[207; 211) 'self': A<X, Y>
1077[207; 213) 'self.y': Y
1078[215; 216) 't': T
1079[245; 342) '{ ...(1); }': ()
1080[255; 256) 'a': A<u64, i64>
1081[259; 281) 'A { x:...1i64 }': A<u64, i64>
1082[266; 270) '1u64': u64
1083[275; 279) '1i64': i64
1084[287; 288) 'a': A<u64, i64>
1085[287; 292) 'a.x()': u64
1086[298; 299) 'a': A<u64, i64>
1087[298; 303) 'a.y()': i64
1088[309; 310) 'a': A<u64, i64>
1089[309; 319) 'a.z(1i128)': (u64, i64, i128)
1090[313; 318) '1i128': i128
1091[325; 326) 'a': A<u64, i64>
1092[325; 339) 'a.z::<u128>(1)': (u64, i64, u128)
1093[337; 338) '1': u128"###
560 ); 1094 );
561} 1095}
562 1096
563#[test] 1097#[test]
564fn infer_impl_generics_with_autoderef() { 1098fn infer_impl_generics_with_autoderef() {
565 check_inference( 1099 assert_snapshot_matches!(
566 "infer_impl_generics_with_autoderef", 1100 infer(r#"
567 r#"
568enum Option<T> { 1101enum Option<T> {
569 Some(T), 1102 Some(T),
570 None, 1103 None,
@@ -576,15 +1109,24 @@ fn test(o: Option<u32>) {
576 (&o).as_ref(); 1109 (&o).as_ref();
577 o.as_ref(); 1110 o.as_ref();
578} 1111}
579"#, 1112"#),
1113 @r###"
1114[78; 82) 'self': &Option<T>
1115[98; 100) '{}': ()
1116[111; 112) 'o': Option<u32>
1117[127; 165) '{ ...f(); }': ()
1118[133; 146) '(&o).as_ref()': Option<&u32>
1119[134; 136) '&o': &Option<u32>
1120[135; 136) 'o': Option<u32>
1121[152; 153) 'o': Option<u32>
1122[152; 162) 'o.as_ref()': Option<&u32>"###
580 ); 1123 );
581} 1124}
582 1125
583#[test] 1126#[test]
584fn infer_generic_chain() { 1127fn infer_generic_chain() {
585 check_inference( 1128 assert_snapshot_matches!(
586 "infer_generic_chain", 1129 infer(r#"
587 r#"
588struct A<T> { 1130struct A<T> {
589 x: T, 1131 x: T,
590} 1132}
@@ -603,15 +1145,44 @@ fn test() -> i128 {
603 let b = A { x: z }; 1145 let b = A { x: z };
604 b.x() 1146 b.x()
605} 1147}
606"#, 1148"#),
1149 @r###"
1150[53; 57) 'self': A<T2>
1151[65; 87) '{ ... }': T2
1152[75; 79) 'self': A<T2>
1153[75; 81) 'self.x': T2
1154[99; 100) 't': T
1155[110; 115) '{ t }': T
1156[112; 113) 't': T
1157[135; 261) '{ ....x() }': i128
1158[146; 147) 'x': i128
1159[150; 151) '1': i128
1160[162; 163) 'y': i128
1161[166; 168) 'id': fn id<i128>(T) -> T
1162[166; 171) 'id(x)': i128
1163[169; 170) 'x': i128
1164[182; 183) 'a': A<i128>
1165[186; 200) 'A { x: id(y) }': A<i128>
1166[193; 195) 'id': fn id<i128>(T) -> T
1167[193; 198) 'id(y)': i128
1168[196; 197) 'y': i128
1169[211; 212) 'z': i128
1170[215; 217) 'id': fn id<i128>(T) -> T
1171[215; 222) 'id(a.x)': i128
1172[218; 219) 'a': A<i128>
1173[218; 221) 'a.x': i128
1174[233; 234) 'b': A<i128>
1175[237; 247) 'A { x: z }': A<i128>
1176[244; 245) 'z': i128
1177[254; 255) 'b': A<i128>
1178[254; 259) 'b.x()': i128"###
607 ); 1179 );
608} 1180}
609 1181
610#[test] 1182#[test]
611fn infer_associated_const() { 1183fn infer_associated_const() {
612 check_inference( 1184 assert_snapshot_matches!(
613 "infer_associated_const", 1185 infer(r#"
614 r#"
615struct Struct; 1186struct Struct;
616 1187
617impl Struct { 1188impl Struct {
@@ -639,15 +1210,22 @@ fn test() {
639 let y = Enum::BAR; 1210 let y = Enum::BAR;
640 let z = TraitTest::ID; 1211 let z = TraitTest::ID;
641} 1212}
642"#, 1213"#),
1214 @r###"
1215[227; 305) '{ ...:ID; }': ()
1216[237; 238) 'x': u32
1217[241; 252) 'Struct::FOO': u32
1218[262; 263) 'y': u32
1219[266; 275) 'Enum::BAR': u32
1220[285; 286) 'z': u32
1221[289; 302) 'TraitTest::ID': u32"###
643 ); 1222 );
644} 1223}
645 1224
646#[test] 1225#[test]
647fn infer_associated_method_struct() { 1226fn infer_associated_method_struct() {
648 check_inference( 1227 assert_snapshot_matches!(
649 "infer_associated_method_struct", 1228 infer(r#"
650 r#"
651struct A { x: u32 }; 1229struct A { x: u32 };
652 1230
653impl A { 1231impl A {
@@ -659,15 +1237,24 @@ fn test() {
659 let a = A::new(); 1237 let a = A::new();
660 a.x; 1238 a.x;
661} 1239}
662"#, 1240"#),
1241 @r###"
1242[50; 76) '{ ... }': A
1243[60; 70) 'A { x: 0 }': A
1244[67; 68) '0': u32
1245[89; 123) '{ ...a.x; }': ()
1246[99; 100) 'a': A
1247[103; 109) 'A::new': fn new() -> A
1248[103; 111) 'A::new()': A
1249[117; 118) 'a': A
1250[117; 120) 'a.x': u32"###
663 ); 1251 );
664} 1252}
665 1253
666#[test] 1254#[test]
667fn infer_associated_method_enum() { 1255fn infer_associated_method_enum() {
668 check_inference( 1256 assert_snapshot_matches!(
669 "infer_associated_method_enum", 1257 infer(r#"
670 r#"
671enum A { B, C }; 1258enum A { B, C };
672 1259
673impl A { 1260impl A {
@@ -684,15 +1271,28 @@ fn test() {
684 let c = A::c(); 1271 let c = A::c();
685 c; 1272 c;
686} 1273}
687"#, 1274"#),
1275 @r###"
1276[48; 68) '{ ... }': A
1277[58; 62) 'A::B': A
1278[89; 109) '{ ... }': A
1279[99; 103) 'A::C': A
1280[122; 179) '{ ... c; }': ()
1281[132; 133) 'a': A
1282[136; 140) 'A::b': fn b() -> A
1283[136; 142) 'A::b()': A
1284[148; 149) 'a': A
1285[159; 160) 'c': A
1286[163; 167) 'A::c': fn c() -> A
1287[163; 169) 'A::c()': A
1288[175; 176) 'c': A"###
688 ); 1289 );
689} 1290}
690 1291
691#[test] 1292#[test]
692fn infer_associated_method_with_modules() { 1293fn infer_associated_method_with_modules() {
693 check_inference( 1294 assert_snapshot_matches!(
694 "infer_associated_method_with_modules", 1295 infer(r#"
695 r#"
696mod a { 1296mod a {
697 struct A; 1297 struct A;
698 impl A { pub fn thing() -> A { A {} }} 1298 impl A { pub fn thing() -> A { A {} }}
@@ -714,15 +1314,31 @@ fn test() {
714 let y = b::B::thing(); 1314 let y = b::B::thing();
715 let z = c::C::thing(); 1315 let z = c::C::thing();
716} 1316}
717"#, 1317"#),
1318 @r###"
1319[56; 64) '{ A {} }': A
1320[58; 62) 'A {}': A
1321[126; 132) '{ 99 }': u32
1322[128; 130) '99': u32
1323[202; 210) '{ C {} }': C
1324[204; 208) 'C {}': C
1325[241; 325) '{ ...g(); }': ()
1326[251; 252) 'x': A
1327[255; 266) 'a::A::thing': fn thing() -> A
1328[255; 268) 'a::A::thing()': A
1329[278; 279) 'y': u32
1330[282; 293) 'b::B::thing': fn thing() -> u32
1331[282; 295) 'b::B::thing()': u32
1332[305; 306) 'z': C
1333[309; 320) 'c::C::thing': fn thing() -> C
1334[309; 322) 'c::C::thing()': C"###
718 ); 1335 );
719} 1336}
720 1337
721#[test] 1338#[test]
722fn infer_associated_method_generics() { 1339fn infer_associated_method_generics() {
723 check_inference( 1340 assert_snapshot_matches!(
724 "infer_associated_method_generics", 1341 infer(r#"
725 r#"
726struct Gen<T> { 1342struct Gen<T> {
727 val: T 1343 val: T
728} 1344}
@@ -736,15 +1352,24 @@ impl<T> Gen<T> {
736fn test() { 1352fn test() {
737 let a = Gen::make(0u32); 1353 let a = Gen::make(0u32);
738} 1354}
739"#, 1355"#),
1356 @r###"
1357[64; 67) 'val': T
1358[82; 109) '{ ... }': Gen<T>
1359[92; 103) 'Gen { val }': Gen<T>
1360[98; 101) 'val': T
1361[123; 155) '{ ...32); }': ()
1362[133; 134) 'a': Gen<u32>
1363[137; 146) 'Gen::make': fn make<u32>(T) -> Gen<T>
1364[137; 152) 'Gen::make(0u32)': Gen<u32>
1365[147; 151) '0u32': u32"###
740 ); 1366 );
741} 1367}
742 1368
743#[test] 1369#[test]
744fn infer_type_alias() { 1370fn infer_type_alias() {
745 check_inference( 1371 assert_snapshot_matches!(
746 "infer_type_alias", 1372 infer(r#"
747 r#"
748struct A<X, Y> { x: X, y: Y }; 1373struct A<X, Y> { x: X, y: Y };
749type Foo = A<u32, i128>; 1374type Foo = A<u32, i128>;
750type Bar<T> = A<T, u128>; 1375type Bar<T> = A<T, u128>;
@@ -757,43 +1382,63 @@ fn test(x: Foo, y: Bar<&str>, z: Baz<i8, u8>) {
757 z.x; 1382 z.x;
758 z.y; 1383 z.y;
759} 1384}
760"#, 1385"#),
1386 @r###"
1387[117; 118) 'x': A<u32, i128>
1388[125; 126) 'y': A<&str, u128>
1389[139; 140) 'z': A<u8, i8>
1390[155; 212) '{ ...z.y; }': ()
1391[161; 162) 'x': A<u32, i128>
1392[161; 164) 'x.x': u32
1393[170; 171) 'x': A<u32, i128>
1394[170; 173) 'x.y': i128
1395[179; 180) 'y': A<&str, u128>
1396[179; 182) 'y.x': &str
1397[188; 189) 'y': A<&str, u128>
1398[188; 191) 'y.y': u128
1399[197; 198) 'z': A<u8, i8>
1400[197; 200) 'z.x': u8
1401[206; 207) 'z': A<u8, i8>
1402[206; 209) 'z.y': i8"###
761 ) 1403 )
762} 1404}
763 1405
764#[test] 1406#[test]
765#[should_panic] // we currently can't handle this 1407#[should_panic] // we currently can't handle this
766fn recursive_type_alias() { 1408fn recursive_type_alias() {
767 check_inference( 1409 assert_snapshot_matches!(
768 "recursive_type_alias", 1410 infer(r#"
769 r#"
770struct A<X> {}; 1411struct A<X> {};
771type Foo = Foo; 1412type Foo = Foo;
772type Bar = A<Bar>; 1413type Bar = A<Bar>;
773fn test(x: Foo) {} 1414fn test(x: Foo) {}
774"#, 1415"#),
1416 @""
775 ) 1417 )
776} 1418}
777 1419
778#[test] 1420#[test]
779fn no_panic_on_field_of_enum() { 1421fn no_panic_on_field_of_enum() {
780 check_inference( 1422 assert_snapshot_matches!(
781 "no_panic_on_field_of_enum", 1423 infer(r#"
782 r#"
783enum X {} 1424enum X {}
784 1425
785fn test(x: X) { 1426fn test(x: X) {
786 x.some_field; 1427 x.some_field;
787} 1428}
788"#, 1429"#),
1430 @r###"
1431[20; 21) 'x': X
1432[26; 47) '{ ...eld; }': ()
1433[32; 33) 'x': X
1434[32; 44) 'x.some_field': {unknown}"###
789 ); 1435 );
790} 1436}
791 1437
792#[test] 1438#[test]
793fn bug_585() { 1439fn bug_585() {
794 check_inference( 1440 assert_snapshot_matches!(
795 "bug_585", 1441 infer(r#"
796 r#"
797fn test() { 1442fn test() {
798 X {}; 1443 X {};
799 match x { 1444 match x {
@@ -801,20 +1446,35 @@ fn test() {
801 A::Y() => (), 1446 A::Y() => (),
802 } 1447 }
803} 1448}
804"#, 1449"#),
1450 @r###"
1451[11; 89) '{ ... } }': ()
1452[17; 21) 'X {}': {unknown}
1453[27; 87) 'match ... }': ()
1454[33; 34) 'x': {unknown}
1455[45; 52) 'A::B {}': {unknown}
1456[56; 58) '()': ()
1457[68; 74) 'A::Y()': {unknown}
1458[78; 80) '()': ()"###
805 ); 1459 );
806} 1460}
807 1461
808#[test] 1462#[test]
809fn bug_651() { 1463fn bug_651() {
810 check_inference( 1464 assert_snapshot_matches!(
811 "bug_651", 1465 infer(r#"
812 r#"
813fn quux() { 1466fn quux() {
814 let y = 92; 1467 let y = 92;
815 1 + y; 1468 1 + y;
816} 1469}
817"#, 1470"#),
1471 @r###"
1472[11; 41) '{ ...+ y; }': ()
1473[21; 22) 'y': i32
1474[25; 27) '92': i32
1475[33; 34) '1': i32
1476[33; 38) '1 + y': i32
1477[37; 38) 'y': i32"###
818 ); 1478 );
819} 1479}
820 1480
@@ -822,14 +1482,21 @@ fn quux() {
822fn recursive_vars() { 1482fn recursive_vars() {
823 covers!(type_var_cycles_resolve_completely); 1483 covers!(type_var_cycles_resolve_completely);
824 covers!(type_var_cycles_resolve_as_possible); 1484 covers!(type_var_cycles_resolve_as_possible);
825 check_inference( 1485 assert_snapshot_matches!(
826 "recursive_vars", 1486 infer(r#"
827 r#"
828fn test() { 1487fn test() {
829 let y = unknown; 1488 let y = unknown;
830 [y, &y]; 1489 [y, &y];
831} 1490}
832"#, 1491"#),
1492 @r###"
1493[11; 48) '{ ...&y]; }': ()
1494[21; 22) 'y': &{unknown}
1495[25; 32) 'unknown': &{unknown}
1496[38; 45) '[y, &y]': [&&{unknown}]
1497[39; 40) 'y': &{unknown}
1498[42; 44) '&y': &&{unknown}
1499[43; 44) 'y': &{unknown}"###
833 ); 1500 );
834} 1501}
835 1502
@@ -837,23 +1504,36 @@ fn test() {
837fn recursive_vars_2() { 1504fn recursive_vars_2() {
838 covers!(type_var_cycles_resolve_completely); 1505 covers!(type_var_cycles_resolve_completely);
839 covers!(type_var_cycles_resolve_as_possible); 1506 covers!(type_var_cycles_resolve_as_possible);
840 check_inference( 1507 assert_snapshot_matches!(
841 "recursive_vars_2", 1508 infer(r#"
842 r#"
843fn test() { 1509fn test() {
844 let x = unknown; 1510 let x = unknown;
845 let y = unknown; 1511 let y = unknown;
846 [(x, y), (&y, &x)]; 1512 [(x, y), (&y, &x)];
847} 1513}
848"#, 1514"#),
1515 @r###"
1516[11; 80) '{ ...x)]; }': ()
1517[21; 22) 'x': &&{unknown}
1518[25; 32) 'unknown': &&{unknown}
1519[42; 43) 'y': &&{unknown}
1520[46; 53) 'unknown': &&{unknown}
1521[59; 77) '[(x, y..., &x)]': [(&&{unknown}, &&{unknown})]
1522[60; 66) '(x, y)': (&&{unknown}, &&{unknown})
1523[61; 62) 'x': &&{unknown}
1524[64; 65) 'y': &&{unknown}
1525[68; 76) '(&y, &x)': (&&&{unknown}, &&&{unknown})
1526[69; 71) '&y': &&&{unknown}
1527[70; 71) 'y': &&{unknown}
1528[73; 75) '&x': &&&{unknown}
1529[74; 75) 'x': &&{unknown}"###
849 ); 1530 );
850} 1531}
851 1532
852#[test] 1533#[test]
853fn infer_type_param() { 1534fn infer_type_param() {
854 check_inference( 1535 assert_snapshot_matches!(
855 "infer_type_param", 1536 infer(r#"
856 r#"
857fn id<T>(x: T) -> T { 1537fn id<T>(x: T) -> T {
858 x 1538 x
859} 1539}
@@ -868,16 +1548,35 @@ fn test() {
868 let x: bool = clone(z); 1548 let x: bool = clone(z);
869 id::<i128>(1); 1549 id::<i128>(1);
870} 1550}
871"#, 1551"#),
1552 @r###"
1553[10; 11) 'x': T
1554[21; 30) '{ x }': T
1555[27; 28) 'x': T
1556[44; 45) 'x': &T
1557[56; 65) '{ x }': &T
1558[62; 63) 'x': &T
1559[77; 157) '{ ...(1); }': ()
1560[87; 88) 'y': u32
1561[91; 96) '10u32': u32
1562[102; 104) 'id': fn id<u32>(T) -> T
1563[102; 107) 'id(y)': u32
1564[105; 106) 'y': u32
1565[117; 118) 'x': bool
1566[127; 132) 'clone': fn clone<bool>(&T) -> T
1567[127; 135) 'clone(z)': bool
1568[133; 134) 'z': &bool
1569[141; 151) 'id::<i128>': fn id<i128>(T) -> T
1570[141; 154) 'id::<i128>(1)': i128
1571[152; 153) '1': i128"###
872 ); 1572 );
873} 1573}
874 1574
875#[test] 1575#[test]
876fn infer_std_crash_1() { 1576fn infer_std_crash_1() {
877 // caused stack overflow, taken from std 1577 // caused stack overflow, taken from std
878 check_inference( 1578 assert_snapshot_matches!(
879 "infer_std_crash_1", 1579 infer(r#"
880 r#"
881enum Maybe<T> { 1580enum Maybe<T> {
882 Real(T), 1581 Real(T),
883 Fake, 1582 Fake,
@@ -888,7 +1587,14 @@ fn write() {
888 Maybe::Real(ref mut something) => (), 1587 Maybe::Real(ref mut something) => (),
889 } 1588 }
890} 1589}
891"#, 1590"#),
1591 @r###"
1592[54; 139) '{ ... } }': ()
1593[60; 137) 'match ... }': ()
1594[66; 83) 'someth...nknown': Maybe<{unknown}>
1595[94; 124) 'Maybe:...thing)': Maybe<{unknown}>
1596[106; 123) 'ref mu...ething': &mut {unknown}
1597[128; 130) '()': ()"###
892 ); 1598 );
893} 1599}
894 1600
@@ -896,52 +1602,73 @@ fn write() {
896fn infer_std_crash_2() { 1602fn infer_std_crash_2() {
897 covers!(type_var_resolves_to_int_var); 1603 covers!(type_var_resolves_to_int_var);
898 // caused "equating two type variables, ...", taken from std 1604 // caused "equating two type variables, ...", taken from std
899 check_inference( 1605 assert_snapshot_matches!(
900 "infer_std_crash_2", 1606 infer(r#"
901 r#"
902fn test_line_buffer() { 1607fn test_line_buffer() {
903 &[0, b'\n', 1, b'\n']; 1608 &[0, b'\n', 1, b'\n'];
904} 1609}
905"#, 1610"#),
1611 @r###"
1612[23; 53) '{ ...n']; }': ()
1613[29; 50) '&[0, b...b'\n']': &[u8]
1614[30; 50) '[0, b'...b'\n']': [u8]
1615[31; 32) '0': u8
1616[34; 39) 'b'\n'': u8
1617[41; 42) '1': u8
1618[44; 49) 'b'\n'': u8"###
906 ); 1619 );
907} 1620}
908 1621
909#[test] 1622#[test]
910fn infer_std_crash_3() { 1623fn infer_std_crash_3() {
911 // taken from rustc 1624 // taken from rustc
912 check_inference( 1625 assert_snapshot_matches!(
913 "infer_std_crash_3", 1626 infer(r#"
914 r#"
915pub fn compute() { 1627pub fn compute() {
916 match _ { 1628 match _ {
917 SizeSkeleton::Pointer { non_zero: true, tail } => {} 1629 SizeSkeleton::Pointer { non_zero: true, tail } => {}
918 } 1630 }
919} 1631}
920"#, 1632"#),
1633 @r###"
1634[18; 102) '{ ... } }': ()
1635[24; 100) 'match ... }': ()
1636[42; 88) 'SizeSk...tail }': {unknown}
1637[76; 80) 'true': {unknown}
1638[82; 86) 'tail': {unknown}
1639[92; 94) '{}': ()"###
921 ); 1640 );
922} 1641}
923 1642
924#[test] 1643#[test]
925fn infer_std_crash_4() { 1644fn infer_std_crash_4() {
926 // taken from rustc 1645 // taken from rustc
927 check_inference( 1646 assert_snapshot_matches!(
928 "infer_std_crash_4", 1647 infer(r#"
929 r#"
930pub fn primitive_type() { 1648pub fn primitive_type() {
931 match *self { 1649 match *self {
932 BorrowedRef { type_: box Primitive(p), ..} => {}, 1650 BorrowedRef { type_: box Primitive(p), ..} => {},
933 } 1651 }
934} 1652}
935"#, 1653"#),
1654 @r###"
1655[25; 110) '{ ... } }': ()
1656[31; 108) 'match ... }': ()
1657[37; 42) '*self': {unknown}
1658[38; 42) 'self': {unknown}
1659[53; 95) 'Borrow...), ..}': {unknown}
1660[74; 77) 'box': {unknown}
1661[78; 87) 'Primitive': {unknown}
1662[88; 89) 'p': {unknown}
1663[99; 101) '{}': ()"###
936 ); 1664 );
937} 1665}
938 1666
939#[test] 1667#[test]
940fn infer_std_crash_5() { 1668fn infer_std_crash_5() {
941 // taken from rustc 1669 // taken from rustc
942 check_inference( 1670 assert_snapshot_matches!(
943 "infer_std_crash_5", 1671 infer(r#"
944 r#"
945fn extra_compiler_flags() { 1672fn extra_compiler_flags() {
946 for content in doesnt_matter { 1673 for content in doesnt_matter {
947 let name = if doesnt_matter { 1674 let name = if doesnt_matter {
@@ -957,16 +1684,39 @@ fn extra_compiler_flags() {
957 }; 1684 };
958 } 1685 }
959} 1686}
960"#, 1687"#),
1688 @r###"
1689[27; 323) '{ ... } }': ()
1690[33; 321) 'for co... }': ()
1691[37; 44) 'content': &{unknown}
1692[48; 61) 'doesnt_matter': {unknown}
1693[62; 321) '{ ... }': ()
1694[76; 80) 'name': &&{unknown}
1695[83; 167) 'if doe... }': &&{unknown}
1696[86; 99) 'doesnt_matter': bool
1697[100; 129) '{ ... }': &&{unknown}
1698[114; 119) 'first': &&{unknown}
1699[135; 167) '{ ... }': &&{unknown}
1700[149; 157) '&content': &&{unknown}
1701[150; 157) 'content': &{unknown}
1702[182; 189) 'content': &&{unknown}
1703[192; 314) 'if ICE... }': &&{unknown}
1704[195; 232) 'ICE_RE..._VALUE': {unknown}
1705[195; 248) 'ICE_RE...&name)': bool
1706[242; 247) '&name': &&&{unknown}
1707[243; 247) 'name': &&{unknown}
1708[249; 277) '{ ... }': &&{unknown}
1709[263; 267) 'name': &&{unknown}
1710[283; 314) '{ ... }': &{unknown}
1711[297; 304) 'content': &{unknown}"###
961 ); 1712 );
962} 1713}
963 1714
964#[test] 1715#[test]
965fn infer_nested_generics_crash() { 1716fn infer_nested_generics_crash() {
966 // another crash found typechecking rustc 1717 // another crash found typechecking rustc
967 check_inference( 1718 assert_snapshot_matches!(
968 "infer_nested_generics_crash", 1719 infer(r#"
969 r#"
970struct Canonical<V> { 1720struct Canonical<V> {
971 value: V, 1721 value: V,
972} 1722}
@@ -976,7 +1726,13 @@ struct QueryResponse<V> {
976fn test<R>(query_response: Canonical<QueryResponse<R>>) { 1726fn test<R>(query_response: Canonical<QueryResponse<R>>) {
977 &query_response.value; 1727 &query_response.value;
978} 1728}
979"#, 1729"#),
1730 @r###"
1731[92; 106) 'query_response': Canonical<QueryResponse<R>>
1732[137; 167) '{ ...lue; }': ()
1733[143; 164) '&query....value': &QueryResponse<R>
1734[144; 158) 'query_response': Canonical<QueryResponse<R>>
1735[144; 164) 'query_....value': QueryResponse<R>"###
980 ); 1736 );
981} 1737}
982 1738
@@ -1008,9 +1764,8 @@ mod foo {
1008 1764
1009#[test] 1765#[test]
1010fn infer_const() { 1766fn infer_const() {
1011 check_inference( 1767 assert_snapshot_matches!(
1012 "infer_const", 1768 infer(r#"
1013 r#"
1014struct Foo; 1769struct Foo;
1015impl Foo { const ASSOC_CONST: u32 = 0; } 1770impl Foo { const ASSOC_CONST: u32 = 0; }
1016const GLOBAL_CONST: u32 = 101; 1771const GLOBAL_CONST: u32 = 101;
@@ -1020,15 +1775,22 @@ fn test() {
1020 let z = GLOBAL_CONST; 1775 let z = GLOBAL_CONST;
1021 let id = Foo::ASSOC_CONST; 1776 let id = Foo::ASSOC_CONST;
1022} 1777}
1023"#, 1778"#),
1779 @r###"
1780[95; 213) '{ ...NST; }': ()
1781[138; 139) 'x': {unknown}
1782[142; 153) 'LOCAL_CONST': {unknown}
1783[163; 164) 'z': u32
1784[167; 179) 'GLOBAL_CONST': u32
1785[189; 191) 'id': u32
1786[194; 210) 'Foo::A..._CONST': u32"###
1024 ); 1787 );
1025} 1788}
1026 1789
1027#[test] 1790#[test]
1028fn infer_static() { 1791fn infer_static() {
1029 check_inference( 1792 assert_snapshot_matches!(
1030 "infer_static", 1793 infer(r#"
1031 r#"
1032static GLOBAL_STATIC: u32 = 101; 1794static GLOBAL_STATIC: u32 = 101;
1033static mut GLOBAL_STATIC_MUT: u32 = 101; 1795static mut GLOBAL_STATIC_MUT: u32 = 101;
1034fn test() { 1796fn test() {
@@ -1039,17 +1801,346 @@ fn test() {
1039 let z = GLOBAL_STATIC; 1801 let z = GLOBAL_STATIC;
1040 let w = GLOBAL_STATIC_MUT; 1802 let w = GLOBAL_STATIC_MUT;
1041} 1803}
1042"#, 1804"#),
1805 @r###"
1806[85; 280) '{ ...MUT; }': ()
1807[173; 174) 'x': {unknown}
1808[177; 189) 'LOCAL_STATIC': {unknown}
1809[199; 200) 'y': {unknown}
1810[203; 219) 'LOCAL_...IC_MUT': {unknown}
1811[229; 230) 'z': u32
1812[233; 246) 'GLOBAL_STATIC': u32
1813[256; 257) 'w': u32
1814[260; 277) 'GLOBAL...IC_MUT': u32"###
1815 );
1816}
1817
1818#[test]
1819fn infer_trait_method_simple() {
1820 // the trait implementation is intentionally incomplete -- it shouldn't matter
1821 assert_snapshot_matches!(
1822 infer(r#"
1823trait Trait1 {
1824 fn method(&self) -> u32;
1825}
1826struct S1;
1827impl Trait1 for S1 {}
1828trait Trait2 {
1829 fn method(&self) -> i128;
1830}
1831struct S2;
1832impl Trait2 for S2 {}
1833fn test() {
1834 S1.method(); // -> u32
1835 S2.method(); // -> i128
1836}
1837"#),
1838 @r###"
1839[31; 35) 'self': &{unknown}
1840[110; 114) 'self': &{unknown}
1841[170; 228) '{ ...i128 }': ()
1842[176; 178) 'S1': S1
1843[176; 187) 'S1.method()': {unknown}
1844[203; 205) 'S2': S2
1845[203; 214) 'S2.method()': {unknown}"###
1846 );
1847}
1848
1849#[test]
1850fn infer_trait_method_scoped() {
1851 // the trait implementation is intentionally incomplete -- it shouldn't matter
1852 assert_snapshot_matches!(
1853 infer(r#"
1854struct S;
1855mod foo {
1856 pub trait Trait1 {
1857 fn method(&self) -> u32;
1858 }
1859 impl Trait1 for super::S {}
1860}
1861mod bar {
1862 pub trait Trait2 {
1863 fn method(&self) -> i128;
1864 }
1865 impl Trait2 for super::S {}
1866}
1867
1868mod foo_test {
1869 use super::S;
1870 use super::foo::Trait1;
1871 fn test() {
1872 S.method(); // -> u32
1873 }
1874}
1875
1876mod bar_test {
1877 use super::S;
1878 use super::bar::Trait2;
1879 fn test() {
1880 S.method(); // -> i128
1881 }
1882}
1883"#),
1884 @r###"
1885[63; 67) 'self': &{unknown}
1886[169; 173) 'self': &{unknown}
1887[300; 337) '{ ... }': ()
1888[310; 311) 'S': S
1889[310; 320) 'S.method()': {unknown}
1890[416; 454) '{ ... }': ()
1891[426; 427) 'S': S
1892[426; 436) 'S.method()': {unknown}"###
1893 );
1894}
1895
1896#[test]
1897fn infer_trait_method_generic_1() {
1898 // the trait implementation is intentionally incomplete -- it shouldn't matter
1899 assert_snapshot_matches!(
1900 infer(r#"
1901trait Trait<T> {
1902 fn method(&self) -> T;
1903}
1904struct S;
1905impl Trait<u32> for S {}
1906fn test() {
1907 S.method();
1908}
1909"#),
1910 @r###"
1911[33; 37) 'self': &{unknown}
1912[92; 111) '{ ...d(); }': ()
1913[98; 99) 'S': S
1914[98; 108) 'S.method()': {unknown}"###
1915 );
1916}
1917
1918#[test]
1919fn infer_trait_method_generic_2() {
1920 // the trait implementation is intentionally incomplete -- it shouldn't matter
1921 assert_snapshot_matches!(
1922 infer(r#"
1923trait Trait<T> {
1924 fn method(&self) -> T;
1925}
1926struct S<T>(T);
1927impl<U> Trait<U> for S<U> {}
1928fn test() {
1929 S(1u32).method();
1930}
1931"#),
1932 @r###"
1933[33; 37) 'self': &{unknown}
1934[102; 127) '{ ...d(); }': ()
1935[108; 109) 'S': S<u32>(T) -> S<T>
1936[108; 115) 'S(1u32)': S<u32>
1937[108; 124) 'S(1u32...thod()': {unknown}
1938[110; 114) '1u32': u32"###
1939 );
1940}
1941
1942#[test]
1943fn infer_trait_assoc_method() {
1944 assert_snapshot_matches!(
1945 infer(r#"
1946trait Default {
1947 fn default() -> Self;
1948}
1949struct S;
1950impl Default for S {}
1951fn test() {
1952 let s1: S = Default::default();
1953 let s2 = S::default();
1954 let s3 = <S as Default>::default();
1955}
1956"#),
1957 @r###"
1958[87; 193) '{ ...t(); }': ()
1959[97; 99) 's1': S
1960[105; 121) 'Defaul...efault': {unknown}
1961[105; 123) 'Defaul...ault()': S
1962[133; 135) 's2': {unknown}
1963[138; 148) 'S::default': {unknown}
1964[138; 150) 'S::default()': {unknown}
1965[160; 162) 's3': {unknown}
1966[165; 188) '<S as ...efault': {unknown}
1967[165; 190) '<S as ...ault()': {unknown}"###
1968 );
1969}
1970
1971#[test]
1972fn infer_from_bound_1() {
1973 assert_snapshot_matches!(
1974 infer(r#"
1975trait Trait<T> {}
1976struct S<T>(T);
1977impl<U> Trait<U> for S<U> {}
1978fn foo<T: Trait<u32>>(t: T) {}
1979fn test() {
1980 let s = S(unknown);
1981 foo(s);
1982}
1983"#),
1984 @r###"
1985[86; 87) 't': T
1986[92; 94) '{}': ()
1987[105; 144) '{ ...(s); }': ()
1988[115; 116) 's': S<{unknown}>
1989[119; 120) 'S': S<{unknown}>(T) -> S<T>
1990[119; 129) 'S(unknown)': S<{unknown}>
1991[121; 128) 'unknown': {unknown}
1992[135; 138) 'foo': fn foo<S<{unknown}>>(T) -> ()
1993[135; 141) 'foo(s)': ()
1994[139; 140) 's': S<{unknown}>"###
1995 );
1996}
1997
1998#[test]
1999fn infer_from_bound_2() {
2000 assert_snapshot_matches!(
2001 infer(r#"
2002trait Trait<T> {}
2003struct S<T>(T);
2004impl<U> Trait<U> for S<U> {}
2005fn foo<U, T: Trait<U>>(t: T) -> U {}
2006fn test() {
2007 let s = S(unknown);
2008 let x: u32 = foo(s);
2009}
2010"#),
2011 @r###"
2012[87; 88) 't': T
2013[98; 100) '{}': ()
2014[111; 163) '{ ...(s); }': ()
2015[121; 122) 's': S<{unknown}>
2016[125; 126) 'S': S<{unknown}>(T) -> S<T>
2017[125; 135) 'S(unknown)': S<{unknown}>
2018[127; 134) 'unknown': {unknown}
2019[145; 146) 'x': u32
2020[154; 157) 'foo': fn foo<u32, S<{unknown}>>(T) -> U
2021[154; 160) 'foo(s)': u32
2022[158; 159) 's': S<{unknown}>"###
2023 );
2024}
2025
2026#[test]
2027fn infer_call_trait_method_on_generic_param_1() {
2028 assert_snapshot_matches!(
2029 infer(r#"
2030trait Trait {
2031 fn method() -> u32;
2032}
2033fn test<T: Trait>(t: T) {
2034 t.method();
2035}
2036"#),
2037 @r###"
2038[59; 60) 't': T
2039[65; 84) '{ ...d(); }': ()
2040[71; 72) 't': T
2041[71; 81) 't.method()': {unknown}"###
2042 );
2043}
2044
2045#[test]
2046fn infer_call_trait_method_on_generic_param_2() {
2047 assert_snapshot_matches!(
2048 infer(r#"
2049trait Trait<T> {
2050 fn method() -> T;
2051}
2052fn test<U, T: Trait<U>>(t: T) {
2053 t.method();
2054}
2055"#),
2056 @r###"
2057[66; 67) 't': T
2058[72; 91) '{ ...d(); }': ()
2059[78; 79) 't': T
2060[78; 88) 't.method()': {unknown}"###
2061 );
2062}
2063
2064#[test]
2065fn infer_with_multiple_trait_impls() {
2066 assert_snapshot_matches!(
2067 infer(r#"
2068trait Into<T> {
2069 fn into(self) -> T;
2070}
2071struct S;
2072impl Into<u32> for S;
2073impl Into<u64> for S;
2074fn test() {
2075 let x: u32 = S.into();
2076 let y: u64 = S.into();
2077 let z = Into::<u64>::into(S);
2078}
2079"#),
2080 @r###"
2081[29; 33) 'self': {unknown}
2082[107; 198) '{ ...(S); }': ()
2083[117; 118) 'x': u32
2084[126; 127) 'S': S
2085[126; 134) 'S.into()': u32
2086[144; 145) 'y': u64
2087[153; 154) 'S': S
2088[153; 161) 'S.into()': u64
2089[171; 172) 'z': {unknown}
2090[175; 192) 'Into::...::into': {unknown}
2091[175; 195) 'Into::...nto(S)': {unknown}
2092[193; 194) 'S': S"###
2093 );
2094}
2095
2096#[test]
2097fn infer_project_associated_type() {
2098 assert_snapshot_matches!(
2099 infer(r#"
2100trait Iterable {
2101 type Item;
2102}
2103struct S;
2104impl Iterable for S { type Item = u32; }
2105fn test<T: Iterable>() {
2106 let x: <S as Iterable>::Item = 1;
2107 let y: T::Item = no_matter;
2108}
2109"#),
2110 @r###"
2111[108; 181) '{ ...ter; }': ()
2112[118; 119) 'x': i32
2113[145; 146) '1': i32
2114[156; 157) 'y': {unknown}
2115[169; 178) 'no_matter': {unknown}"###
2116 );
2117}
2118
2119#[test]
2120fn infer_associated_type_bound() {
2121 assert_snapshot_matches!(
2122 infer(r#"
2123trait Iterable {
2124 type Item;
2125}
2126fn test<T: Iterable<Item=u32>>() {
2127 let y: T::Item = unknown;
2128}
2129"#),
2130 @r###"
2131[67; 100) '{ ...own; }': ()
2132[77; 78) 'y': {unknown}
2133[90; 97) 'unknown': {unknown}"###
1043 ); 2134 );
1044} 2135}
1045 2136
1046fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { 2137fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String {
1047 let func = source_binder::function_from_position(db, pos).unwrap(); 2138 let func = source_binder::function_from_position(db, pos).unwrap();
1048 let body_syntax_mapping = func.body_syntax_mapping(db); 2139 let body_source_map = func.body_source_map(db);
1049 let inference_result = func.infer(db); 2140 let inference_result = func.infer(db);
1050 let (_, syntax) = func.source(db); 2141 let (_, syntax) = func.source(db);
1051 let node = algo::find_node_at_offset::<ast::Expr>(syntax.syntax(), pos.offset).unwrap(); 2142 let node = algo::find_node_at_offset::<ast::Expr>(syntax.syntax(), pos.offset).unwrap();
1052 let expr = body_syntax_mapping.node_expr(node).unwrap(); 2143 let expr = body_source_map.node_expr(node).unwrap();
1053 let ty = &inference_result[expr]; 2144 let ty = &inference_result[expr];
1054 ty.to_string() 2145 ty.to_string()
1055} 2146}
@@ -1058,20 +2149,21 @@ fn infer(content: &str) -> String {
1058 let (db, _, file_id) = MockDatabase::with_single_file(content); 2149 let (db, _, file_id) = MockDatabase::with_single_file(content);
1059 let source_file = db.parse(file_id); 2150 let source_file = db.parse(file_id);
1060 let mut acc = String::new(); 2151 let mut acc = String::new();
2152 acc.push_str("\n");
1061 for fn_def in source_file.syntax().descendants().filter_map(ast::FnDef::cast) { 2153 for fn_def in source_file.syntax().descendants().filter_map(ast::FnDef::cast) {
1062 let func = source_binder::function_from_source(&db, file_id, fn_def).unwrap(); 2154 let func = source_binder::function_from_source(&db, file_id, fn_def).unwrap();
1063 let inference_result = func.infer(&db); 2155 let inference_result = func.infer(&db);
1064 let body_syntax_mapping = func.body_syntax_mapping(&db); 2156 let body_source_map = func.body_source_map(&db);
1065 let mut types = Vec::new(); 2157 let mut types = Vec::new();
1066 for (pat, ty) in inference_result.type_of_pat.iter() { 2158 for (pat, ty) in inference_result.type_of_pat.iter() {
1067 let syntax_ptr = match body_syntax_mapping.pat_syntax(pat) { 2159 let syntax_ptr = match body_source_map.pat_syntax(pat) {
1068 Some(sp) => sp, 2160 Some(sp) => sp,
1069 None => continue, 2161 None => continue,
1070 }; 2162 };
1071 types.push((syntax_ptr, ty)); 2163 types.push((syntax_ptr, ty));
1072 } 2164 }
1073 for (expr, ty) in inference_result.type_of_expr.iter() { 2165 for (expr, ty) in inference_result.type_of_expr.iter() {
1074 let syntax_ptr = match body_syntax_mapping.expr_syntax(expr) { 2166 let syntax_ptr = match body_source_map.expr_syntax(expr) {
1075 Some(sp) => sp, 2167 Some(sp) => sp,
1076 None => continue, 2168 None => continue,
1077 }; 2169 };
@@ -1091,15 +2183,10 @@ fn infer(content: &str) -> String {
1091 .unwrap(); 2183 .unwrap();
1092 } 2184 }
1093 } 2185 }
2186 acc.truncate(acc.trim_end().len());
1094 acc 2187 acc
1095} 2188}
1096 2189
1097fn check_inference(name: &str, content: &str) {
1098 let result = infer(content);
1099
1100 insta::assert_snapshot_matches!(&name, &result);
1101}
1102
1103fn ellipsize(mut text: String, max_len: usize) -> String { 2190fn ellipsize(mut text: String, max_len: usize) -> String {
1104 if text.len() <= max_len { 2191 if text.len() <= max_len {
1105 return text; 2192 return text;
diff --git a/crates/ra_ide_api/src/change.rs b/crates/ra_ide_api/src/change.rs
index 3f041f9c3..0c90ed5b5 100644
--- a/crates/ra_ide_api/src/change.rs
+++ b/crates/ra_ide_api/src/change.rs
@@ -223,8 +223,7 @@ impl RootDatabase {
223 self.query(hir::db::FileItemsQuery).sweep(sweep); 223 self.query(hir::db::FileItemsQuery).sweep(sweep);
224 self.query(hir::db::FileItemQuery).sweep(sweep); 224 self.query(hir::db::FileItemQuery).sweep(sweep);
225 225
226 self.query(hir::db::LowerModuleQuery).sweep(sweep); 226 self.query(hir::db::LowerModuleWithSourceMapQuery).sweep(sweep);
227 self.query(hir::db::LowerModuleSourceMapQuery).sweep(sweep); 227 self.query(hir::db::BodyWithSourceMapQuery).sweep(sweep);
228 self.query(hir::db::BodySyntaxMappingQuery).sweep(sweep);
229 } 228 }
230} 229}
diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs
index d5ad2e79f..94c66be31 100644
--- a/crates/ra_ide_api/src/completion/complete_dot.rs
+++ b/crates/ra_ide_api/src/completion/complete_dot.rs
@@ -9,8 +9,8 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
9 _ => return, 9 _ => return,
10 }; 10 };
11 let infer_result = function.infer(ctx.db); 11 let infer_result = function.infer(ctx.db);
12 let syntax_mapping = function.body_syntax_mapping(ctx.db); 12 let source_map = function.body_source_map(ctx.db);
13 let expr = match syntax_mapping.node_expr(receiver) { 13 let expr = match source_map.node_expr(receiver) {
14 Some(expr) => expr, 14 Some(expr) => expr,
15 None => return, 15 None => return,
16 }; 16 };
diff --git a/crates/ra_ide_api/src/completion/complete_struct_literal.rs b/crates/ra_ide_api/src/completion/complete_struct_literal.rs
index afb092f59..6bef9624e 100644
--- a/crates/ra_ide_api/src/completion/complete_struct_literal.rs
+++ b/crates/ra_ide_api/src/completion/complete_struct_literal.rs
@@ -9,8 +9,8 @@ pub(super) fn complete_struct_literal(acc: &mut Completions, ctx: &CompletionCon
9 _ => return, 9 _ => return,
10 }; 10 };
11 let infer_result = function.infer(ctx.db); 11 let infer_result = function.infer(ctx.db);
12 let syntax_mapping = function.body_syntax_mapping(ctx.db); 12 let source_map = function.body_source_map(ctx.db);
13 let expr = match syntax_mapping.node_expr(struct_lit.into()) { 13 let expr = match source_map.node_expr(struct_lit.into()) {
14 Some(expr) => expr, 14 Some(expr) => expr,
15 None => return, 15 None => return,
16 }; 16 };
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs
index 6fa430754..9ec179593 100644
--- a/crates/ra_ide_api/src/goto_definition.rs
+++ b/crates/ra_ide_api/src/goto_definition.rs
@@ -54,10 +54,10 @@ pub(crate) fn reference_definition(
54 if let Some(method_call) = name_ref.syntax().parent().and_then(ast::MethodCallExpr::cast) { 54 if let Some(method_call) = name_ref.syntax().parent().and_then(ast::MethodCallExpr::cast) {
55 tested_by!(goto_definition_works_for_methods); 55 tested_by!(goto_definition_works_for_methods);
56 let infer_result = function.infer(db); 56 let infer_result = function.infer(db);
57 let syntax_mapping = function.body_syntax_mapping(db); 57 let source_map = function.body_source_map(db);
58 let expr = ast::Expr::cast(method_call.syntax()).unwrap(); 58 let expr = ast::Expr::cast(method_call.syntax()).unwrap();
59 if let Some(func) = 59 if let Some(func) =
60 syntax_mapping.node_expr(expr).and_then(|it| infer_result.method_resolution(it)) 60 source_map.node_expr(expr).and_then(|it| infer_result.method_resolution(it))
61 { 61 {
62 return Exact(NavigationTarget::from_function(db, func)); 62 return Exact(NavigationTarget::from_function(db, func));
63 }; 63 };
@@ -66,10 +66,10 @@ pub(crate) fn reference_definition(
66 if let Some(field_expr) = name_ref.syntax().parent().and_then(ast::FieldExpr::cast) { 66 if let Some(field_expr) = name_ref.syntax().parent().and_then(ast::FieldExpr::cast) {
67 tested_by!(goto_definition_works_for_fields); 67 tested_by!(goto_definition_works_for_fields);
68 let infer_result = function.infer(db); 68 let infer_result = function.infer(db);
69 let syntax_mapping = function.body_syntax_mapping(db); 69 let source_map = function.body_source_map(db);
70 let expr = ast::Expr::cast(field_expr.syntax()).unwrap(); 70 let expr = ast::Expr::cast(field_expr.syntax()).unwrap();
71 if let Some(field) = 71 if let Some(field) =
72 syntax_mapping.node_expr(expr).and_then(|it| infer_result.field_resolution(it)) 72 source_map.node_expr(expr).and_then(|it| infer_result.field_resolution(it))
73 { 73 {
74 return Exact(NavigationTarget::from_field(db, field)); 74 return Exact(NavigationTarget::from_field(db, field));
75 }; 75 };
@@ -80,11 +80,11 @@ pub(crate) fn reference_definition(
80 tested_by!(goto_definition_works_for_named_fields); 80 tested_by!(goto_definition_works_for_named_fields);
81 81
82 let infer_result = function.infer(db); 82 let infer_result = function.infer(db);
83 let syntax_mapping = function.body_syntax_mapping(db); 83 let source_map = function.body_source_map(db);
84 84
85 let struct_lit = field_expr.syntax().ancestors().find_map(ast::StructLit::cast); 85 let struct_lit = field_expr.syntax().ancestors().find_map(ast::StructLit::cast);
86 86
87 if let Some(expr) = struct_lit.and_then(|lit| syntax_mapping.node_expr(lit.into())) { 87 if let Some(expr) = struct_lit.and_then(|lit| source_map.node_expr(lit.into())) {
88 let ty = infer_result[expr].clone(); 88 let ty = infer_result[expr].clone();
89 if let hir::Ty::Adt { def_id, .. } = ty { 89 if let hir::Ty::Adt { def_id, .. } = ty {
90 if let hir::AdtDef::Struct(s) = def_id { 90 if let hir::AdtDef::Struct(s) = def_id {
@@ -109,9 +109,8 @@ pub(crate) fn reference_definition(
109 Some(Resolution::Def(def)) => return Exact(NavigationTarget::from_def(db, def)), 109 Some(Resolution::Def(def)) => return Exact(NavigationTarget::from_def(db, def)),
110 Some(Resolution::LocalBinding(pat)) => { 110 Some(Resolution::LocalBinding(pat)) => {
111 let body = resolver.body().expect("no body for local binding"); 111 let body = resolver.body().expect("no body for local binding");
112 let syntax_mapping = body.syntax_mapping(db); 112 let source_map = body.owner().body_source_map(db);
113 let ptr = 113 let ptr = source_map.pat_syntax(pat).expect("pattern not found in syntax mapping");
114 syntax_mapping.pat_syntax(pat).expect("pattern not found in syntax mapping");
115 let name = 114 let name =
116 path.as_ident().cloned().expect("local binding from a multi-segment path"); 115 path.as_ident().cloned().expect("local binding from a multi-segment path");
117 let nav = NavigationTarget::from_scope_entry(file_id, name, ptr); 116 let nav = NavigationTarget::from_scope_entry(file_id, name, ptr);
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs
index 1a1853df3..8ec60090d 100644
--- a/crates/ra_ide_api/src/hover.rs
+++ b/crates/ra_ide_api/src/hover.rs
@@ -107,7 +107,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
107 leaf.ancestors().find(|n| ast::Expr::cast(*n).is_some() || ast::Pat::cast(*n).is_some()) 107 leaf.ancestors().find(|n| ast::Expr::cast(*n).is_some() || ast::Pat::cast(*n).is_some())
108 })?; 108 })?;
109 let frange = FileRange { file_id: position.file_id, range: node.range() }; 109 let frange = FileRange { file_id: position.file_id, range: node.range() };
110 res.extend(type_of(db, frange).map(Into::into)); 110 res.extend(type_of(db, frange).map(rust_code_markup));
111 range = Some(node.range()); 111 range = Some(node.range());
112 } 112 }
113 113
@@ -132,22 +132,37 @@ pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Option<String> {
132 let parent_fn = node.ancestors().find_map(ast::FnDef::cast)?; 132 let parent_fn = node.ancestors().find_map(ast::FnDef::cast)?;
133 let function = hir::source_binder::function_from_source(db, frange.file_id, parent_fn)?; 133 let function = hir::source_binder::function_from_source(db, frange.file_id, parent_fn)?;
134 let infer = function.infer(db); 134 let infer = function.infer(db);
135 let syntax_mapping = function.body_syntax_mapping(db); 135 let source_map = function.body_source_map(db);
136 if let Some(expr) = ast::Expr::cast(node).and_then(|e| syntax_mapping.node_expr(e)) { 136 if let Some(expr) = ast::Expr::cast(node).and_then(|e| source_map.node_expr(e)) {
137 Some(infer[expr].to_string()) 137 Some(infer[expr].to_string())
138 } else if let Some(pat) = ast::Pat::cast(node).and_then(|p| syntax_mapping.node_pat(p)) { 138 } else if let Some(pat) = ast::Pat::cast(node).and_then(|p| source_map.node_pat(p)) {
139 Some(infer[pat].to_string()) 139 Some(infer[pat].to_string())
140 } else { 140 } else {
141 None 141 None
142 } 142 }
143} 143}
144 144
145fn rust_code_markup<CODE: AsRef<str>>(val: CODE) -> String {
146 rust_code_markup_with_doc::<_, &str>(val, None)
147}
148
149fn rust_code_markup_with_doc<CODE, DOC>(val: CODE, doc: Option<DOC>) -> String
150where
151 CODE: AsRef<str>,
152 DOC: AsRef<str>,
153{
154 if let Some(doc) = doc {
155 format!("```rust\n{}\n```\n\n{}", val.as_ref(), doc.as_ref())
156 } else {
157 format!("```rust\n{}\n```", val.as_ref())
158 }
159}
160
145// FIXME: this should not really use navigation target. Rather, approximately 161// FIXME: this should not really use navigation target. Rather, approximately
146// resolved symbol should return a `DefId`. 162// resolved symbol should return a `DefId`.
147fn doc_text_for(db: &RootDatabase, nav: NavigationTarget) -> Option<String> { 163fn doc_text_for(db: &RootDatabase, nav: NavigationTarget) -> Option<String> {
148 match (nav.description(db), nav.docs(db)) { 164 match (nav.description(db), nav.docs(db)) {
149 (Some(desc), Some(docs)) => Some("```rust\n".to_string() + &*desc + "\n```\n\n" + &*docs), 165 (Some(desc), docs) => Some(rust_code_markup_with_doc(desc, docs)),
150 (Some(desc), None) => Some("```rust\n".to_string() + &*desc + "\n```"),
151 (None, Some(docs)) => Some(docs), 166 (None, Some(docs)) => Some(docs),
152 _ => None, 167 _ => None,
153 } 168 }
@@ -238,6 +253,10 @@ mod tests {
238 s.trim_start_matches("```rust\n").trim_end_matches("\n```") 253 s.trim_start_matches("```rust\n").trim_end_matches("\n```")
239 } 254 }
240 255
256 fn trim_markup_opt(s: Option<&str>) -> Option<&str> {
257 s.map(trim_markup)
258 }
259
241 fn check_hover_result(fixture: &str, expected: &[&str]) { 260 fn check_hover_result(fixture: &str, expected: &[&str]) {
242 let (analysis, position) = analysis_and_position(fixture); 261 let (analysis, position) = analysis_and_position(fixture);
243 let hover = analysis.hover(position).unwrap().unwrap(); 262 let hover = analysis.hover(position).unwrap().unwrap();
@@ -264,7 +283,7 @@ mod tests {
264 ); 283 );
265 let hover = analysis.hover(position).unwrap().unwrap(); 284 let hover = analysis.hover(position).unwrap().unwrap();
266 assert_eq!(hover.range, TextRange::from_to(95.into(), 100.into())); 285 assert_eq!(hover.range, TextRange::from_to(95.into(), 100.into()));
267 assert_eq!(hover.info.first(), Some("u32")); 286 assert_eq!(trim_markup_opt(hover.info.first()), Some("u32"));
268 } 287 }
269 288
270 #[test] 289 #[test]
@@ -410,21 +429,21 @@ mod tests {
410 ); 429 );
411 let hover = analysis.hover(position).unwrap().unwrap(); 430 let hover = analysis.hover(position).unwrap().unwrap();
412 // not the nicest way to show it currently 431 // not the nicest way to show it currently
413 assert_eq!(hover.info.first(), Some("Some<i32>(T) -> Option<T>")); 432 assert_eq!(trim_markup_opt(hover.info.first()), Some("Some<i32>(T) -> Option<T>"));
414 } 433 }
415 434
416 #[test] 435 #[test]
417 fn hover_for_local_variable() { 436 fn hover_for_local_variable() {
418 let (analysis, position) = single_file_with_position("fn func(foo: i32) { fo<|>o; }"); 437 let (analysis, position) = single_file_with_position("fn func(foo: i32) { fo<|>o; }");
419 let hover = analysis.hover(position).unwrap().unwrap(); 438 let hover = analysis.hover(position).unwrap().unwrap();
420 assert_eq!(hover.info.first(), Some("i32")); 439 assert_eq!(trim_markup_opt(hover.info.first()), Some("i32"));
421 } 440 }
422 441
423 #[test] 442 #[test]
424 fn hover_for_local_variable_pat() { 443 fn hover_for_local_variable_pat() {
425 let (analysis, position) = single_file_with_position("fn func(fo<|>o: i32) {}"); 444 let (analysis, position) = single_file_with_position("fn func(fo<|>o: i32) {}");
426 let hover = analysis.hover(position).unwrap().unwrap(); 445 let hover = analysis.hover(position).unwrap().unwrap();
427 assert_eq!(hover.info.first(), Some("i32")); 446 assert_eq!(trim_markup_opt(hover.info.first()), Some("i32"));
428 } 447 }
429 448
430 #[test] 449 #[test]
@@ -455,7 +474,7 @@ mod tests {
455 ); 474 );
456 475
457 let type_name = analysis.type_of(range).unwrap().unwrap(); 476 let type_name = analysis.type_of(range).unwrap().unwrap();
458 assert_eq!("[unknown]", &type_name); 477 assert_eq!("{unknown}", &type_name);
459 } 478 }
460 479
461 #[test] 480 #[test]
@@ -491,6 +510,6 @@ mod tests {
491 ", 510 ",
492 ); 511 );
493 let hover = analysis.hover(position).unwrap().unwrap(); 512 let hover = analysis.hover(position).unwrap().unwrap();
494 assert_eq!(hover.info.first(), Some("Thing")); 513 assert_eq!(trim_markup_opt(hover.info.first()), Some("Thing"));
495 } 514 }
496} 515}
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs
index 6546d0644..b8a4adbce 100644
--- a/crates/ra_ide_api/src/lib.rs
+++ b/crates/ra_ide_api/src/lib.rs
@@ -32,13 +32,14 @@ mod references;
32mod impls; 32mod impls;
33mod assists; 33mod assists;
34mod diagnostics; 34mod diagnostics;
35mod syntax_tree;
35 36
36#[cfg(test)] 37#[cfg(test)]
37mod marks; 38mod marks;
38 39
39use std::sync::Arc; 40use std::sync::Arc;
40 41
41use ra_syntax::{SourceFile, TreeArc, TextRange, TextUnit, AstNode}; 42use ra_syntax::{SourceFile, TreeArc, TextRange, TextUnit};
42use ra_text_edit::TextEdit; 43use ra_text_edit::TextEdit;
43use ra_db::{ 44use ra_db::{
44 SourceDatabase, CheckCanceled, 45 SourceDatabase, CheckCanceled,
@@ -245,8 +246,8 @@ impl Analysis {
245 246
246 /// Returns a syntax tree represented as `String`, for debug purposes. 247 /// Returns a syntax tree represented as `String`, for debug purposes.
247 // FIXME: use a better name here. 248 // FIXME: use a better name here.
248 pub fn syntax_tree(&self, file_id: FileId) -> String { 249 pub fn syntax_tree(&self, file_id: FileId, text_range: Option<TextRange>) -> String {
249 self.db.parse(file_id).syntax().debug_dump() 250 syntax_tree::syntax_tree(&self.db, file_id, text_range)
250 } 251 }
251 252
252 /// Returns an edit to remove all newlines in the range, cleaning up minor 253 /// Returns an edit to remove all newlines in the range, cleaning up minor
diff --git a/crates/ra_ide_api/src/syntax_tree.rs b/crates/ra_ide_api/src/syntax_tree.rs
new file mode 100644
index 000000000..bbe9222b4
--- /dev/null
+++ b/crates/ra_ide_api/src/syntax_tree.rs
@@ -0,0 +1,87 @@
1use ra_db::SourceDatabase;
2use crate::db::RootDatabase;
3use ra_syntax::{
4 SourceFile, SyntaxNode, TextRange, AstNode,
5 algo::{self, visit::{visitor, Visitor}}, ast::{self, AstToken}
6};
7
8pub use ra_db::FileId;
9
10pub(crate) fn syntax_tree(
11 db: &RootDatabase,
12 file_id: FileId,
13 text_range: Option<TextRange>,
14) -> String {
15 if let Some(text_range) = text_range {
16 let file = db.parse(file_id);
17 let node = algo::find_covering_node(file.syntax(), text_range);
18
19 if let Some(tree) = syntax_tree_for_string(node, text_range) {
20 return tree;
21 }
22
23 node.debug_dump()
24 } else {
25 db.parse(file_id).syntax().debug_dump()
26 }
27}
28
29/// Attempts parsing the selected contents of a string literal
30/// as rust syntax and returns its syntax tree
31fn syntax_tree_for_string(node: &SyntaxNode, text_range: TextRange) -> Option<String> {
32 // When the range is inside a string
33 // we'll attempt parsing it as rust syntax
34 // to provide the syntax tree of the contents of the string
35 visitor()
36 .visit(|node: &ast::String| syntax_tree_for_token(node, text_range))
37 .visit(|node: &ast::RawString| syntax_tree_for_token(node, text_range))
38 .accept(node)?
39}
40
41fn syntax_tree_for_token<T: AstToken>(node: &T, text_range: TextRange) -> Option<String> {
42 // Range of the full node
43 let node_range = node.syntax().range();
44 let text = node.text().to_string();
45
46 // We start at some point inside the node
47 // Either we have selected the whole string
48 // or our selection is inside it
49 let start = text_range.start() - node_range.start();
50
51 // how many characters we have selected
52 let len = text_range.len().to_usize();
53
54 let node_len = node_range.len().to_usize();
55
56 let start = start.to_usize();
57
58 // We want to cap our length
59 let len = len.min(node_len);
60
61 // Ensure our slice is inside the actual string
62 let end = if start + len < text.len() { start + len } else { text.len() - start };
63
64 let text = &text[start..end];
65
66 // Remove possible extra string quotes from the start
67 // and the end of the string
68 let text = text
69 .trim_start_matches('r')
70 .trim_start_matches('#')
71 .trim_start_matches('"')
72 .trim_end_matches('#')
73 .trim_end_matches('"')
74 .trim()
75 // Remove custom markers
76 .replace("<|>", "");
77
78 let parsed = SourceFile::parse(&text);
79
80 // If the "file" parsed without errors,
81 // return its syntax
82 if parsed.errors().is_empty() {
83 return Some(parsed.syntax().debug_dump());
84 }
85
86 None
87}
diff --git a/crates/ra_ide_api/tests/test/main.rs b/crates/ra_ide_api/tests/test/main.rs
index ff1a0e46b..0f0766f62 100644
--- a/crates/ra_ide_api/tests/test/main.rs
+++ b/crates/ra_ide_api/tests/test/main.rs
@@ -1,6 +1,6 @@
1use insta::assert_debug_snapshot_matches; 1use insta::assert_debug_snapshot_matches;
2use ra_ide_api::{ 2use ra_ide_api::{
3 mock_analysis::{single_file, single_file_with_position, MockAnalysis}, 3 mock_analysis::{single_file, single_file_with_position, single_file_with_range, MockAnalysis},
4 AnalysisChange, CrateGraph, Edition::Edition2018, Query, NavigationTarget, 4 AnalysisChange, CrateGraph, Edition::Edition2018, Query, NavigationTarget,
5 ReferenceSearchResult, 5 ReferenceSearchResult,
6}; 6};
@@ -138,3 +138,255 @@ mod foo {
138 assert_eq!(s.name(), "FooInner"); 138 assert_eq!(s.name(), "FooInner");
139 assert_eq!(s.container_name(), Some(&SmolStr::new("foo"))); 139 assert_eq!(s.container_name(), Some(&SmolStr::new("foo")));
140} 140}
141
142#[test]
143fn test_syntax_tree_without_range() {
144 // Basic syntax
145 let (analysis, file_id) = single_file(r#"fn foo() {}"#);
146 let syn = analysis.syntax_tree(file_id, None);
147
148 assert_eq!(
149 syn.trim(),
150 r#"
151SOURCE_FILE@[0; 11)
152 FN_DEF@[0; 11)
153 FN_KW@[0; 2)
154 WHITESPACE@[2; 3)
155 NAME@[3; 6)
156 IDENT@[3; 6) "foo"
157 PARAM_LIST@[6; 8)
158 L_PAREN@[6; 7)
159 R_PAREN@[7; 8)
160 WHITESPACE@[8; 9)
161 BLOCK@[9; 11)
162 L_CURLY@[9; 10)
163 R_CURLY@[10; 11)
164 "#
165 .trim()
166 );
167
168 let (analysis, file_id) = single_file(
169 r#"
170fn test() {
171 assert!("
172 fn foo() {
173 }
174 ", "");
175}"#
176 .trim(),
177 );
178 let syn = analysis.syntax_tree(file_id, None);
179
180 assert_eq!(
181 syn.trim(),
182 r#"
183SOURCE_FILE@[0; 60)
184 FN_DEF@[0; 60)
185 FN_KW@[0; 2)
186 WHITESPACE@[2; 3)
187 NAME@[3; 7)
188 IDENT@[3; 7) "test"
189 PARAM_LIST@[7; 9)
190 L_PAREN@[7; 8)
191 R_PAREN@[8; 9)
192 WHITESPACE@[9; 10)
193 BLOCK@[10; 60)
194 L_CURLY@[10; 11)
195 WHITESPACE@[11; 16)
196 EXPR_STMT@[16; 58)
197 MACRO_CALL@[16; 57)
198 PATH@[16; 22)
199 PATH_SEGMENT@[16; 22)
200 NAME_REF@[16; 22)
201 IDENT@[16; 22) "assert"
202 EXCL@[22; 23)
203 TOKEN_TREE@[23; 57)
204 L_PAREN@[23; 24)
205 STRING@[24; 52)
206 COMMA@[52; 53)
207 WHITESPACE@[53; 54)
208 STRING@[54; 56)
209 R_PAREN@[56; 57)
210 SEMI@[57; 58)
211 WHITESPACE@[58; 59)
212 R_CURLY@[59; 60)
213 "#
214 .trim()
215 );
216}
217
218#[test]
219fn test_syntax_tree_with_range() {
220 let (analysis, range) = single_file_with_range(r#"<|>fn foo() {}<|>"#.trim());
221 let syn = analysis.syntax_tree(range.file_id, Some(range.range));
222
223 assert_eq!(
224 syn.trim(),
225 r#"
226FN_DEF@[0; 11)
227 FN_KW@[0; 2)
228 WHITESPACE@[2; 3)
229 NAME@[3; 6)
230 IDENT@[3; 6) "foo"
231 PARAM_LIST@[6; 8)
232 L_PAREN@[6; 7)
233 R_PAREN@[7; 8)
234 WHITESPACE@[8; 9)
235 BLOCK@[9; 11)
236 L_CURLY@[9; 10)
237 R_CURLY@[10; 11)
238 "#
239 .trim()
240 );
241
242 let (analysis, range) = single_file_with_range(
243 r#"fn test() {
244 <|>assert!("
245 fn foo() {
246 }
247 ", "");<|>
248}"#
249 .trim(),
250 );
251 let syn = analysis.syntax_tree(range.file_id, Some(range.range));
252
253 assert_eq!(
254 syn.trim(),
255 r#"
256EXPR_STMT@[16; 58)
257 MACRO_CALL@[16; 57)
258 PATH@[16; 22)
259 PATH_SEGMENT@[16; 22)
260 NAME_REF@[16; 22)
261 IDENT@[16; 22) "assert"
262 EXCL@[22; 23)
263 TOKEN_TREE@[23; 57)
264 L_PAREN@[23; 24)
265 STRING@[24; 52)
266 COMMA@[52; 53)
267 WHITESPACE@[53; 54)
268 STRING@[54; 56)
269 R_PAREN@[56; 57)
270 SEMI@[57; 58)
271 "#
272 .trim()
273 );
274}
275
276#[test]
277fn test_syntax_tree_inside_string() {
278 let (analysis, range) = single_file_with_range(
279 r#"fn test() {
280 assert!("
281<|>fn foo() {
282}<|>
283fn bar() {
284}
285 ", "");
286}"#
287 .trim(),
288 );
289 let syn = analysis.syntax_tree(range.file_id, Some(range.range));
290 assert_eq!(
291 syn.trim(),
292 r#"
293SOURCE_FILE@[0; 12)
294 FN_DEF@[0; 12)
295 FN_KW@[0; 2)
296 WHITESPACE@[2; 3)
297 NAME@[3; 6)
298 IDENT@[3; 6) "foo"
299 PARAM_LIST@[6; 8)
300 L_PAREN@[6; 7)
301 R_PAREN@[7; 8)
302 WHITESPACE@[8; 9)
303 BLOCK@[9; 12)
304 L_CURLY@[9; 10)
305 WHITESPACE@[10; 11)
306 R_CURLY@[11; 12)
307"#
308 .trim()
309 );
310
311 // With a raw string
312 let (analysis, range) = single_file_with_range(
313 r###"fn test() {
314 assert!(r#"
315<|>fn foo() {
316}<|>
317fn bar() {
318}
319 "#, "");
320}"###
321 .trim(),
322 );
323 let syn = analysis.syntax_tree(range.file_id, Some(range.range));
324 assert_eq!(
325 syn.trim(),
326 r#"
327SOURCE_FILE@[0; 12)
328 FN_DEF@[0; 12)
329 FN_KW@[0; 2)
330 WHITESPACE@[2; 3)
331 NAME@[3; 6)
332 IDENT@[3; 6) "foo"
333 PARAM_LIST@[6; 8)
334 L_PAREN@[6; 7)
335 R_PAREN@[7; 8)
336 WHITESPACE@[8; 9)
337 BLOCK@[9; 12)
338 L_CURLY@[9; 10)
339 WHITESPACE@[10; 11)
340 R_CURLY@[11; 12)
341"#
342 .trim()
343 );
344
345 // With a raw string
346 let (analysis, range) = single_file_with_range(
347 r###"fn test() {
348 assert!(r<|>#"
349fn foo() {
350}
351fn bar() {
352}"<|>#, "");
353}"###
354 .trim(),
355 );
356 let syn = analysis.syntax_tree(range.file_id, Some(range.range));
357 assert_eq!(
358 syn.trim(),
359 r#"
360SOURCE_FILE@[0; 25)
361 FN_DEF@[0; 12)
362 FN_KW@[0; 2)
363 WHITESPACE@[2; 3)
364 NAME@[3; 6)
365 IDENT@[3; 6) "foo"
366 PARAM_LIST@[6; 8)
367 L_PAREN@[6; 7)
368 R_PAREN@[7; 8)
369 WHITESPACE@[8; 9)
370 BLOCK@[9; 12)
371 L_CURLY@[9; 10)
372 WHITESPACE@[10; 11)
373 R_CURLY@[11; 12)
374 WHITESPACE@[12; 13)
375 FN_DEF@[13; 25)
376 FN_KW@[13; 15)
377 WHITESPACE@[15; 16)
378 NAME@[16; 19)
379 IDENT@[16; 19) "bar"
380 PARAM_LIST@[19; 21)
381 L_PAREN@[19; 20)
382 R_PAREN@[20; 21)
383 WHITESPACE@[21; 22)
384 BLOCK@[22; 25)
385 L_CURLY@[22; 23)
386 WHITESPACE@[23; 24)
387 R_CURLY@[24; 25)
388
389"#
390 .trim()
391 );
392}
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index dce6fcc67..89e96a33a 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -32,7 +32,9 @@ pub fn handle_analyzer_status(world: ServerWorld, _: ()) -> Result<String> {
32 32
33pub fn handle_syntax_tree(world: ServerWorld, params: req::SyntaxTreeParams) -> Result<String> { 33pub fn handle_syntax_tree(world: ServerWorld, params: req::SyntaxTreeParams) -> Result<String> {
34 let id = params.text_document.try_conv_with(&world)?; 34 let id = params.text_document.try_conv_with(&world)?;
35 let res = world.analysis().syntax_tree(id); 35 let line_index = world.analysis().file_line_index(id);
36 let text_range = params.range.map(|p| p.conv_with(&line_index));
37 let res = world.analysis().syntax_tree(id, text_range);
36 Ok(res) 38 Ok(res)
37} 39}
38 40
diff --git a/crates/ra_lsp_server/src/req.rs b/crates/ra_lsp_server/src/req.rs
index e224ede80..5c589f969 100644
--- a/crates/ra_lsp_server/src/req.rs
+++ b/crates/ra_lsp_server/src/req.rs
@@ -39,6 +39,7 @@ impl Request for SyntaxTree {
39#[serde(rename_all = "camelCase")] 39#[serde(rename_all = "camelCase")]
40pub struct SyntaxTreeParams { 40pub struct SyntaxTreeParams {
41 pub text_document: TextDocumentIdentifier, 41 pub text_document: TextDocumentIdentifier,
42 pub range: Option<Range>,
42} 43}
43 44
44pub enum ExtendSelection {} 45pub enum ExtendSelection {}