Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not ICE on HIR based WF check when involving lifetimes #87811

Merged
merged 1 commit into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
14 changes: 14 additions & 0 deletions src/test/ui/wf/hir-wf-check-erase-regions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Regression test for #87549.
estebank marked this conversation as resolved.
Show resolved Hide resolved
// compile-flags: -C incremental=tmp/wf/hir-wf-check-erase-regions

pub struct Table<T, const N: usize>([Option<T>; N]);

impl<'a, T, const N: usize> IntoIterator for &'a Table<T, N> {
type IntoIter = std::iter::Flatten<std::slice::Iter<'a, T>>; //~ 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() {}
31 changes: 31 additions & 0 deletions src/test/ui/wf/hir-wf-check-erase-regions.stderr
Original file line number Diff line number Diff line change
@@ -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<std::slice::Iter<'a, T>>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `&T` is not an iterator
|
::: $SRC_DIR/core/src/iter/adapters/flatten.rs:LL:COL
|
LL | pub struct Flatten<I: Iterator<Item: IntoIterator>> {
| ------------ 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<I: Iterator<Item: IntoIterator>> {
| ------------ 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`.