Skip to content

Commit 5709f22

Browse files
authored
Rollup merge of rust-lang#87811 - estebank:issue-87549, r=oli-obk
Do not ICE on HIR based WF check when involving lifetimes Fix rust-lang#87549.
2 parents c9f68d2 + f93cbed commit 5709f22

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
245245
if let ObligationCauseCode::WellFormed(Some(wf_loc)) =
246246
root_obligation.cause.code.peel_derives()
247247
{
248-
if let Some(cause) =
249-
self.tcx.diagnostic_hir_wf_check((obligation.predicate, wf_loc.clone()))
250-
{
248+
if let Some(cause) = self.tcx.diagnostic_hir_wf_check((
249+
tcx.erase_regions(obligation.predicate),
250+
wf_loc.clone(),
251+
)) {
251252
obligation.cause = cause;
252253
span = obligation.cause.span;
253254
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Regression test for #87549.
2+
// compile-flags: -C incremental=tmp/wf/hir-wf-check-erase-regions
3+
4+
pub struct Table<T, const N: usize>([Option<T>; N]);
5+
6+
impl<'a, T, const N: usize> IntoIterator for &'a Table<T, N> {
7+
type IntoIter = std::iter::Flatten<std::slice::Iter<'a, T>>; //~ ERROR `&T` is not an iterator
8+
type Item = &'a T;
9+
10+
fn into_iter(self) -> Self::IntoIter { //~ ERROR `&T` is not an iterator
11+
unimplemented!()
12+
}
13+
}
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
error[E0277]: `&T` is not an iterator
2+
--> $DIR/hir-wf-check-erase-regions.rs:7:5
3+
|
4+
LL | type IntoIter = std::iter::Flatten<std::slice::Iter<'a, T>>;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `&T` is not an iterator
6+
|
7+
::: $SRC_DIR/core/src/iter/adapters/flatten.rs:LL:COL
8+
|
9+
LL | pub struct Flatten<I: Iterator<Item: IntoIterator>> {
10+
| ------------ required by this bound in `Flatten`
11+
|
12+
= help: the trait `Iterator` is not implemented for `&T`
13+
= note: required because of the requirements on the impl of `IntoIterator` for `&T`
14+
15+
error[E0277]: `&T` is not an iterator
16+
--> $DIR/hir-wf-check-erase-regions.rs:10:27
17+
|
18+
LL | fn into_iter(self) -> Self::IntoIter {
19+
| ^^^^^^^^^^^^^^ `&T` is not an iterator
20+
|
21+
::: $SRC_DIR/core/src/iter/adapters/flatten.rs:LL:COL
22+
|
23+
LL | pub struct Flatten<I: Iterator<Item: IntoIterator>> {
24+
| ------------ required by this bound in `Flatten`
25+
|
26+
= help: the trait `Iterator` is not implemented for `&T`
27+
= note: required because of the requirements on the impl of `IntoIterator` for `&T`
28+
29+
error: aborting due to 2 previous errors
30+
31+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)