Skip to content

Commit bc1bd95

Browse files
committed
Do not ICE on recovery from unmet associated type bound obligation
1 parent 695fe96 commit bc1bd95

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

src/librustc_typeck/check/mod.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -705,9 +705,14 @@ impl Inherited<'a, 'tcx> {
705705
span_bug!(obligation.cause.span, "escaping bound vars in predicate {:?}",
706706
obligation);
707707
}
708-
self.fulfillment_cx
709-
.borrow_mut()
710-
.register_predicate_obligation(self, obligation);
708+
let _ = self.fulfillment_cx
709+
.try_borrow_mut()
710+
.map_err(|e| self.tcx.sess.delay_span_bug(obligation.cause.span, &format!(
711+
"fullfillment context already borrowed: {:?} - {:?}",
712+
e,
713+
obligation,
714+
)))
715+
.map(|mut cx| cx.register_predicate_obligation(self, obligation));
711716
}
712717

713718
fn register_predicates<I>(&self, obligations: I)

src/test/ui/issues/issue-66353.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// #66353: ICE when trying to recover from incorrect associated type
2+
3+
trait _Func<T> {
4+
fn func(_: Self);
5+
}
6+
7+
trait _A {
8+
type AssocT;
9+
}
10+
11+
fn main() {
12+
_Func::< <() as _A>::AssocT >::func(());
13+
//~^ ERROR the trait bound `(): _A` is not satisfied
14+
//~| ERROR the trait bound `(): _Func<_>` is not satisfied
15+
}

src/test/ui/issues/issue-66353.stderr

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0277]: the trait bound `(): _A` is not satisfied
2+
--> $DIR/issue-66353.rs:12:14
3+
|
4+
LL | _Func::< <() as _A>::AssocT >::func(());
5+
| ^^^^^^^^^^^^^^^^^^ the trait `_A` is not implemented for `()`
6+
7+
error[E0277]: the trait bound `(): _Func<_>` is not satisfied
8+
--> $DIR/issue-66353.rs:12:41
9+
|
10+
LL | fn func(_: Self);
11+
| ----------------- required by `_Func::func`
12+
...
13+
LL | _Func::< <() as _A>::AssocT >::func(());
14+
| ^^ the trait `_Func<_>` is not implemented for `()`
15+
16+
error: aborting due to 2 previous errors
17+
18+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)