From 6787f124b5557120cd1e4557cbdb59aa7f215be6 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 7 Feb 2020 15:13:00 +0100 Subject: Clean up RPIT a bit --- crates/ra_hir_ty/src/infer.rs | 28 ++-------------------------- crates/ra_hir_ty/src/infer/expr.rs | 1 - crates/ra_hir_ty/src/marks.rs | 1 - crates/ra_hir_ty/src/tests/traits.rs | 24 +++++++++++------------- 4 files changed, 13 insertions(+), 41 deletions(-) (limited to 'crates/ra_hir_ty/src') diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs index 8d5b7c943..dec6bd84c 100644 --- a/crates/ra_hir_ty/src/infer.rs +++ b/crates/ra_hir_ty/src/infer.rs @@ -34,7 +34,6 @@ use hir_expand::{diagnostics::DiagnosticSink, name::name}; use ra_arena::map::ArenaMap; use ra_prof::profile; use ra_syntax::SmolStr; -use test_utils::tested_by; use super::{ primitive::{FloatTy, IntTy}, @@ -289,29 +288,6 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { self.make_ty_with_mode(type_ref, ImplTraitLoweringMode::Disallowed) } - /// Replaces `impl Trait` in `ty` by type variables and obligations for - /// those variables. This is done for function arguments when calling a - /// function, and for return types when inside the function body, i.e. in - /// the cases where the `impl Trait` is 'transparent'. In other cases, `impl - /// Trait` is represented by `Ty::Opaque`. - fn insert_vars_for_impl_trait(&mut self, ty: Ty) -> Ty { - ty.fold(&mut |ty| match ty { - Ty::Opaque(preds) => { - tested_by!(insert_vars_for_impl_trait); - let var = self.table.new_type_var(); - let var_subst = Substs::builder(1).push(var.clone()).build(); - self.obligations.extend( - preds - .iter() - .map(|pred| pred.clone().subst_bound_vars(&var_subst)) - .filter_map(Obligation::from_predicate), - ); - var - } - _ => ty, - }) - } - /// Replaces Ty::Unknown by a new type var, so we can maybe still infer it. fn insert_type_vars_shallow(&mut self, ty: Ty) -> Ty { match ty { @@ -487,8 +463,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { self.infer_pat(*pat, &ty, BindingMode::default()); } - let return_ty = self.make_ty_with_mode(&data.ret_type, ImplTraitLoweringMode::Variable); - self.return_ty = self.insert_vars_for_impl_trait(return_ty); + let return_ty = self.make_ty_with_mode(&data.ret_type, ImplTraitLoweringMode::Disallowed); // FIXME implement RPIT + self.return_ty = return_ty; } fn infer_body(&mut self) { diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index b69785e55..6222bd90e 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs @@ -635,7 +635,6 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { continue; } - let param_ty = self.insert_vars_for_impl_trait(param_ty); let param_ty = self.normalize_associated_types_in(param_ty); self.infer_expr_coerce(arg, &Expectation::has_type(param_ty.clone())); } diff --git a/crates/ra_hir_ty/src/marks.rs b/crates/ra_hir_ty/src/marks.rs index fe74acf11..0f754eb9c 100644 --- a/crates/ra_hir_ty/src/marks.rs +++ b/crates/ra_hir_ty/src/marks.rs @@ -6,5 +6,4 @@ test_utils::marks!( type_var_resolves_to_int_var match_ergonomics_ref coerce_merge_fail_fallback - insert_vars_for_impl_trait ); diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index bae5eae07..134cea8d8 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs @@ -1,7 +1,6 @@ use insta::assert_snapshot; use ra_db::fixture::WithFixture; -use test_utils::covers; use super::{infer, infer_with_mismatches, type_at, type_at_pos}; use crate::test_db::TestDB; @@ -1650,7 +1649,6 @@ fn test() where T: Trait, U: Trait { #[test] fn unify_impl_trait() { - covers!(insert_vars_for_impl_trait); assert_snapshot!( infer_with_mismatches(r#" trait Trait {} @@ -1682,26 +1680,26 @@ fn test() -> impl Trait { [172; 183) '{ loop {} }': T [174; 181) 'loop {}': ! [179; 181) '{}': () - [214; 310) '{ ...t()) }': S + [214; 310) '{ ...t()) }': S<{unknown}> [224; 226) 's1': S - [229; 230) 'S': S(T) -> S + [229; 230) 'S': S(u32) -> S [229; 241) 'S(default())': S - [231; 238) 'default': fn default() -> T + [231; 238) 'default': fn default() -> u32 [231; 240) 'default()': u32 - [247; 250) 'foo': fn foo(impl Trait) -> () + [247; 250) 'foo': fn foo>(S) -> () [247; 254) 'foo(s1)': () [251; 253) 's1': S [264; 265) 'x': i32 - [273; 276) 'bar': fn bar(impl Trait) -> T + [273; 276) 'bar': fn bar>(S) -> i32 [273; 290) 'bar(S(...lt()))': i32 - [277; 278) 'S': S(T) -> S + [277; 278) 'S': S(i32) -> S [277; 289) 'S(default())': S - [279; 286) 'default': fn default() -> T + [279; 286) 'default': fn default() -> i32 [279; 288) 'default()': i32 - [296; 297) 'S': S(T) -> S - [296; 308) 'S(default())': S - [298; 305) 'default': fn default() -> T - [298; 307) 'default()': i32 + [296; 297) 'S': S<{unknown}>({unknown}) -> S<{unknown}> + [296; 308) 'S(default())': S<{unknown}> + [298; 305) 'default': fn default<{unknown}>() -> {unknown} + [298; 307) 'default()': {unknown} "### ); } -- cgit v1.2.3