aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/code_model.rs14
-rw-r--r--crates/ra_hir/src/source_analyzer.rs3
-rw-r--r--crates/ra_hir_ty/src/infer.rs33
-rw-r--r--crates/ra_hir_ty/src/infer/path.rs29
-rw-r--r--crates/ra_hir_ty/src/lib.rs4
-rw-r--r--crates/ra_hir_ty/src/lower.rs98
6 files changed, 141 insertions, 40 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 837a3ed6d..fda31d517 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -733,8 +733,7 @@ impl Local {
733 let ty = infer[self.pat_id].clone(); 733 let ty = infer[self.pat_id].clone();
734 let resolver = def.resolver(db); 734 let resolver = def.resolver(db);
735 let krate = def.module(db).krate; 735 let krate = def.module(db).krate;
736 let ctx = hir_ty::TyLoweringContext { db, resolver: &resolver }; 736 let environment = TraitEnvironment::lower(db, &resolver);
737 let environment = TraitEnvironment::lower(&ctx);
738 Type { krate, ty: InEnvironment { value: ty, environment } } 737 Type { krate, ty: InEnvironment { value: ty, environment } }
739 } 738 }
740 739
@@ -790,8 +789,12 @@ impl ImplBlock {
790 pub fn target_ty(&self, db: &impl HirDatabase) -> Type { 789 pub fn target_ty(&self, db: &impl HirDatabase) -> Type {
791 let impl_data = db.impl_data(self.id); 790 let impl_data = db.impl_data(self.id);
792 let resolver = self.id.resolver(db); 791 let resolver = self.id.resolver(db);
793 let ctx = hir_ty::TyLoweringContext { db, resolver: &resolver }; 792 let ctx = hir_ty::TyLoweringContext {
794 let environment = TraitEnvironment::lower(&ctx); 793 db,
794 resolver: &resolver,
795 impl_trait_mode: hir_ty::ImplTraitLoweringMode::Disallowed,
796 };
797 let environment = TraitEnvironment::lower(db, &resolver);
795 let ty = Ty::from_hir(&ctx, &impl_data.target_type); 798 let ty = Ty::from_hir(&ctx, &impl_data.target_type);
796 Type { 799 Type {
797 krate: self.id.lookup(db).container.module(db).krate, 800 krate: self.id.lookup(db).container.module(db).krate,
@@ -846,8 +849,7 @@ pub struct Type {
846impl Type { 849impl Type {
847 fn new(db: &impl HirDatabase, krate: CrateId, lexical_env: impl HasResolver, ty: Ty) -> Type { 850 fn new(db: &impl HirDatabase, krate: CrateId, lexical_env: impl HasResolver, ty: Ty) -> Type {
848 let resolver = lexical_env.resolver(db); 851 let resolver = lexical_env.resolver(db);
849 let ctx = hir_ty::TyLoweringContext { db, resolver: &resolver }; 852 let environment = TraitEnvironment::lower(db, &resolver);
850 let environment = TraitEnvironment::lower(&ctx);
851 Type { krate, ty: InEnvironment { value: ty, environment } } 853 Type { krate, ty: InEnvironment { value: ty, environment } }
852 } 854 }
853 855
diff --git a/crates/ra_hir/src/source_analyzer.rs b/crates/ra_hir/src/source_analyzer.rs
index 9cfd52856..bb9a35c5d 100644
--- a/crates/ra_hir/src/source_analyzer.rs
+++ b/crates/ra_hir/src/source_analyzer.rs
@@ -179,8 +179,7 @@ impl SourceAnalyzer {
179 } 179 }
180 180
181 fn trait_env(&self, db: &impl HirDatabase) -> Arc<TraitEnvironment> { 181 fn trait_env(&self, db: &impl HirDatabase) -> Arc<TraitEnvironment> {
182 let ctx = hir_ty::TyLoweringContext { db, resolver: &self.resolver }; 182 TraitEnvironment::lower(db, &self.resolver)
183 TraitEnvironment::lower(&ctx)
184 } 183 }
185 184
186 pub fn type_of(&self, db: &impl HirDatabase, expr: &ast::Expr) -> Option<Type> { 185 pub fn type_of(&self, db: &impl HirDatabase, expr: &ast::Expr) -> Option<Type> {
diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs
index e27ce6e91..b4a3e1675 100644
--- a/crates/ra_hir_ty/src/infer.rs
+++ b/crates/ra_hir_ty/src/infer.rs
@@ -42,7 +42,9 @@ use super::{
42 ApplicationTy, GenericPredicate, InEnvironment, ProjectionTy, Substs, TraitEnvironment, 42 ApplicationTy, GenericPredicate, InEnvironment, ProjectionTy, Substs, TraitEnvironment,
43 TraitRef, Ty, TypeCtor, TypeWalk, Uncertain, 43 TraitRef, Ty, TypeCtor, TypeWalk, Uncertain,
44}; 44};
45use crate::{db::HirDatabase, infer::diagnostics::InferenceDiagnostic}; 45use crate::{
46 db::HirDatabase, infer::diagnostics::InferenceDiagnostic, lower::ImplTraitLoweringMode,
47};
46 48
47pub(crate) use unify::unify; 49pub(crate) use unify::unify;
48 50
@@ -215,13 +217,12 @@ struct InferenceContext<'a, D: HirDatabase> {
215 217
216impl<'a, D: HirDatabase> InferenceContext<'a, D> { 218impl<'a, D: HirDatabase> InferenceContext<'a, D> {
217 fn new(db: &'a D, owner: DefWithBodyId, resolver: Resolver) -> Self { 219 fn new(db: &'a D, owner: DefWithBodyId, resolver: Resolver) -> Self {
218 let ctx = crate::lower::TyLoweringContext { db, resolver: &resolver };
219 InferenceContext { 220 InferenceContext {
220 result: InferenceResult::default(), 221 result: InferenceResult::default(),
221 table: unify::InferenceTable::new(), 222 table: unify::InferenceTable::new(),
222 obligations: Vec::default(), 223 obligations: Vec::default(),
223 return_ty: Ty::Unknown, // set in collect_fn_signature 224 return_ty: Ty::Unknown, // set in collect_fn_signature
224 trait_env: TraitEnvironment::lower(&ctx), 225 trait_env: TraitEnvironment::lower(db, &resolver),
225 coerce_unsized_map: Self::init_coerce_unsized_map(db, &resolver), 226 coerce_unsized_map: Self::init_coerce_unsized_map(db, &resolver),
226 db, 227 db,
227 owner, 228 owner,
@@ -272,14 +273,26 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
272 self.result.diagnostics.push(diagnostic); 273 self.result.diagnostics.push(diagnostic);
273 } 274 }
274 275
275 fn make_ty(&mut self, type_ref: &TypeRef) -> Ty { 276 fn make_ty_with_mode(
277 &mut self,
278 type_ref: &TypeRef,
279 impl_trait_mode: ImplTraitLoweringMode,
280 ) -> Ty {
276 // FIXME use right resolver for block 281 // FIXME use right resolver for block
277 let ctx = crate::lower::TyLoweringContext { db: self.db, resolver: &self.resolver }; 282 let ctx = crate::lower::TyLoweringContext {
283 db: self.db,
284 resolver: &self.resolver,
285 impl_trait_mode,
286 };
278 let ty = Ty::from_hir(&ctx, type_ref); 287 let ty = Ty::from_hir(&ctx, type_ref);
279 let ty = self.insert_type_vars(ty); 288 let ty = self.insert_type_vars(ty);
280 self.normalize_associated_types_in(ty) 289 self.normalize_associated_types_in(ty)
281 } 290 }
282 291
292 fn make_ty(&mut self, type_ref: &TypeRef) -> Ty {
293 self.make_ty_with_mode(type_ref, ImplTraitLoweringMode::Disallowed)
294 }
295
283 /// Replaces `impl Trait` in `ty` by type variables and obligations for 296 /// Replaces `impl Trait` in `ty` by type variables and obligations for
284 /// those variables. This is done for function arguments when calling a 297 /// those variables. This is done for function arguments when calling a
285 /// function, and for return types when inside the function body, i.e. in 298 /// function, and for return types when inside the function body, i.e. in
@@ -444,7 +457,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
444 None => return (Ty::Unknown, None), 457 None => return (Ty::Unknown, None),
445 }; 458 };
446 let resolver = &self.resolver; 459 let resolver = &self.resolver;
447 let ctx = crate::lower::TyLoweringContext { db: self.db, resolver: &self.resolver }; 460 let ctx = crate::lower::TyLoweringContext {
461 db: self.db,
462 resolver: &self.resolver,
463 impl_trait_mode: ImplTraitLoweringMode::Disallowed,
464 };
448 // FIXME: this should resolve assoc items as well, see this example: 465 // FIXME: this should resolve assoc items as well, see this example:
449 // https://play.rust-lang.org/?gist=087992e9e22495446c01c0d4e2d69521 466 // https://play.rust-lang.org/?gist=087992e9e22495446c01c0d4e2d69521
450 match resolver.resolve_path_in_type_ns_fully(self.db, path.mod_path()) { 467 match resolver.resolve_path_in_type_ns_fully(self.db, path.mod_path()) {
@@ -471,11 +488,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
471 fn collect_fn(&mut self, data: &FunctionData) { 488 fn collect_fn(&mut self, data: &FunctionData) {
472 let body = Arc::clone(&self.body); // avoid borrow checker problem 489 let body = Arc::clone(&self.body); // avoid borrow checker problem
473 for (type_ref, pat) in data.params.iter().zip(body.params.iter()) { 490 for (type_ref, pat) in data.params.iter().zip(body.params.iter()) {
474 let ty = self.make_ty(type_ref); 491 let ty = self.make_ty_with_mode(type_ref, ImplTraitLoweringMode::Opaque);
475 492
476 self.infer_pat(*pat, &ty, BindingMode::default()); 493 self.infer_pat(*pat, &ty, BindingMode::default());
477 } 494 }
478 let return_ty = self.make_ty(&data.ret_type); 495 let return_ty = self.make_ty_with_mode(&data.ret_type, ImplTraitLoweringMode::Placeholder);
479 self.return_ty = self.insert_vars_for_impl_trait(return_ty); 496 self.return_ty = self.insert_vars_for_impl_trait(return_ty);
480 } 497 }
481 498
diff --git a/crates/ra_hir_ty/src/infer/path.rs b/crates/ra_hir_ty/src/infer/path.rs
index 132f3d6f2..02fc99288 100644
--- a/crates/ra_hir_ty/src/infer/path.rs
+++ b/crates/ra_hir_ty/src/infer/path.rs
@@ -9,7 +9,10 @@ use hir_def::{
9}; 9};
10use hir_expand::name::Name; 10use hir_expand::name::Name;
11 11
12use crate::{db::HirDatabase, method_resolution, Substs, Ty, TypeWalk, ValueTyDefId}; 12use crate::{
13 db::HirDatabase, lower::ImplTraitLoweringMode, method_resolution, Substs, Ty, TypeWalk,
14 ValueTyDefId,
15};
13 16
14use super::{ExprOrPatId, InferenceContext, TraitRef}; 17use super::{ExprOrPatId, InferenceContext, TraitRef};
15 18
@@ -39,7 +42,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
39 } 42 }
40 let ty = self.make_ty(type_ref); 43 let ty = self.make_ty(type_ref);
41 let remaining_segments_for_ty = path.segments().take(path.segments().len() - 1); 44 let remaining_segments_for_ty = path.segments().take(path.segments().len() - 1);
42 let ctx = crate::lower::TyLoweringContext { db: self.db, resolver: &resolver }; 45 let ctx = crate::lower::TyLoweringContext {
46 db: self.db,
47 resolver: &resolver,
48 impl_trait_mode: ImplTraitLoweringMode::Disallowed,
49 };
43 let ty = Ty::from_type_relative_path(&ctx, ty, remaining_segments_for_ty); 50 let ty = Ty::from_type_relative_path(&ctx, ty, remaining_segments_for_ty);
44 self.resolve_ty_assoc_item( 51 self.resolve_ty_assoc_item(
45 ty, 52 ty,
@@ -74,7 +81,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
74 if let Some(self_subst) = self_subst { 81 if let Some(self_subst) = self_subst {
75 ty = ty.subst(&self_subst); 82 ty = ty.subst(&self_subst);
76 } 83 }
77 let ctx = crate::lower::TyLoweringContext { db: self.db, resolver: &self.resolver }; 84 let ctx = crate::lower::TyLoweringContext {
85 db: self.db,
86 resolver: &self.resolver,
87 impl_trait_mode: ImplTraitLoweringMode::Disallowed,
88 };
78 let substs = Ty::substs_from_path(&ctx, path, typable); 89 let substs = Ty::substs_from_path(&ctx, path, typable);
79 let ty = ty.subst(&substs); 90 let ty = ty.subst(&substs);
80 Some(ty) 91 Some(ty)
@@ -100,7 +111,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
100 (TypeNs::TraitId(trait_), true) => { 111 (TypeNs::TraitId(trait_), true) => {
101 let segment = 112 let segment =
102 remaining_segments.last().expect("there should be at least one segment here"); 113 remaining_segments.last().expect("there should be at least one segment here");
103 let ctx = crate::lower::TyLoweringContext { db: self.db, resolver: &self.resolver }; 114 let ctx = crate::lower::TyLoweringContext {
115 db: self.db,
116 resolver: &self.resolver,
117 impl_trait_mode: ImplTraitLoweringMode::Disallowed,
118 };
104 let trait_ref = 119 let trait_ref =
105 TraitRef::from_resolved_path(&ctx, trait_.into(), resolved_segment, None); 120 TraitRef::from_resolved_path(&ctx, trait_.into(), resolved_segment, None);
106 self.resolve_trait_assoc_item(trait_ref, segment, id) 121 self.resolve_trait_assoc_item(trait_ref, segment, id)
@@ -112,7 +127,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
112 // as Iterator>::Item::default`) 127 // as Iterator>::Item::default`)
113 let remaining_segments_for_ty = 128 let remaining_segments_for_ty =
114 remaining_segments.take(remaining_segments.len() - 1); 129 remaining_segments.take(remaining_segments.len() - 1);
115 let ctx = crate::lower::TyLoweringContext { db: self.db, resolver: &self.resolver }; 130 let ctx = crate::lower::TyLoweringContext {
131 db: self.db,
132 resolver: &self.resolver,
133 impl_trait_mode: ImplTraitLoweringMode::Disallowed,
134 };
116 let ty = Ty::from_partly_resolved_hir_path( 135 let ty = Ty::from_partly_resolved_hir_path(
117 &ctx, 136 &ctx,
118 def, 137 def,
diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs
index 6f0e8b481..c64b81f98 100644
--- a/crates/ra_hir_ty/src/lib.rs
+++ b/crates/ra_hir_ty/src/lib.rs
@@ -60,7 +60,9 @@ use display::{HirDisplay, HirFormatter};
60pub use autoderef::autoderef; 60pub use autoderef::autoderef;
61pub use infer::{do_infer_query, InferTy, InferenceResult}; 61pub use infer::{do_infer_query, InferTy, InferenceResult};
62pub use lower::CallableDef; 62pub use lower::CallableDef;
63pub use lower::{callable_item_sig, TyDefId, TyLoweringContext, ValueTyDefId}; 63pub use lower::{
64 callable_item_sig, ImplTraitLoweringMode, TyDefId, TyLoweringContext, ValueTyDefId,
65};
64pub use traits::{InEnvironment, Obligation, ProjectionPredicate, TraitEnvironment}; 66pub use traits::{InEnvironment, Obligation, ProjectionPredicate, TraitEnvironment};
65 67
66/// A type constructor or type name: this might be something like the primitive 68/// A type constructor or type name: this might be something like the primitive
diff --git a/crates/ra_hir_ty/src/lower.rs b/crates/ra_hir_ty/src/lower.rs
index 87c984e3f..3d2421223 100644
--- a/crates/ra_hir_ty/src/lower.rs
+++ b/crates/ra_hir_ty/src/lower.rs
@@ -35,6 +35,14 @@ use crate::{
35pub struct TyLoweringContext<'a, DB: HirDatabase> { 35pub struct TyLoweringContext<'a, DB: HirDatabase> {
36 pub db: &'a DB, 36 pub db: &'a DB,
37 pub resolver: &'a Resolver, 37 pub resolver: &'a Resolver,
38 pub impl_trait_mode: ImplTraitLoweringMode,
39}
40
41#[derive(Clone, Debug)]
42pub enum ImplTraitLoweringMode {
43 Opaque,
44 Placeholder,
45 Disallowed,
38} 46}
39 47
40impl Ty { 48impl Ty {
@@ -484,7 +492,11 @@ pub(crate) fn field_types_query(
484 VariantId::EnumVariantId(it) => it.parent.resolver(db), 492 VariantId::EnumVariantId(it) => it.parent.resolver(db),
485 }; 493 };
486 let mut res = ArenaMap::default(); 494 let mut res = ArenaMap::default();
487 let ctx = TyLoweringContext { db, resolver: &resolver }; 495 let ctx = TyLoweringContext {
496 db,
497 resolver: &resolver,
498 impl_trait_mode: ImplTraitLoweringMode::Disallowed,
499 };
488 for (field_id, field_data) in var_data.fields().iter() { 500 for (field_id, field_data) in var_data.fields().iter() {
489 res.insert(field_id, Ty::from_hir(&ctx, &field_data.type_ref)) 501 res.insert(field_id, Ty::from_hir(&ctx, &field_data.type_ref))
490 } 502 }
@@ -505,7 +517,11 @@ pub(crate) fn generic_predicates_for_param_query(
505 param_idx: u32, 517 param_idx: u32,
506) -> Arc<[GenericPredicate]> { 518) -> Arc<[GenericPredicate]> {
507 let resolver = def.resolver(db); 519 let resolver = def.resolver(db);
508 let ctx = TyLoweringContext { db, resolver: &resolver }; 520 let ctx = TyLoweringContext {
521 db,
522 resolver: &resolver,
523 impl_trait_mode: ImplTraitLoweringMode::Disallowed,
524 };
509 resolver 525 resolver
510 .where_predicates_in_scope() 526 .where_predicates_in_scope()
511 // we have to filter out all other predicates *first*, before attempting to lower them 527 // we have to filter out all other predicates *first*, before attempting to lower them
@@ -524,11 +540,12 @@ pub(crate) fn generic_predicates_for_param_recover(
524} 540}
525 541
526impl TraitEnvironment { 542impl TraitEnvironment {
527 pub fn lower(ctx: &TyLoweringContext<'_, impl HirDatabase>) -> Arc<TraitEnvironment> { 543 pub fn lower(db: &impl HirDatabase, resolver: &Resolver) -> Arc<TraitEnvironment> {
528 let predicates = ctx 544 let ctx =
529 .resolver 545 TyLoweringContext { db, resolver, impl_trait_mode: ImplTraitLoweringMode::Disallowed };
546 let predicates = resolver
530 .where_predicates_in_scope() 547 .where_predicates_in_scope()
531 .flat_map(|pred| GenericPredicate::from_where_predicate(ctx, pred)) 548 .flat_map(|pred| GenericPredicate::from_where_predicate(&ctx, pred))
532 .collect::<Vec<_>>(); 549 .collect::<Vec<_>>();
533 550
534 Arc::new(TraitEnvironment { predicates }) 551 Arc::new(TraitEnvironment { predicates })
@@ -541,7 +558,11 @@ pub(crate) fn generic_predicates_query(
541 def: GenericDefId, 558 def: GenericDefId,
542) -> Arc<[GenericPredicate]> { 559) -> Arc<[GenericPredicate]> {
543 let resolver = def.resolver(db); 560 let resolver = def.resolver(db);
544 let ctx = TyLoweringContext { db, resolver: &resolver }; 561 let ctx = TyLoweringContext {
562 db,
563 resolver: &resolver,
564 impl_trait_mode: ImplTraitLoweringMode::Disallowed,
565 };
545 resolver 566 resolver
546 .where_predicates_in_scope() 567 .where_predicates_in_scope()
547 .flat_map(|pred| GenericPredicate::from_where_predicate(&ctx, pred)) 568 .flat_map(|pred| GenericPredicate::from_where_predicate(&ctx, pred))
@@ -551,7 +572,11 @@ pub(crate) fn generic_predicates_query(
551/// Resolve the default type params from generics 572/// Resolve the default type params from generics
552pub(crate) fn generic_defaults_query(db: &impl HirDatabase, def: GenericDefId) -> Substs { 573pub(crate) fn generic_defaults_query(db: &impl HirDatabase, def: GenericDefId) -> Substs {
553 let resolver = def.resolver(db); 574 let resolver = def.resolver(db);
554 let ctx = TyLoweringContext { db, resolver: &resolver }; 575 let ctx = TyLoweringContext {
576 db,
577 resolver: &resolver,
578 impl_trait_mode: ImplTraitLoweringMode::Disallowed,
579 };
555 let generic_params = generics(db, def.into()); 580 let generic_params = generics(db, def.into());
556 581
557 let defaults = generic_params 582 let defaults = generic_params
@@ -565,9 +590,18 @@ pub(crate) fn generic_defaults_query(db: &impl HirDatabase, def: GenericDefId) -
565fn fn_sig_for_fn(db: &impl HirDatabase, def: FunctionId) -> FnSig { 590fn fn_sig_for_fn(db: &impl HirDatabase, def: FunctionId) -> FnSig {
566 let data = db.function_data(def); 591 let data = db.function_data(def);
567 let resolver = def.resolver(db); 592 let resolver = def.resolver(db);
568 let ctx = TyLoweringContext { db, resolver: &resolver }; 593 let ctx_params = TyLoweringContext {
569 let params = data.params.iter().map(|tr| Ty::from_hir(&ctx, tr)).collect::<Vec<_>>(); 594 db,
570 let ret = Ty::from_hir(&ctx, &data.ret_type); 595 resolver: &resolver,
596 impl_trait_mode: ImplTraitLoweringMode::Placeholder,
597 };
598 let params = data.params.iter().map(|tr| Ty::from_hir(&ctx_params, tr)).collect::<Vec<_>>();
599 let ctx_ret = TyLoweringContext {
600 db,
601 resolver: &resolver,
602 impl_trait_mode: ImplTraitLoweringMode::Opaque,
603 };
604 let ret = Ty::from_hir(&ctx_ret, &data.ret_type);
571 FnSig::from_params_and_return(params, ret) 605 FnSig::from_params_and_return(params, ret)
572} 606}
573 607
@@ -583,7 +617,11 @@ fn type_for_fn(db: &impl HirDatabase, def: FunctionId) -> Ty {
583fn type_for_const(db: &impl HirDatabase, def: ConstId) -> Ty { 617fn type_for_const(db: &impl HirDatabase, def: ConstId) -> Ty {
584 let data = db.const_data(def); 618 let data = db.const_data(def);
585 let resolver = def.resolver(db); 619 let resolver = def.resolver(db);
586 let ctx = TyLoweringContext { db, resolver: &resolver }; 620 let ctx = TyLoweringContext {
621 db,
622 resolver: &resolver,
623 impl_trait_mode: ImplTraitLoweringMode::Disallowed,
624 };
587 625
588 Ty::from_hir(&ctx, &data.type_ref) 626 Ty::from_hir(&ctx, &data.type_ref)
589} 627}
@@ -592,7 +630,11 @@ fn type_for_const(db: &impl HirDatabase, def: ConstId) -> Ty {
592fn type_for_static(db: &impl HirDatabase, def: StaticId) -> Ty { 630fn type_for_static(db: &impl HirDatabase, def: StaticId) -> Ty {
593 let data = db.static_data(def); 631 let data = db.static_data(def);
594 let resolver = def.resolver(db); 632 let resolver = def.resolver(db);
595 let ctx = TyLoweringContext { db, resolver: &resolver }; 633 let ctx = TyLoweringContext {
634 db,
635 resolver: &resolver,
636 impl_trait_mode: ImplTraitLoweringMode::Disallowed,
637 };
596 638
597 Ty::from_hir(&ctx, &data.type_ref) 639 Ty::from_hir(&ctx, &data.type_ref)
598} 640}
@@ -612,7 +654,11 @@ fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: StructId) -> FnSig
612 let struct_data = db.struct_data(def.into()); 654 let struct_data = db.struct_data(def.into());
613 let fields = struct_data.variant_data.fields(); 655 let fields = struct_data.variant_data.fields();
614 let resolver = def.resolver(db); 656 let resolver = def.resolver(db);
615 let ctx = TyLoweringContext { db, resolver: &resolver }; 657 let ctx = TyLoweringContext {
658 db,
659 resolver: &resolver,
660 impl_trait_mode: ImplTraitLoweringMode::Disallowed,
661 };
616 let params = 662 let params =
617 fields.iter().map(|(_, field)| Ty::from_hir(&ctx, &field.type_ref)).collect::<Vec<_>>(); 663 fields.iter().map(|(_, field)| Ty::from_hir(&ctx, &field.type_ref)).collect::<Vec<_>>();
618 let ret = type_for_adt(db, def.into()); 664 let ret = type_for_adt(db, def.into());
@@ -635,7 +681,11 @@ fn fn_sig_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariantId
635 let var_data = &enum_data.variants[def.local_id]; 681 let var_data = &enum_data.variants[def.local_id];
636 let fields = var_data.variant_data.fields(); 682 let fields = var_data.variant_data.fields();
637 let resolver = def.parent.resolver(db); 683 let resolver = def.parent.resolver(db);
638 let ctx = TyLoweringContext { db, resolver: &resolver }; 684 let ctx = TyLoweringContext {
685 db,
686 resolver: &resolver,
687 impl_trait_mode: ImplTraitLoweringMode::Disallowed,
688 };
639 let params = 689 let params =
640 fields.iter().map(|(_, field)| Ty::from_hir(&ctx, &field.type_ref)).collect::<Vec<_>>(); 690 fields.iter().map(|(_, field)| Ty::from_hir(&ctx, &field.type_ref)).collect::<Vec<_>>();
641 let generics = generics(db, def.parent.into()); 691 let generics = generics(db, def.parent.into());
@@ -664,7 +714,11 @@ fn type_for_adt(db: &impl HirDatabase, adt: AdtId) -> Ty {
664fn type_for_type_alias(db: &impl HirDatabase, t: TypeAliasId) -> Ty { 714fn type_for_type_alias(db: &impl HirDatabase, t: TypeAliasId) -> Ty {
665 let generics = generics(db, t.into()); 715 let generics = generics(db, t.into());
666 let resolver = t.resolver(db); 716 let resolver = t.resolver(db);
667 let ctx = TyLoweringContext { db, resolver: &resolver }; 717 let ctx = TyLoweringContext {
718 db,
719 resolver: &resolver,
720 impl_trait_mode: ImplTraitLoweringMode::Disallowed,
721 };
668 let type_ref = &db.type_alias_data(t).type_ref; 722 let type_ref = &db.type_alias_data(t).type_ref;
669 let substs = Substs::identity(&generics); 723 let substs = Substs::identity(&generics);
670 let inner = Ty::from_hir(&ctx, type_ref.as_ref().unwrap_or(&TypeRef::Error)); 724 let inner = Ty::from_hir(&ctx, type_ref.as_ref().unwrap_or(&TypeRef::Error));
@@ -747,7 +801,11 @@ pub(crate) fn value_ty_query(db: &impl HirDatabase, def: ValueTyDefId) -> Ty {
747pub(crate) fn impl_self_ty_query(db: &impl HirDatabase, impl_id: ImplId) -> Ty { 801pub(crate) fn impl_self_ty_query(db: &impl HirDatabase, impl_id: ImplId) -> Ty {
748 let impl_data = db.impl_data(impl_id); 802 let impl_data = db.impl_data(impl_id);
749 let resolver = impl_id.resolver(db); 803 let resolver = impl_id.resolver(db);
750 let ctx = TyLoweringContext { db, resolver: &resolver }; 804 let ctx = TyLoweringContext {
805 db,
806 resolver: &resolver,
807 impl_trait_mode: ImplTraitLoweringMode::Disallowed,
808 };
751 Ty::from_hir(&ctx, &impl_data.target_type) 809 Ty::from_hir(&ctx, &impl_data.target_type)
752} 810}
753 811
@@ -762,7 +820,11 @@ pub(crate) fn impl_self_ty_recover(
762pub(crate) fn impl_trait_query(db: &impl HirDatabase, impl_id: ImplId) -> Option<TraitRef> { 820pub(crate) fn impl_trait_query(db: &impl HirDatabase, impl_id: ImplId) -> Option<TraitRef> {
763 let impl_data = db.impl_data(impl_id); 821 let impl_data = db.impl_data(impl_id);
764 let resolver = impl_id.resolver(db); 822 let resolver = impl_id.resolver(db);
765 let ctx = TyLoweringContext { db, resolver: &resolver }; 823 let ctx = TyLoweringContext {
824 db,
825 resolver: &resolver,
826 impl_trait_mode: ImplTraitLoweringMode::Disallowed,
827 };
766 let self_ty = db.impl_self_ty(impl_id); 828 let self_ty = db.impl_self_ty(impl_id);
767 let target_trait = impl_data.target_trait.as_ref()?; 829 let target_trait = impl_data.target_trait.as_ref()?;
768 TraitRef::from_hir(&ctx, target_trait, Some(self_ty.clone())) 830 TraitRef::from_hir(&ctx, target_trait, Some(self_ty.clone()))