aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty/infer.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-09-27 03:58:26 +0100
committerGitHub <[email protected]>2019-09-27 03:58:26 +0100
commit2b69c84396cf376b496e7de3c954400e51b5fc24 (patch)
tree385a5a3cb167877096534bad2a7c3efdee3c9c1d /crates/ra_hir/src/ty/infer.rs
parentfc218ec0d04577e33db509e956a044293c12ea67 (diff)
parentedadeb95be16a69175e94a0e211ae9bb74267abb (diff)
Merge #1815
1815: Support correct `$crate` expansion in macros r=uHOOCCOOHu a=uHOOCCOOHu This PR makes normal use cases of `$crate` from macros work as expected. It makes more macros from `std` work. Type inference works well with `panic`, `unimplemented`, `format`, and maybe more. Sadly that `vec![1, 2, 3]` still not works, but it is not longer an issue about macro. Screenshot: ![Screenshot_20190927_022136](https://user-images.githubusercontent.com/14816024/65714465-b4568f80-e0cd-11e9-8043-dd44c2ae8040.png) Co-authored-by: uHOOCCOOHu <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/ty/infer.rs')
-rw-r--r--crates/ra_hir/src/ty/infer.rs9
1 files changed, 4 insertions, 5 deletions
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs
index 8e07fc186..2e4a489a0 100644
--- a/crates/ra_hir/src/ty/infer.rs
+++ b/crates/ra_hir/src/ty/infer.rs
@@ -609,7 +609,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
609 609
610 for (i, &subpat) in subpats.iter().enumerate() { 610 for (i, &subpat) in subpats.iter().enumerate() {
611 let expected_ty = def 611 let expected_ty = def
612 .and_then(|d| d.field(self.db, &Name::tuple_field_name(i))) 612 .and_then(|d| d.field(self.db, &Name::new_tuple_field(i)))
613 .map_or(Ty::Unknown, |field| field.ty(self.db)) 613 .map_or(Ty::Unknown, |field| field.ty(self.db))
614 .subst(&substs); 614 .subst(&substs);
615 let expected_ty = self.normalize_associated_types_in(expected_ty); 615 let expected_ty = self.normalize_associated_types_in(expected_ty);
@@ -1374,10 +1374,9 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1374 ) 1374 )
1375 .find_map(|derefed_ty| match canonicalized.decanonicalize_ty(derefed_ty.value) { 1375 .find_map(|derefed_ty| match canonicalized.decanonicalize_ty(derefed_ty.value) {
1376 Ty::Apply(a_ty) => match a_ty.ctor { 1376 Ty::Apply(a_ty) => match a_ty.ctor {
1377 TypeCtor::Tuple { .. } => { 1377 TypeCtor::Tuple { .. } => name
1378 let i = name.to_string().parse::<usize>().ok(); 1378 .as_tuple_index()
1379 i.and_then(|i| a_ty.parameters.0.get(i).cloned()) 1379 .and_then(|idx| a_ty.parameters.0.get(idx).cloned()),
1380 }
1381 TypeCtor::Adt(Adt::Struct(s)) => s.field(self.db, name).map(|field| { 1380 TypeCtor::Adt(Adt::Struct(s)) => s.field(self.db, name).map(|field| {
1382 self.write_field_resolution(tgt_expr, field); 1381 self.write_field_resolution(tgt_expr, field);
1383 field.ty(self.db).subst(&a_ty.parameters) 1382 field.ty(self.db).subst(&a_ty.parameters)