]> git.lizzy.rs Git - rust.git/commitdiff
Test for a Salsa bug
authorFlorian Diebold <flodiebold@gmail.com>
Sat, 20 Mar 2021 14:26:42 +0000 (15:26 +0100)
committerFlorian Diebold <flodiebold@gmail.com>
Sun, 21 Mar 2021 12:33:06 +0000 (13:33 +0100)
crates/hir_ty/src/lib.rs
crates/hir_ty/src/tests.rs
crates/hir_ty/src/tests/traits.rs

index c46529879d075dd44009bff686ba5fb303a86ede..815bb8418a39112538235f8f1e128d4a0b76a957 100644 (file)
@@ -106,6 +106,10 @@ pub fn trait_ref(&self, db: &dyn HirDatabase) -> TraitRef {
         }
     }
 
+    pub fn self_type_parameter(&self) -> &Ty {
+        &self.substitution[0]
+    }
+
     fn trait_(&self, db: &dyn HirDatabase) -> TraitId {
         match from_assoc_type_id(self.associated_ty_id).lookup(db.upcast()).container {
             AssocContainerId::TraitId(it) => it,
index 0a4141e698b44b66be923180755f01913d6e8904..ad283c1e04ba5ca688fe3ac39ace2a75eaf937f8 100644 (file)
@@ -369,3 +369,72 @@ fn check_infer_with_mismatches(ra_fixture: &str, expect: Expect) {
     actual.push('\n');
     expect.assert_eq(&actual);
 }
+
+#[test]
+fn salsa_bug() {
+    let (mut db, pos) = TestDB::with_position(
+        "
+        //- /lib.rs
+        trait Index {
+            type Output;
+        }
+
+        type Key<S: UnificationStoreBase> = <S as UnificationStoreBase>::Key;
+
+        pub trait UnificationStoreBase: Index<Output = Key<Self>> {
+            type Key;
+
+            fn len(&self) -> usize;
+        }
+
+        pub trait UnificationStoreMut: UnificationStoreBase {
+            fn push(&mut self, value: Self::Key);
+        }
+
+        fn main() {
+            let x = 1;
+            x.push(1);$0
+        }
+    ",
+    );
+
+    let module = db.module_for_file(pos.file_id);
+    let crate_def_map = module.def_map(&db);
+    visit_module(&db, &crate_def_map, module.local_id, &mut |def| {
+        db.infer(def);
+    });
+
+    let new_text = "
+        //- /lib.rs
+        trait Index {
+            type Output;
+        }
+
+        type Key<S: UnificationStoreBase> = <S as UnificationStoreBase>::Key;
+
+        pub trait UnificationStoreBase: Index<Output = Key<Self>> {
+            type Key;
+
+            fn len(&self) -> usize;
+        }
+
+        pub trait UnificationStoreMut: UnificationStoreBase {
+            fn push(&mut self, value: Self::Key);
+        }
+
+        fn main() {
+
+            let x = 1;
+            x.push(1);
+        }
+    "
+    .to_string();
+
+    db.set_file_text(pos.file_id, Arc::new(new_text));
+
+    let module = db.module_for_file(pos.file_id);
+    let crate_def_map = module.def_map(&db);
+    visit_module(&db, &crate_def_map, module.local_id, &mut |def| {
+        db.infer(def);
+    });
+}
index 8f2bdffc03fdd2747f759e3888213d42a64cef7b..1bb6dff95e708971f7f8e0f96509cf5bc9e8c1a9 100644 (file)
@@ -2271,6 +2271,57 @@ fn test<T, U>() where T: Trait<U::Item>, U: Trait<T::Item> {
     );
 }
 
+#[test]
+fn unselected_projection_in_trait_env_cycle_3() {
+    // this is a cycle, although it would be possible to handle if we didn't go
+    // into bindings when looking for traits
+    check_types(
+        r#"
+//- /main.rs
+trait Trait {
+    type Item;
+    type OtherItem;
+}
+
+fn test<T>() where T: Trait<OtherItem = T::Item> {
+    let x: T::Item = no_matter;
+}                   //^ {unknown}
+"#,
+    );
+}
+
+#[test]
+fn unselected_projection_in_trait_env_no_cycle() {
+    // this is not a cycle
+    check_types(
+        r#"
+//- /main.rs
+trait Index {
+    type Output;
+}
+
+type Key<S: UnificationStoreBase> = <S as UnificationStoreBase>::Key;
+
+pub trait UnificationStoreBase: Index<Output = Key<Self>> {
+    type Key;
+
+    fn len(&self) -> usize;
+}
+
+pub trait UnificationStoreMut: UnificationStoreBase {
+    fn push(&mut self, value: Self::Key);
+}
+
+fn test<T>(t: T) where T: UnificationStoreMut {
+    let x;
+    t.push(x);
+    let y: Key<T>;
+    (x, y);
+}      //^ (UnificationStoreBase::Key<T>, UnificationStoreBase::Key<T>)
+"#,
+    );
+}
+
 #[test]
 fn inline_assoc_type_bounds_1() {
     check_types(