]> git.lizzy.rs Git - rust.git/commitdiff
Filter out error predicates in type bounds as well
authorFlorian Diebold <flodiebold@gmail.com>
Sat, 21 Dec 2019 18:15:06 +0000 (19:15 +0100)
committerFlorian Diebold <flodiebold@gmail.com>
Sun, 22 Dec 2019 23:08:03 +0000 (00:08 +0100)
crates/ra_hir_ty/src/tests/traits.rs
crates/ra_hir_ty/src/traits/chalk.rs

index 76e2198b6638474966767518cdd6b730047f6816..ae316922bdea8a3df540c06642e0b4c48ca82544 100644 (file)
@@ -958,6 +958,23 @@ fn test() {
     );
 }
 
+#[test]
+fn error_bound_chalk() {
+    let t = type_at(
+        r#"
+//- /main.rs
+trait Trait {
+    fn foo(&self) -> u32 {}
+}
+
+fn test(x: (impl Trait + UnknownTrait)) {
+    x.foo()<|>;
+}
+"#,
+    );
+    assert_eq!(t, "u32");
+}
+
 #[test]
 fn assoc_type_bindings() {
     assert_snapshot!(
index 9e38337e560c44641a7a1907b5994c5c4a0caac6..555930c9bfa12afbdec21d679f39bc63b42ed8c4 100644 (file)
@@ -129,12 +129,22 @@ fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::Ty<TypeFamily> {
             Ty::Bound(idx) => chalk_ir::TyData::BoundVar(idx as usize).intern(),
             Ty::Infer(_infer_ty) => panic!("uncanonicalized infer ty"),
             Ty::Dyn(predicates) => {
-                let where_clauses = predicates.iter().cloned().map(|p| p.to_chalk(db)).collect();
+                let where_clauses = predicates
+                    .iter()
+                    .filter(|p| !p.is_error())
+                    .cloned()
+                    .map(|p| p.to_chalk(db))
+                    .collect();
                 let bounded_ty = chalk_ir::BoundedTy { bounds: make_binders(where_clauses, 1) };
                 chalk_ir::TyData::Dyn(bounded_ty).intern()
             }
             Ty::Opaque(predicates) => {
-                let where_clauses = predicates.iter().cloned().map(|p| p.to_chalk(db)).collect();
+                let where_clauses = predicates
+                    .iter()
+                    .filter(|p| !p.is_error())
+                    .cloned()
+                    .map(|p| p.to_chalk(db))
+                    .collect();
                 let bounded_ty = chalk_ir::BoundedTy { bounds: make_binders(where_clauses, 1) };
                 chalk_ir::TyData::Opaque(bounded_ty).intern()
             }