From dbfc68cea05c82d5bd7f8ee4f1cec4b173517eb4 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 23 Mar 2019 18:03:09 +0100 Subject: Fix apply_substs assertion failure Fixes #1030. --- crates/ra_hir/src/ty/infer.rs | 4 ++-- crates/ra_hir/src/ty/tests.rs | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 132ee0ca2..cff7e7481 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -407,7 +407,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let substs = Ty::substs_from_path_segment(self.db, &self.resolver, segment, typable); - self.db.type_for_def(typable, Namespace::Types).apply_substs(substs) + self.db.type_for_def(typable, Namespace::Types).subst(&substs) } Resolution::LocalBinding(_) => { // can't have a local binding in an associated item path @@ -466,7 +466,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let typable: Option = def.into(); let typable = typable?; let substs = Ty::substs_from_path(self.db, &self.resolver, path, typable); - let ty = self.db.type_for_def(typable, Namespace::Values).apply_substs(substs); + let ty = self.db.type_for_def(typable, Namespace::Values).subst(&substs); let ty = self.insert_type_vars(ty); Some(ty) } diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 0f2172ddf..5d8ad4aa7 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs @@ -1791,6 +1791,29 @@ fn test(query_response: Canonical>) { ); } +#[test] +fn bug_1030() { + assert_snapshot_matches!(infer(r#" +struct HashSet; +struct FxHasher; +type FxHashSet = HashSet; + +impl HashSet { + fn default() -> HashSet {} +} + +pub fn main_loop() { + FxHashSet::default(); +} +"#), + @r###" +[144; 146) '{}': () +[169; 198) '{ ...t(); }': () +[175; 193) 'FxHash...efault': fn default<{unknown}, {unknown}>() -> HashSet +[175; 195) 'FxHash...ault()': HashSet<{unknown}, {unknown}>"### + ); +} + #[test] fn cross_crate_associated_method_call() { let (mut db, pos) = MockDatabase::with_position( -- cgit v1.2.3