diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-04-05 18:25:19 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-04-05 18:25:19 +0100 |
commit | c91b5376835ab54cd4bca02953625ef1f1fabeba (patch) | |
tree | 390be0ec3c0a57db5188b06c86f0a7df0242b01c /crates/hir/src | |
parent | 467a5c6cd13af6ccb76e9ebdb35f96fc10fb438f (diff) | |
parent | a316d583600e11ee1fcc8027a838efafe435f03c (diff) |
Merge #8348
8348: Make `Binders` more like Chalk r=flodiebold a=flodiebold
Working towards #8313.
- hide `value`
- use `VariableKinds`
- adjust `subst` to be like Chalk's `substitute`
- also clean up some other `TypeWalk` stuff to prepare for it being replaced by Chalk's `Fold`
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/hir/src')
-rw-r--r-- | crates/hir/src/display.rs | 4 | ||||
-rw-r--r-- | crates/hir/src/lib.rs | 10 | ||||
-rw-r--r-- | crates/hir/src/semantics.rs | 4 | ||||
-rw-r--r-- | crates/hir/src/source_analyzer.rs | 4 |
4 files changed, 12 insertions, 10 deletions
diff --git a/crates/hir/src/display.rs b/crates/hir/src/display.rs index 993772aac..01a4d205f 100644 --- a/crates/hir/src/display.rs +++ b/crates/hir/src/display.rs | |||
@@ -9,6 +9,7 @@ use hir_ty::display::{ | |||
9 | write_bounds_like_dyn_trait_with_prefix, write_visibility, HirDisplay, HirDisplayError, | 9 | write_bounds_like_dyn_trait_with_prefix, write_visibility, HirDisplay, HirDisplayError, |
10 | HirFormatter, | 10 | HirFormatter, |
11 | }; | 11 | }; |
12 | use hir_ty::Interner; | ||
12 | use syntax::ast::{self, NameOwner}; | 13 | use syntax::ast::{self, NameOwner}; |
13 | 14 | ||
14 | use crate::{ | 15 | use crate::{ |
@@ -235,7 +236,8 @@ impl HirDisplay for TypeParam { | |||
235 | write!(f, "{}", self.name(f.db))?; | 236 | write!(f, "{}", self.name(f.db))?; |
236 | let bounds = f.db.generic_predicates_for_param(self.id); | 237 | let bounds = f.db.generic_predicates_for_param(self.id); |
237 | let substs = TyBuilder::type_params_subst(f.db, self.id.parent); | 238 | let substs = TyBuilder::type_params_subst(f.db, self.id.parent); |
238 | let predicates = bounds.iter().cloned().map(|b| b.subst(&substs)).collect::<Vec<_>>(); | 239 | let predicates = |
240 | bounds.iter().cloned().map(|b| b.substitute(&Interner, &substs)).collect::<Vec<_>>(); | ||
239 | if !(predicates.is_empty() || f.omit_verbose_types()) { | 241 | if !(predicates.is_empty() || f.omit_verbose_types()) { |
240 | write_bounds_like_dyn_trait_with_prefix(":", &predicates, f)?; | 242 | write_bounds_like_dyn_trait_with_prefix(":", &predicates, f)?; |
241 | } | 243 | } |
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index b14c9a675..003821981 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs | |||
@@ -516,7 +516,7 @@ impl Field { | |||
516 | VariantDef::Variant(it) => it.parent.id.into(), | 516 | VariantDef::Variant(it) => it.parent.id.into(), |
517 | }; | 517 | }; |
518 | let substs = TyBuilder::type_params_subst(db, generic_def_id); | 518 | let substs = TyBuilder::type_params_subst(db, generic_def_id); |
519 | let ty = db.field_types(var_id)[self.id].clone().subst(&substs); | 519 | let ty = db.field_types(var_id)[self.id].clone().substitute(&Interner, &substs); |
520 | Type::new(db, self.parent.module(db).id.krate(), var_id, ty) | 520 | Type::new(db, self.parent.module(db).id.krate(), var_id, ty) |
521 | } | 521 | } |
522 | 522 | ||
@@ -702,7 +702,7 @@ impl_from!(Struct, Union, Enum for Adt); | |||
702 | impl Adt { | 702 | impl Adt { |
703 | pub fn has_non_default_type_params(self, db: &dyn HirDatabase) -> bool { | 703 | pub fn has_non_default_type_params(self, db: &dyn HirDatabase) -> bool { |
704 | let subst = db.generic_defaults(self.into()); | 704 | let subst = db.generic_defaults(self.into()); |
705 | subst.iter().any(|ty| ty.value.is_unknown()) | 705 | subst.iter().any(|ty| ty.skip_binders().is_unknown()) |
706 | } | 706 | } |
707 | 707 | ||
708 | /// Turns this ADT into a type. Any type parameters of the ADT will be | 708 | /// Turns this ADT into a type. Any type parameters of the ADT will be |
@@ -1089,7 +1089,7 @@ pub struct TypeAlias { | |||
1089 | impl TypeAlias { | 1089 | impl TypeAlias { |
1090 | pub fn has_non_default_type_params(self, db: &dyn HirDatabase) -> bool { | 1090 | pub fn has_non_default_type_params(self, db: &dyn HirDatabase) -> bool { |
1091 | let subst = db.generic_defaults(self.id.into()); | 1091 | let subst = db.generic_defaults(self.id.into()); |
1092 | subst.iter().any(|ty| ty.value.is_unknown()) | 1092 | subst.iter().any(|ty| ty.skip_binders().is_unknown()) |
1093 | } | 1093 | } |
1094 | 1094 | ||
1095 | pub fn module(self, db: &dyn HirDatabase) -> Module { | 1095 | pub fn module(self, db: &dyn HirDatabase) -> Module { |
@@ -1503,7 +1503,7 @@ impl TypeParam { | |||
1503 | let krate = self.id.parent.module(db.upcast()).krate(); | 1503 | let krate = self.id.parent.module(db.upcast()).krate(); |
1504 | let ty = params.get(local_idx)?.clone(); | 1504 | let ty = params.get(local_idx)?.clone(); |
1505 | let subst = TyBuilder::type_params_subst(db, self.id.parent); | 1505 | let subst = TyBuilder::type_params_subst(db, self.id.parent); |
1506 | let ty = ty.subst(&subst.prefix(local_idx)); | 1506 | let ty = ty.substitute(&Interner, &subst.prefix(local_idx)); |
1507 | Some(Type::new_with_resolver_inner(db, krate, &resolver, ty)) | 1507 | Some(Type::new_with_resolver_inner(db, krate, &resolver, ty)) |
1508 | } | 1508 | } |
1509 | } | 1509 | } |
@@ -1916,7 +1916,7 @@ impl Type { | |||
1916 | .iter() | 1916 | .iter() |
1917 | .map(|(local_id, ty)| { | 1917 | .map(|(local_id, ty)| { |
1918 | let def = Field { parent: variant_id.into(), id: local_id }; | 1918 | let def = Field { parent: variant_id.into(), id: local_id }; |
1919 | let ty = ty.clone().subst(substs); | 1919 | let ty = ty.clone().substitute(&Interner, substs); |
1920 | (def, self.derived(ty)) | 1920 | (def, self.derived(ty)) |
1921 | }) | 1921 | }) |
1922 | .collect() | 1922 | .collect() |
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index 3bf722d2a..7955bf0b5 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs | |||
@@ -494,9 +494,9 @@ impl<'db> SemanticsImpl<'db> { | |||
494 | fn resolve_method_call_as_callable(&self, call: &ast::MethodCallExpr) -> Option<Callable> { | 494 | fn resolve_method_call_as_callable(&self, call: &ast::MethodCallExpr) -> Option<Callable> { |
495 | // FIXME: this erases Substs | 495 | // FIXME: this erases Substs |
496 | let func = self.resolve_method_call(call)?; | 496 | let func = self.resolve_method_call(call)?; |
497 | let ty = self.db.value_ty(func.into()); | 497 | let (ty, _) = self.db.value_ty(func.into()).into_value_and_skipped_binders(); |
498 | let resolver = self.analyze(call.syntax()).resolver; | 498 | let resolver = self.analyze(call.syntax()).resolver; |
499 | let ty = Type::new_with_resolver(self.db, &resolver, ty.value)?; | 499 | let ty = Type::new_with_resolver(self.db, &resolver, ty)?; |
500 | let mut res = ty.as_callable(self.db)?; | 500 | let mut res = ty.as_callable(self.db)?; |
501 | res.is_bound_method = true; | 501 | res.is_bound_method = true; |
502 | Some(res) | 502 | Some(res) |
diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs index 8e9ea0a03..4ce1c2080 100644 --- a/crates/hir/src/source_analyzer.rs +++ b/crates/hir/src/source_analyzer.rs | |||
@@ -20,7 +20,7 @@ use hir_def::{ | |||
20 | use hir_expand::{hygiene::Hygiene, name::AsName, HirFileId, InFile}; | 20 | use hir_expand::{hygiene::Hygiene, name::AsName, HirFileId, InFile}; |
21 | use hir_ty::{ | 21 | use hir_ty::{ |
22 | diagnostics::{record_literal_missing_fields, record_pattern_missing_fields}, | 22 | diagnostics::{record_literal_missing_fields, record_pattern_missing_fields}, |
23 | InferenceResult, Substitution, TyLoweringContext, | 23 | InferenceResult, Interner, Substitution, TyLoweringContext, |
24 | }; | 24 | }; |
25 | use syntax::{ | 25 | use syntax::{ |
26 | ast::{self, AstNode}, | 26 | ast::{self, AstNode}, |
@@ -339,7 +339,7 @@ impl SourceAnalyzer { | |||
339 | .into_iter() | 339 | .into_iter() |
340 | .map(|local_id| { | 340 | .map(|local_id| { |
341 | let field = FieldId { parent: variant, local_id }; | 341 | let field = FieldId { parent: variant, local_id }; |
342 | let ty = field_types[local_id].clone().subst(substs); | 342 | let ty = field_types[local_id].clone().substitute(&Interner, substs); |
343 | (field.into(), Type::new_with_resolver_inner(db, krate, &self.resolver, ty)) | 343 | (field.into(), Type::new_with_resolver_inner(db, krate, &self.resolver, ty)) |
344 | }) | 344 | }) |
345 | .collect() | 345 | .collect() |