aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty')
-rw-r--r--crates/ra_hir_ty/Cargo.toml8
-rw-r--r--crates/ra_hir_ty/src/diagnostics.rs19
-rw-r--r--crates/ra_hir_ty/src/diagnostics/expr.rs4
-rw-r--r--crates/ra_hir_ty/src/tests.rs2
-rw-r--r--crates/ra_hir_ty/src/traits/chalk.rs19
-rw-r--r--crates/ra_hir_ty/src/traits/chalk/mapping.rs22
6 files changed, 42 insertions, 32 deletions
diff --git a/crates/ra_hir_ty/Cargo.toml b/crates/ra_hir_ty/Cargo.toml
index cdabb359f..623ce261a 100644
--- a/crates/ra_hir_ty/Cargo.toml
+++ b/crates/ra_hir_ty/Cargo.toml
@@ -28,13 +28,13 @@ test_utils = { path = "../test_utils" }
28 28
29scoped-tls = "1" 29scoped-tls = "1"
30 30
31chalk-solve = { version = "0.18.0" } 31chalk-solve = { version = "0.19.0" }
32chalk-ir = { version = "0.18.0" } 32chalk-ir = { version = "0.19.0" }
33chalk-recursive = { version = "0.18.0" } 33chalk-recursive = { version = "0.19.0" }
34 34
35[dev-dependencies] 35[dev-dependencies]
36expect = { path = "../expect" } 36expect = { path = "../expect" }
37 37
38tracing = "0.1" 38tracing = "0.1"
39tracing-subscriber = { version = "0.2", default-features = false, features = ["env-filter", "registry"] } 39tracing-subscriber = { version = "0.2", default-features = false, features = ["env-filter", "registry"] }
40tracing-tree = { version = "0.1.3" } 40tracing-tree = { version = "0.1.4" }
diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/ra_hir_ty/src/diagnostics.rs
index d3ee9cf55..f210c305a 100644
--- a/crates/ra_hir_ty/src/diagnostics.rs
+++ b/crates/ra_hir_ty/src/diagnostics.rs
@@ -29,7 +29,7 @@ pub fn validate_body(db: &dyn HirDatabase, owner: DefWithBodyId, sink: &mut Diag
29#[derive(Debug)] 29#[derive(Debug)]
30pub struct NoSuchField { 30pub struct NoSuchField {
31 pub file: HirFileId, 31 pub file: HirFileId,
32 pub field: AstPtr<ast::RecordField>, 32 pub field: AstPtr<ast::RecordExprField>,
33} 33}
34 34
35impl Diagnostic for NoSuchField { 35impl Diagnostic for NoSuchField {
@@ -47,19 +47,19 @@ impl Diagnostic for NoSuchField {
47} 47}
48 48
49impl AstDiagnostic for NoSuchField { 49impl AstDiagnostic for NoSuchField {
50 type AST = ast::RecordField; 50 type AST = ast::RecordExprField;
51 51
52 fn ast(&self, db: &dyn AstDatabase) -> Self::AST { 52 fn ast(&self, db: &dyn AstDatabase) -> Self::AST {
53 let root = db.parse_or_expand(self.source().file_id).unwrap(); 53 let root = db.parse_or_expand(self.source().file_id).unwrap();
54 let node = self.source().value.to_node(&root); 54 let node = self.source().value.to_node(&root);
55 ast::RecordField::cast(node).unwrap() 55 ast::RecordExprField::cast(node).unwrap()
56 } 56 }
57} 57}
58 58
59#[derive(Debug)] 59#[derive(Debug)]
60pub struct MissingFields { 60pub struct MissingFields {
61 pub file: HirFileId, 61 pub file: HirFileId,
62 pub field_list: AstPtr<ast::RecordFieldList>, 62 pub field_list: AstPtr<ast::RecordExprFieldList>,
63 pub missed_fields: Vec<Name>, 63 pub missed_fields: Vec<Name>,
64} 64}
65 65
@@ -80,12 +80,12 @@ impl Diagnostic for MissingFields {
80} 80}
81 81
82impl AstDiagnostic for MissingFields { 82impl AstDiagnostic for MissingFields {
83 type AST = ast::RecordFieldList; 83 type AST = ast::RecordExprFieldList;
84 84
85 fn ast(&self, db: &dyn AstDatabase) -> Self::AST { 85 fn ast(&self, db: &dyn AstDatabase) -> Self::AST {
86 let root = db.parse_or_expand(self.source().file_id).unwrap(); 86 let root = db.parse_or_expand(self.source().file_id).unwrap();
87 let node = self.source().value.to_node(&root); 87 let node = self.source().value.to_node(&root);
88 ast::RecordFieldList::cast(node).unwrap() 88 ast::RecordExprFieldList::cast(node).unwrap()
89 } 89 }
90} 90}
91 91
@@ -234,6 +234,9 @@ impl Diagnostic for MismatchedArgCount {
234 fn as_any(&self) -> &(dyn Any + Send + 'static) { 234 fn as_any(&self) -> &(dyn Any + Send + 'static) {
235 self 235 self
236 } 236 }
237 fn is_experimental(&self) -> bool {
238 true
239 }
237} 240}
238 241
239impl AstDiagnostic for MismatchedArgCount { 242impl AstDiagnostic for MismatchedArgCount {
@@ -248,7 +251,7 @@ impl AstDiagnostic for MismatchedArgCount {
248#[cfg(test)] 251#[cfg(test)]
249mod tests { 252mod tests {
250 use hir_def::{db::DefDatabase, AssocItemId, ModuleDefId}; 253 use hir_def::{db::DefDatabase, AssocItemId, ModuleDefId};
251 use hir_expand::diagnostics::{Diagnostic, DiagnosticSink}; 254 use hir_expand::diagnostics::{Diagnostic, DiagnosticSinkBuilder};
252 use ra_db::{fixture::WithFixture, FileId, SourceDatabase, SourceDatabaseExt}; 255 use ra_db::{fixture::WithFixture, FileId, SourceDatabase, SourceDatabaseExt};
253 use ra_syntax::{TextRange, TextSize}; 256 use ra_syntax::{TextRange, TextSize};
254 use rustc_hash::FxHashMap; 257 use rustc_hash::FxHashMap;
@@ -280,7 +283,7 @@ mod tests {
280 } 283 }
281 284
282 for f in fns { 285 for f in fns {
283 let mut sink = DiagnosticSink::new(&mut cb); 286 let mut sink = DiagnosticSinkBuilder::new().build(&mut cb);
284 validate_body(self, f.into(), &mut sink); 287 validate_body(self, f.into(), &mut sink);
285 } 288 }
286 } 289 }
diff --git a/crates/ra_hir_ty/src/diagnostics/expr.rs b/crates/ra_hir_ty/src/diagnostics/expr.rs
index fd930eab1..f0e0f2988 100644
--- a/crates/ra_hir_ty/src/diagnostics/expr.rs
+++ b/crates/ra_hir_ty/src/diagnostics/expr.rs
@@ -100,8 +100,8 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
100 100
101 if let Ok(source_ptr) = source_map.expr_syntax(id) { 101 if let Ok(source_ptr) = source_map.expr_syntax(id) {
102 let root = source_ptr.file_syntax(db.upcast()); 102 let root = source_ptr.file_syntax(db.upcast());
103 if let ast::Expr::RecordLit(record_lit) = &source_ptr.value.to_node(&root) { 103 if let ast::Expr::RecordExpr(record_lit) = &source_ptr.value.to_node(&root) {
104 if let Some(field_list) = record_lit.record_field_list() { 104 if let Some(field_list) = record_lit.record_expr_field_list() {
105 let variant_data = variant_data(db.upcast(), variant_def); 105 let variant_data = variant_data(db.upcast(), variant_def);
106 let missed_fields = missed_fields 106 let missed_fields = missed_fields
107 .into_iter() 107 .into_iter()
diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs
index 45bc14c37..016e689ff 100644
--- a/crates/ra_hir_ty/src/tests.rs
+++ b/crates/ra_hir_ty/src/tests.rs
@@ -81,7 +81,7 @@ fn check_types_impl(ra_fixture: &str, display_source: bool) {
81fn type_at_range(db: &TestDB, pos: FileRange) -> Ty { 81fn type_at_range(db: &TestDB, pos: FileRange) -> Ty {
82 let file = db.parse(pos.file_id).ok().unwrap(); 82 let file = db.parse(pos.file_id).ok().unwrap();
83 let expr = algo::find_node_at_range::<ast::Expr>(file.syntax(), pos.range).unwrap(); 83 let expr = algo::find_node_at_range::<ast::Expr>(file.syntax(), pos.range).unwrap();
84 let fn_def = expr.syntax().ancestors().find_map(ast::FnDef::cast).unwrap(); 84 let fn_def = expr.syntax().ancestors().find_map(ast::Fn::cast).unwrap();
85 let module = db.module_for_file(pos.file_id); 85 let module = db.module_for_file(pos.file_id);
86 let func = *module.child_by_source(db)[keys::FUNCTION] 86 let func = *module.child_by_source(db)[keys::FUNCTION]
87 .get(&InFile::new(pos.file_id.into(), fn_def)) 87 .get(&InFile::new(pos.file_id.into(), fn_def))
diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs
index 5298dbecf..1c7065364 100644
--- a/crates/ra_hir_ty/src/traits/chalk.rs
+++ b/crates/ra_hir_ty/src/traits/chalk.rs
@@ -183,6 +183,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
183 .collect(), 183 .collect(),
184 1, 184 1,
185 ), 185 ),
186 where_clauses: make_binders(vec![], 0),
186 }; 187 };
187 let num_vars = datas.num_binders; 188 let num_vars = datas.num_binders;
188 Arc::new(OpaqueTyDatum { opaque_ty_id: id, bound: make_binders(bound, num_vars) }) 189 Arc::new(OpaqueTyDatum { opaque_ty_id: id, bound: make_binders(bound, num_vars) })
@@ -193,15 +194,6 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
193 Ty::Unknown.to_chalk(self.db) 194 Ty::Unknown.to_chalk(self.db)
194 } 195 }
195 196
196 fn force_impl_for(
197 &self,
198 _well_known: rust_ir::WellKnownTrait,
199 _ty: &chalk_ir::TyData<Interner>,
200 ) -> Option<bool> {
201 // this method is mostly for rustc
202 None
203 }
204
205 fn is_object_safe(&self, _trait_id: chalk_ir::TraitId<Interner>) -> bool { 197 fn is_object_safe(&self, _trait_id: chalk_ir::TraitId<Interner>) -> bool {
206 // FIXME: implement actual object safety 198 // FIXME: implement actual object safety
207 true 199 true
@@ -547,8 +539,13 @@ pub(crate) fn fn_def_datum_query(
547 ), 539 ),
548 where_clauses, 540 where_clauses,
549 }; 541 };
550 let datum = 542 let datum = FnDefDatum {
551 FnDefDatum { id: fn_def_id, binders: make_binders(bound, sig.num_binders), abi: () }; 543 id: fn_def_id,
544 abi: (),
545 safety: chalk_ir::Safety::Safe,
546 variadic: sig.value.is_varargs,
547 binders: make_binders(bound, sig.num_binders),
548 };
552 Arc::new(datum) 549 Arc::new(datum)
553} 550}
554 551
diff --git a/crates/ra_hir_ty/src/traits/chalk/mapping.rs b/crates/ra_hir_ty/src/traits/chalk/mapping.rs
index 09d8347ca..b3e92993d 100644
--- a/crates/ra_hir_ty/src/traits/chalk/mapping.rs
+++ b/crates/ra_hir_ty/src/traits/chalk/mapping.rs
@@ -30,11 +30,16 @@ impl ToChalk for Ty {
30 Ty::Apply(apply_ty) => match apply_ty.ctor { 30 Ty::Apply(apply_ty) => match apply_ty.ctor {
31 TypeCtor::Ref(m) => ref_to_chalk(db, m, apply_ty.parameters), 31 TypeCtor::Ref(m) => ref_to_chalk(db, m, apply_ty.parameters),
32 TypeCtor::Array => array_to_chalk(db, apply_ty.parameters), 32 TypeCtor::Array => array_to_chalk(db, apply_ty.parameters),
33 TypeCtor::FnPtr { num_args: _, is_varargs: _ } => { 33 TypeCtor::FnPtr { num_args: _, is_varargs } => {
34 // FIXME: handle is_varargs
35 let substitution = apply_ty.parameters.to_chalk(db).shifted_in(&Interner); 34 let substitution = apply_ty.parameters.to_chalk(db).shifted_in(&Interner);
36 chalk_ir::TyData::Function(chalk_ir::Fn { num_binders: 0, substitution }) 35 chalk_ir::TyData::Function(chalk_ir::FnPointer {
37 .intern(&Interner) 36 num_binders: 0,
37 abi: (),
38 safety: chalk_ir::Safety::Safe,
39 variadic: is_varargs,
40 substitution,
41 })
42 .intern(&Interner)
38 } 43 }
39 _ => { 44 _ => {
40 let name = apply_ty.ctor.to_chalk(db); 45 let name = apply_ty.ctor.to_chalk(db);
@@ -118,7 +123,12 @@ impl ToChalk for Ty {
118 let parameters = from_chalk(db, opaque_ty.substitution); 123 let parameters = from_chalk(db, opaque_ty.substitution);
119 Ty::Opaque(OpaqueTy { opaque_ty_id: impl_trait_id, parameters }) 124 Ty::Opaque(OpaqueTy { opaque_ty_id: impl_trait_id, parameters })
120 } 125 }
121 chalk_ir::TyData::Function(chalk_ir::Fn { num_binders, substitution }) => { 126 chalk_ir::TyData::Function(chalk_ir::FnPointer {
127 num_binders,
128 variadic,
129 substitution,
130 ..
131 }) => {
122 assert_eq!(num_binders, 0); 132 assert_eq!(num_binders, 0);
123 let parameters: Substs = from_chalk( 133 let parameters: Substs = from_chalk(
124 db, 134 db,
@@ -127,7 +137,7 @@ impl ToChalk for Ty {
127 Ty::Apply(ApplicationTy { 137 Ty::Apply(ApplicationTy {
128 ctor: TypeCtor::FnPtr { 138 ctor: TypeCtor::FnPtr {
129 num_args: (parameters.len() - 1) as u16, 139 num_args: (parameters.len() - 1) as u16,
130 is_varargs: false, 140 is_varargs: variadic,
131 }, 141 },
132 parameters, 142 parameters,
133 }) 143 })