aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty
diff options
context:
space:
mode:
authorDmitry <[email protected]>2020-08-09 14:35:51 +0100
committerDmitry <[email protected]>2020-08-09 14:39:32 +0100
commit8068302fefc75440b823f4bf1731a5f347d7c767 (patch)
tree251b967182e79bc82a58c2fb208c688f6152df1f /crates/ra_hir_ty
parent1a43a0f63e0008787225abb6fb2baef97b6a39e0 (diff)
parent8a57afe5a4bfab40072a83f7dc4ca560bf860919 (diff)
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'crates/ra_hir_ty')
-rw-r--r--crates/ra_hir_ty/Cargo.toml6
-rw-r--r--crates/ra_hir_ty/src/diagnostics.rs14
-rw-r--r--crates/ra_hir_ty/src/diagnostics/expr.rs6
-rw-r--r--crates/ra_hir_ty/src/diagnostics/unsafe_check.rs38
-rw-r--r--crates/ra_hir_ty/src/infer.rs11
-rw-r--r--crates/ra_hir_ty/src/lower.rs5
-rw-r--r--crates/ra_hir_ty/src/tests.rs2
-rw-r--r--crates/ra_hir_ty/src/tests/simple.rs38
-rw-r--r--crates/ra_hir_ty/src/traits/chalk.rs19
-rw-r--r--crates/ra_hir_ty/src/traits/chalk/mapping.rs22
10 files changed, 117 insertions, 44 deletions
diff --git a/crates/ra_hir_ty/Cargo.toml b/crates/ra_hir_ty/Cargo.toml
index 7242e2cb6..83397d579 100644
--- a/crates/ra_hir_ty/Cargo.toml
+++ b/crates/ra_hir_ty/Cargo.toml
@@ -28,9 +28,9 @@ 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.21.0" }
32chalk-ir = { version = "0.18.0" } 32chalk-ir = { version = "0.21.0" }
33chalk-recursive = { version = "0.18.0" } 33chalk-recursive = { version = "0.21.0" }
34 34
35[dev-dependencies] 35[dev-dependencies]
36expect = { path = "../expect" } 36expect = { path = "../expect" }
diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/ra_hir_ty/src/diagnostics.rs
index 885abbaf2..977c0525b 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,19 +80,19 @@ 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
92#[derive(Debug)] 92#[derive(Debug)]
93pub struct MissingPatFields { 93pub struct MissingPatFields {
94 pub file: HirFileId, 94 pub file: HirFileId,
95 pub field_list: AstPtr<ast::RecordFieldPatList>, 95 pub field_list: AstPtr<ast::RecordPatFieldList>,
96 pub missed_fields: Vec<Name>, 96 pub missed_fields: Vec<Name>,
97} 97}
98 98
diff --git a/crates/ra_hir_ty/src/diagnostics/expr.rs b/crates/ra_hir_ty/src/diagnostics/expr.rs
index fd930eab1..95bbf2d95 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()
@@ -131,7 +131,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
131 if let Some(expr) = source_ptr.value.as_ref().left() { 131 if let Some(expr) = source_ptr.value.as_ref().left() {
132 let root = source_ptr.file_syntax(db.upcast()); 132 let root = source_ptr.file_syntax(db.upcast());
133 if let ast::Pat::RecordPat(record_pat) = expr.to_node(&root) { 133 if let ast::Pat::RecordPat(record_pat) = expr.to_node(&root) {
134 if let Some(field_list) = record_pat.record_field_pat_list() { 134 if let Some(field_list) = record_pat.record_pat_field_list() {
135 let variant_data = variant_data(db.upcast(), variant_def); 135 let variant_data = variant_data(db.upcast(), variant_def);
136 let missed_fields = missed_fields 136 let missed_fields = missed_fields
137 .into_iter() 137 .into_iter()
diff --git a/crates/ra_hir_ty/src/diagnostics/unsafe_check.rs b/crates/ra_hir_ty/src/diagnostics/unsafe_check.rs
index 5cc76bdce..61ffbf5d1 100644
--- a/crates/ra_hir_ty/src/diagnostics/unsafe_check.rs
+++ b/crates/ra_hir_ty/src/diagnostics/unsafe_check.rs
@@ -6,6 +6,7 @@ use std::sync::Arc;
6use hir_def::{ 6use hir_def::{
7 body::Body, 7 body::Body,
8 expr::{Expr, ExprId, UnaryOp}, 8 expr::{Expr, ExprId, UnaryOp},
9 resolver::{resolver_for_expr, ResolveValueResult, ValueNs},
9 DefWithBodyId, 10 DefWithBodyId,
10}; 11};
11use hir_expand::diagnostics::DiagnosticSink; 12use hir_expand::diagnostics::DiagnosticSink;
@@ -70,7 +71,7 @@ pub fn unsafe_expressions(
70) -> Vec<UnsafeExpr> { 71) -> Vec<UnsafeExpr> {
71 let mut unsafe_exprs = vec![]; 72 let mut unsafe_exprs = vec![];
72 let body = db.body(def); 73 let body = db.body(def);
73 walk_unsafe(&mut unsafe_exprs, db, infer, &body, body.body_expr, false); 74 walk_unsafe(&mut unsafe_exprs, db, infer, def, &body, body.body_expr, false);
74 75
75 unsafe_exprs 76 unsafe_exprs
76} 77}
@@ -79,6 +80,7 @@ fn walk_unsafe(
79 unsafe_exprs: &mut Vec<UnsafeExpr>, 80 unsafe_exprs: &mut Vec<UnsafeExpr>,
80 db: &dyn HirDatabase, 81 db: &dyn HirDatabase,
81 infer: &InferenceResult, 82 infer: &InferenceResult,
83 def: DefWithBodyId,
82 body: &Body, 84 body: &Body,
83 current: ExprId, 85 current: ExprId,
84 inside_unsafe_block: bool, 86 inside_unsafe_block: bool,
@@ -97,6 +99,15 @@ fn walk_unsafe(
97 } 99 }
98 } 100 }
99 } 101 }
102 Expr::Path(path) => {
103 let resolver = resolver_for_expr(db.upcast(), def, current);
104 let value_or_partial = resolver.resolve_path_in_value_ns(db.upcast(), path.mod_path());
105 if let Some(ResolveValueResult::ValueNs(ValueNs::StaticId(id))) = value_or_partial {
106 if db.static_data(id).mutable {
107 unsafe_exprs.push(UnsafeExpr { expr: current, inside_unsafe_block });
108 }
109 }
110 }
100 Expr::MethodCall { .. } => { 111 Expr::MethodCall { .. } => {
101 if infer 112 if infer
102 .method_resolution(current) 113 .method_resolution(current)
@@ -112,13 +123,13 @@ fn walk_unsafe(
112 } 123 }
113 } 124 }
114 Expr::Unsafe { body: child } => { 125 Expr::Unsafe { body: child } => {
115 return walk_unsafe(unsafe_exprs, db, infer, body, *child, true); 126 return walk_unsafe(unsafe_exprs, db, infer, def, body, *child, true);
116 } 127 }
117 _ => {} 128 _ => {}
118 } 129 }
119 130
120 expr.walk_child_exprs(|child| { 131 expr.walk_child_exprs(|child| {
121 walk_unsafe(unsafe_exprs, db, infer, body, child, inside_unsafe_block); 132 walk_unsafe(unsafe_exprs, db, infer, def, body, child, inside_unsafe_block);
122 }); 133 });
123} 134}
124 135
@@ -170,4 +181,25 @@ fn main() {
170"#, 181"#,
171 ); 182 );
172 } 183 }
184
185 #[test]
186 fn missing_unsafe_diagnostic_with_static_mut() {
187 check_diagnostics(
188 r#"
189struct Ty {
190 a: u8,
191}
192
193static mut static_mut: Ty = Ty { a: 0 };
194
195fn main() {
196 let x = static_mut.a;
197 //^^^^^^^^^^ This operation is unsafe and requires an unsafe function or block
198 unsafe {
199 let x = static_mut.a;
200 }
201}
202"#,
203 );
204 }
173} 205}
diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs
index 28f32a0a4..3d12039a6 100644
--- a/crates/ra_hir_ty/src/infer.rs
+++ b/crates/ra_hir_ty/src/infer.rs
@@ -440,6 +440,12 @@ impl<'a> InferenceContext<'a> {
440 let ty = self.insert_type_vars(ty.subst(&substs)); 440 let ty = self.insert_type_vars(ty.subst(&substs));
441 forbid_unresolved_segments((ty, Some(strukt.into())), unresolved) 441 forbid_unresolved_segments((ty, Some(strukt.into())), unresolved)
442 } 442 }
443 TypeNs::AdtId(AdtId::UnionId(u)) => {
444 let substs = Ty::substs_from_path(&ctx, path, u.into(), true);
445 let ty = self.db.ty(u.into());
446 let ty = self.insert_type_vars(ty.subst(&substs));
447 forbid_unresolved_segments((ty, Some(u.into())), unresolved)
448 }
443 TypeNs::EnumVariantId(var) => { 449 TypeNs::EnumVariantId(var) => {
444 let substs = Ty::substs_from_path(&ctx, path, var.into(), true); 450 let substs = Ty::substs_from_path(&ctx, path, var.into(), true);
445 let ty = self.db.ty(var.parent.into()); 451 let ty = self.db.ty(var.parent.into());
@@ -490,10 +496,7 @@ impl<'a> InferenceContext<'a> {
490 // FIXME potentially resolve assoc type 496 // FIXME potentially resolve assoc type
491 (Ty::Unknown, None) 497 (Ty::Unknown, None)
492 } 498 }
493 TypeNs::AdtId(AdtId::EnumId(_)) 499 TypeNs::AdtId(AdtId::EnumId(_)) | TypeNs::BuiltinType(_) | TypeNs::TraitId(_) => {
494 | TypeNs::AdtId(AdtId::UnionId(_))
495 | TypeNs::BuiltinType(_)
496 | TypeNs::TraitId(_) => {
497 // FIXME diagnostic 500 // FIXME diagnostic
498 (Ty::Unknown, None) 501 (Ty::Unknown, None)
499 } 502 }
diff --git a/crates/ra_hir_ty/src/lower.rs b/crates/ra_hir_ty/src/lower.rs
index 1eacc6f95..7638f167b 100644
--- a/crates/ra_hir_ty/src/lower.rs
+++ b/crates/ra_hir_ty/src/lower.rs
@@ -518,6 +518,7 @@ impl Ty {
518 let (segment, generic_def) = match resolved { 518 let (segment, generic_def) = match resolved {
519 ValueTyDefId::FunctionId(it) => (last, Some(it.into())), 519 ValueTyDefId::FunctionId(it) => (last, Some(it.into())),
520 ValueTyDefId::StructId(it) => (last, Some(it.into())), 520 ValueTyDefId::StructId(it) => (last, Some(it.into())),
521 ValueTyDefId::UnionId(it) => (last, Some(it.into())),
521 ValueTyDefId::ConstId(it) => (last, Some(it.into())), 522 ValueTyDefId::ConstId(it) => (last, Some(it.into())),
522 ValueTyDefId::StaticId(_) => (last, None), 523 ValueTyDefId::StaticId(_) => (last, None),
523 ValueTyDefId::EnumVariantId(var) => { 524 ValueTyDefId::EnumVariantId(var) => {
@@ -1148,11 +1149,12 @@ impl_from!(BuiltinType, AdtId(StructId, EnumId, UnionId), TypeAliasId for TyDefI
1148pub enum ValueTyDefId { 1149pub enum ValueTyDefId {
1149 FunctionId(FunctionId), 1150 FunctionId(FunctionId),
1150 StructId(StructId), 1151 StructId(StructId),
1152 UnionId(UnionId),
1151 EnumVariantId(EnumVariantId), 1153 EnumVariantId(EnumVariantId),
1152 ConstId(ConstId), 1154 ConstId(ConstId),
1153 StaticId(StaticId), 1155 StaticId(StaticId),
1154} 1156}
1155impl_from!(FunctionId, StructId, EnumVariantId, ConstId, StaticId for ValueTyDefId); 1157impl_from!(FunctionId, StructId, UnionId, EnumVariantId, ConstId, StaticId for ValueTyDefId);
1156 1158
1157/// Build the declared type of an item. This depends on the namespace; e.g. for 1159/// Build the declared type of an item. This depends on the namespace; e.g. for
1158/// `struct Foo(usize)`, we have two types: The type of the struct itself, and 1160/// `struct Foo(usize)`, we have two types: The type of the struct itself, and
@@ -1179,6 +1181,7 @@ pub(crate) fn value_ty_query(db: &dyn HirDatabase, def: ValueTyDefId) -> Binders
1179 match def { 1181 match def {
1180 ValueTyDefId::FunctionId(it) => type_for_fn(db, it), 1182 ValueTyDefId::FunctionId(it) => type_for_fn(db, it),
1181 ValueTyDefId::StructId(it) => type_for_struct_constructor(db, it), 1183 ValueTyDefId::StructId(it) => type_for_struct_constructor(db, it),
1184 ValueTyDefId::UnionId(it) => type_for_adt(db, it.into()),
1182 ValueTyDefId::EnumVariantId(it) => type_for_enum_variant_constructor(db, it), 1185 ValueTyDefId::EnumVariantId(it) => type_for_enum_variant_constructor(db, it),
1183 ValueTyDefId::ConstId(it) => type_for_const(db, it), 1186 ValueTyDefId::ConstId(it) => type_for_const(db, it),
1184 ValueTyDefId::StaticId(it) => type_for_static(db, it), 1187 ValueTyDefId::StaticId(it) => type_for_static(db, it),
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/tests/simple.rs b/crates/ra_hir_ty/src/tests/simple.rs
index 3fd7d5cd4..5a7cf9455 100644
--- a/crates/ra_hir_ty/src/tests/simple.rs
+++ b/crates/ra_hir_ty/src/tests/simple.rs
@@ -334,16 +334,44 @@ fn infer_union() {
334 bar: f32, 334 bar: f32,
335 } 335 }
336 336
337 fn test() {
338 let u = MyUnion { foo: 0 };
339 unsafe { baz(u); }
340 let u = MyUnion { bar: 0.0 };
341 unsafe { baz(u); }
342 }
343
337 unsafe fn baz(u: MyUnion) { 344 unsafe fn baz(u: MyUnion) {
338 let inner = u.foo; 345 let inner = u.foo;
346 let inner = u.bar;
339 } 347 }
340 "#, 348 "#,
341 expect![[r#" 349 expect![[r#"
342 61..62 'u': MyUnion 350 57..172 '{ ...); } }': ()
343 73..99 '{ ...foo; }': () 351 67..68 'u': MyUnion
344 83..88 'inner': u32 352 71..89 'MyUnio...o: 0 }': MyUnion
345 91..92 'u': MyUnion 353 86..87 '0': u32
346 91..96 'u.foo': u32 354 95..113 'unsafe...(u); }': ()
355 102..113 '{ baz(u); }': ()
356 104..107 'baz': fn baz(MyUnion)
357 104..110 'baz(u)': ()
358 108..109 'u': MyUnion
359 122..123 'u': MyUnion
360 126..146 'MyUnio... 0.0 }': MyUnion
361 141..144 '0.0': f32
362 152..170 'unsafe...(u); }': ()
363 159..170 '{ baz(u); }': ()
364 161..164 'baz': fn baz(MyUnion)
365 161..167 'baz(u)': ()
366 165..166 'u': MyUnion
367 188..189 'u': MyUnion
368 200..249 '{ ...bar; }': ()
369 210..215 'inner': u32
370 218..219 'u': MyUnion
371 218..223 'u.foo': u32
372 233..238 'inner': f32
373 241..242 'u': MyUnion
374 241..246 'u.bar': f32
347 "#]], 375 "#]],
348 ); 376 );
349} 377}
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 })