From f93cbedadec03e5d4d6733e0756d87b6eb706a4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 6 Aug 2021 02:36:54 -0700 Subject: [PATCH] Do not ICE on HIR based WF check when involving lifetimes Fix #87549. --- .../src/traits/error_reporting/mod.rs | 7 +++-- src/test/ui/wf/hir-wf-check-erase-regions.rs | 14 +++++++++ .../ui/wf/hir-wf-check-erase-regions.stderr | 31 +++++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 src/test/ui/wf/hir-wf-check-erase-regions.rs create mode 100644 src/test/ui/wf/hir-wf-check-erase-regions.stderr diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 3f713ce3c3914..ac07cc1f03439 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -245,9 +245,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { if let ObligationCauseCode::WellFormed(Some(wf_loc)) = root_obligation.cause.code.peel_derives() { - if let Some(cause) = - self.tcx.diagnostic_hir_wf_check((obligation.predicate, wf_loc.clone())) - { + if let Some(cause) = self.tcx.diagnostic_hir_wf_check(( + tcx.erase_regions(obligation.predicate), + wf_loc.clone(), + )) { obligation.cause = cause; span = obligation.cause.span; } diff --git a/src/test/ui/wf/hir-wf-check-erase-regions.rs b/src/test/ui/wf/hir-wf-check-erase-regions.rs new file mode 100644 index 0000000000000..bb398e5698a80 --- /dev/null +++ b/src/test/ui/wf/hir-wf-check-erase-regions.rs @@ -0,0 +1,14 @@ +// Regression test for #87549. +// compile-flags: -C incremental=tmp/wf/hir-wf-check-erase-regions + +pub struct Table([Option; N]); + +impl<'a, T, const N: usize> IntoIterator for &'a Table { + type IntoIter = std::iter::Flatten>; //~ ERROR `&T` is not an iterator + type Item = &'a T; + + fn into_iter(self) -> Self::IntoIter { //~ ERROR `&T` is not an iterator + unimplemented!() + } +} +fn main() {} diff --git a/src/test/ui/wf/hir-wf-check-erase-regions.stderr b/src/test/ui/wf/hir-wf-check-erase-regions.stderr new file mode 100644 index 0000000000000..a704754e82a92 --- /dev/null +++ b/src/test/ui/wf/hir-wf-check-erase-regions.stderr @@ -0,0 +1,31 @@ +error[E0277]: `&T` is not an iterator + --> $DIR/hir-wf-check-erase-regions.rs:7:5 + | +LL | type IntoIter = std::iter::Flatten>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `&T` is not an iterator + | + ::: $SRC_DIR/core/src/iter/adapters/flatten.rs:LL:COL + | +LL | pub struct Flatten> { + | ------------ required by this bound in `Flatten` + | + = help: the trait `Iterator` is not implemented for `&T` + = note: required because of the requirements on the impl of `IntoIterator` for `&T` + +error[E0277]: `&T` is not an iterator + --> $DIR/hir-wf-check-erase-regions.rs:10:27 + | +LL | fn into_iter(self) -> Self::IntoIter { + | ^^^^^^^^^^^^^^ `&T` is not an iterator + | + ::: $SRC_DIR/core/src/iter/adapters/flatten.rs:LL:COL + | +LL | pub struct Flatten> { + | ------------ required by this bound in `Flatten` + | + = help: the trait `Iterator` is not implemented for `&T` + = note: required because of the requirements on the impl of `IntoIterator` for `&T` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`.