aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src')
-rw-r--r--crates/ra_hir_ty/src/tests/regression.rs57
-rw-r--r--crates/ra_hir_ty/src/traits/chalk/mapping.rs8
2 files changed, 63 insertions, 2 deletions
diff --git a/crates/ra_hir_ty/src/tests/regression.rs b/crates/ra_hir_ty/src/tests/regression.rs
index d806e0ffb..4367621fc 100644
--- a/crates/ra_hir_ty/src/tests/regression.rs
+++ b/crates/ra_hir_ty/src/tests/regression.rs
@@ -779,3 +779,60 @@ pub trait Service<Request> {
779 "### 779 "###
780 ); 780 );
781} 781}
782
783#[test]
784fn issue_4966() {
785 assert_snapshot!(
786 infer(r#"
787pub trait IntoIterator {
788 type Item;
789}
790
791struct Repeat<A> { element: A }
792
793struct Map<F> { f: F }
794
795struct Vec<T> {}
796
797#[lang = "deref"]
798pub trait Deref {
799 type Target;
800}
801
802impl<T> Deref for Vec<T> {
803 type Target = [T];
804}
805
806fn from_iter<A, T: IntoIterator<Item = A>>(iter: T) -> Vec<A> {}
807
808fn main() {
809 let inner = Map { f: |_: &f64| 0.0 };
810
811 let repeat = Repeat { element: inner };
812
813 let vec = from_iter(repeat);
814
815 vec.foo_bar();
816}
817"#),
818 @r###"
819 270..274 'iter': T
820 289..291 '{}': ()
821 303..447 '{ ...r(); }': ()
822 313..318 'inner': Map<|&f64| -> f64>
823 321..345 'Map { ... 0.0 }': Map<|&f64| -> f64>
824 330..343 '|_: &f64| 0.0': |&f64| -> f64
825 331..332 '_': &f64
826 340..343 '0.0': f64
827 356..362 'repeat': Repeat<Map<|&f64| -> f64>>
828 365..390 'Repeat...nner }': Repeat<Map<|&f64| -> f64>>
829 383..388 'inner': Map<|&f64| -> f64>
830 401..404 'vec': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>>
831 407..416 'from_iter': fn from_iter<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>, Repeat<Map<|&f64| -> f64>>>(Repeat<Map<|&f64| -> f64>>) -> Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>>
832 407..424 'from_i...epeat)': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>>
833 417..423 'repeat': Repeat<Map<|&f64| -> f64>>
834 431..434 'vec': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>>
835 431..444 'vec.foo_bar()': {unknown}
836 "###
837 );
838}
diff --git a/crates/ra_hir_ty/src/traits/chalk/mapping.rs b/crates/ra_hir_ty/src/traits/chalk/mapping.rs
index 7dc9ee759..06453ef82 100644
--- a/crates/ra_hir_ty/src/traits/chalk/mapping.rs
+++ b/crates/ra_hir_ty/src/traits/chalk/mapping.rs
@@ -117,8 +117,12 @@ impl ToChalk for Ty {
117 let parameters = from_chalk(db, opaque_ty.substitution); 117 let parameters = from_chalk(db, opaque_ty.substitution);
118 Ty::Opaque(OpaqueTy { opaque_ty_id: impl_trait_id, parameters }) 118 Ty::Opaque(OpaqueTy { opaque_ty_id: impl_trait_id, parameters })
119 } 119 }
120 chalk_ir::TyData::Function(chalk_ir::Fn { num_binders: _, substitution }) => { 120 chalk_ir::TyData::Function(chalk_ir::Fn { num_binders, substitution }) => {
121 let parameters: Substs = from_chalk(db, substitution); 121 assert_eq!(num_binders, 0);
122 let parameters: Substs = from_chalk(
123 db,
124 substitution.shifted_out(&Interner).expect("fn ptr should have no binders"),
125 );
122 Ty::Apply(ApplicationTy { 126 Ty::Apply(ApplicationTy {
123 ctor: TypeCtor::FnPtr { num_args: (parameters.len() - 1) as u16 }, 127 ctor: TypeCtor::FnPtr { num_args: (parameters.len() - 1) as u16 },
124 parameters, 128 parameters,