Skip to content

Commit 1f7f457

Browse files
committed
Filter out error predicates in type bounds as well
1 parent 4053fcf commit 1f7f457

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

crates/ra_hir_ty/src/tests/traits.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,23 @@ fn test() {
958958
);
959959
}
960960

961+
#[test]
962+
fn error_bound_chalk() {
963+
let t = type_at(
964+
r#"
965+
//- /main.rs
966+
trait Trait {
967+
fn foo(&self) -> u32 {}
968+
}
969+
970+
fn test(x: (impl Trait + UnknownTrait)) {
971+
x.foo()<|>;
972+
}
973+
"#,
974+
);
975+
assert_eq!(t, "u32");
976+
}
977+
961978
#[test]
962979
fn assoc_type_bindings() {
963980
assert_snapshot!(

crates/ra_hir_ty/src/traits/chalk.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,22 @@ impl ToChalk for Ty {
129129
Ty::Bound(idx) => chalk_ir::TyData::BoundVar(idx as usize).intern(),
130130
Ty::Infer(_infer_ty) => panic!("uncanonicalized infer ty"),
131131
Ty::Dyn(predicates) => {
132-
let where_clauses = predicates.iter().cloned().map(|p| p.to_chalk(db)).collect();
132+
let where_clauses = predicates
133+
.iter()
134+
.filter(|p| !p.is_error())
135+
.cloned()
136+
.map(|p| p.to_chalk(db))
137+
.collect();
133138
let bounded_ty = chalk_ir::BoundedTy { bounds: make_binders(where_clauses, 1) };
134139
chalk_ir::TyData::Dyn(bounded_ty).intern()
135140
}
136141
Ty::Opaque(predicates) => {
137-
let where_clauses = predicates.iter().cloned().map(|p| p.to_chalk(db)).collect();
142+
let where_clauses = predicates
143+
.iter()
144+
.filter(|p| !p.is_error())
145+
.cloned()
146+
.map(|p| p.to_chalk(db))
147+
.collect();
138148
let bounded_ty = chalk_ir::BoundedTy { bounds: make_binders(where_clauses, 1) };
139149
chalk_ir::TyData::Opaque(bounded_ty).intern()
140150
}

0 commit comments

Comments
 (0)