From bc1bd95e5a63643cfbbe1d84b2560117644bf8f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 13 Nov 2019 14:28:15 -0800 Subject: [PATCH 1/2] Do not ICE on recovery from unmet associated type bound obligation --- src/librustc_typeck/check/mod.rs | 11 ++++++++--- src/test/ui/issues/issue-66353.rs | 15 +++++++++++++++ src/test/ui/issues/issue-66353.stderr | 18 ++++++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 src/test/ui/issues/issue-66353.rs create mode 100644 src/test/ui/issues/issue-66353.stderr diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 72b5018589cf8..be56157287c57 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -705,9 +705,14 @@ impl Inherited<'a, 'tcx> { span_bug!(obligation.cause.span, "escaping bound vars in predicate {:?}", obligation); } - self.fulfillment_cx - .borrow_mut() - .register_predicate_obligation(self, obligation); + let _ = self.fulfillment_cx + .try_borrow_mut() + .map_err(|e| self.tcx.sess.delay_span_bug(obligation.cause.span, &format!( + "fullfillment context already borrowed: {:?} - {:?}", + e, + obligation, + ))) + .map(|mut cx| cx.register_predicate_obligation(self, obligation)); } fn register_predicates(&self, obligations: I) diff --git a/src/test/ui/issues/issue-66353.rs b/src/test/ui/issues/issue-66353.rs new file mode 100644 index 0000000000000..d8abdd5206ef4 --- /dev/null +++ b/src/test/ui/issues/issue-66353.rs @@ -0,0 +1,15 @@ +// #66353: ICE when trying to recover from incorrect associated type + +trait _Func { + fn func(_: Self); +} + +trait _A { + type AssocT; +} + +fn main() { + _Func::< <() as _A>::AssocT >::func(()); + //~^ ERROR the trait bound `(): _A` is not satisfied + //~| ERROR the trait bound `(): _Func<_>` is not satisfied +} diff --git a/src/test/ui/issues/issue-66353.stderr b/src/test/ui/issues/issue-66353.stderr new file mode 100644 index 0000000000000..8fd50300ca63e --- /dev/null +++ b/src/test/ui/issues/issue-66353.stderr @@ -0,0 +1,18 @@ +error[E0277]: the trait bound `(): _A` is not satisfied + --> $DIR/issue-66353.rs:12:14 + | +LL | _Func::< <() as _A>::AssocT >::func(()); + | ^^^^^^^^^^^^^^^^^^ the trait `_A` is not implemented for `()` + +error[E0277]: the trait bound `(): _Func<_>` is not satisfied + --> $DIR/issue-66353.rs:12:41 + | +LL | fn func(_: Self); + | ----------------- required by `_Func::func` +... +LL | _Func::< <() as _A>::AssocT >::func(()); + | ^^ the trait `_Func<_>` is not implemented for `()` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`. From b884205cf451463c9b0bda6e694831c1494e28d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 14 Nov 2019 11:34:46 -0800 Subject: [PATCH 2/2] review comments --- src/librustc_typeck/check/mod.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index be56157287c57..25cd6a74b6e60 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -705,14 +705,9 @@ impl Inherited<'a, 'tcx> { span_bug!(obligation.cause.span, "escaping bound vars in predicate {:?}", obligation); } - let _ = self.fulfillment_cx - .try_borrow_mut() - .map_err(|e| self.tcx.sess.delay_span_bug(obligation.cause.span, &format!( - "fullfillment context already borrowed: {:?} - {:?}", - e, - obligation, - ))) - .map(|mut cx| cx.register_predicate_obligation(self, obligation)); + self.fulfillment_cx + .borrow_mut() + .register_predicate_obligation(self, obligation); } fn register_predicates(&self, obligations: I) @@ -3111,7 +3106,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fallback_has_occurred: bool, mutate_fullfillment_errors: impl Fn(&mut Vec>), ) { - if let Err(mut errors) = self.fulfillment_cx.borrow_mut().select_where_possible(self) { + let result = self.fulfillment_cx.borrow_mut().select_where_possible(self); + if let Err(mut errors) = result { mutate_fullfillment_errors(&mut errors); self.report_fulfillment_errors(&errors, self.inh.body_id, fallback_has_occurred); }