Repository: rust-analyzer/rust-analyzer
Pull request #9065 (2021-05-30 16:39:14)

hir_ty: don't pass where clauses of associated types down to chalk
See #9052.

flodiebold: bors d+
bors[bot]: :v: cynecx can now approve this pull request. To approve and merge a pull request, simply reply with `bors r+`. More detailed instructions are available [here](https://bors.tech/documentation/getting-started/#reviewing-pull-requests).

Patch:
diff --git a/crates/hir_ty/src/chalk_db.rs b/crates/hir_ty/src/chalk_db.rs
index b108fd559c..4e042bf422 100644
--- a/crates/hir_ty/src/chalk_db.rs
+++ b/crates/hir_ty/src/chalk_db.rs
@@ -383,7 +383,7 @@ pub(crate) fn associated_ty_data_query(
     // Lower bounds -- we could/should maybe move this to a separate query in `lower`
     let type_alias_data = db.type_alias_data(type_alias);
     let generic_params = generics(db.upcast(), type_alias.into());
-    let bound_vars = generic_params.bound_vars_subst(DebruijnIndex::INNERMOST);
+    // let bound_vars = generic_params.bound_vars_subst(DebruijnIndex::INNERMOST);
     let resolver = hir_def::resolver::HasResolver::resolver(type_alias, db.upcast());
     let ctx = crate::TyLoweringContext::new(db, &resolver)
         .with_type_param_mode(crate::lower::TypeParamLoweringMode::Variable);
@@ -396,8 +396,10 @@ pub(crate) fn associated_ty_data_query(
         .filter_map(|pred| generic_predicate_to_inline_bound(db, &pred, &self_ty))
         .collect();
 
-    let where_clauses = convert_where_clauses(db, type_alias.into(), &bound_vars);
-    let bound_data = rust_ir::AssociatedTyDatumBound { bounds, where_clauses };
+    // FIXME: Re-enable where clauses on associated types when an upstream chalk bug is fixed.
+    //        (rust-analyzer#9052)
+    // let where_clauses = convert_where_clauses(db, type_alias.into(), &bound_vars);
+    let bound_data = rust_ir::AssociatedTyDatumBound { bounds, where_clauses: vec![] };
     let datum = AssociatedTyDatum {
         trait_id: to_chalk_trait_id(trait_),
         id,


Test patch:
diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs
index 7c0ff2170f..49add4ab99 100644
--- a/crates/hir_ty/src/tests/traits.rs
+++ b/crates/hir_ty/src/tests/traits.rs
@@ -161,7 +161,7 @@ mod result {
 }
 
 #[test]
-fn infer_tryv2() {
+fn infer_try_trait_v2() {
     check_types(
         r#"
 //- /main.rs crate:main deps:core
@@ -172,26 +172,41 @@ fn test() {
 } //^ i32
 
 //- /core.rs crate:core
-#[prelude_import] use ops::*;
 mod ops {
-    trait Try {
-        type Output;
-        type Residual;
+    mod try_trait {
+        pub trait Try: FromResidual {
+            type Output;
+            type Residual;
+        }
+        pub trait FromResidual<R = <Self as Try>::Residual> {}
     }
+
+    pub use self::try_trait::FromResidual;
+    pub use self::try_trait::Try;
+}
+
+mov convert {
+    pub trait From<T> {}
+    impl<T> From<T> for T {}
 }
 
 #[prelude_import] use result::*;
 mod result {
-    enum Infallible {}
-    enum Result<O, E> {
+    use crate::convert::From;
+    use crate::ops::{Try, FromResidual};
+
+    pub enum Infallible {}
+    pub enum Result<O, E> {
         Ok(O),
         Err(E)
     }
 
-    impl<O, E> crate::ops::Try for Result<O, E> {
+    impl<O, E> Try for Result<O, E> {
         type Output = O;
         type Error = Result<Infallible, E>;
     }
+
+    impl<T, E, F: From<E>> FromResidual<Result<Infallible, E>> for Result<T, F> {}
 }
 "#,
     );