diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 72b5018589cf8..25cd6a74b6e60 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3106,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); } 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`.