Skip to content

Commit e1570fe

Browse files
committed
Check for bound variables when reporting type error
`can_eq` ICEs if it's passed types with escaping bound variables, so we need to check for them, even in error reporting.
1 parent 8365fcb commit e1570fe

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4076,7 +4076,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
40764076
})
40774077
} else if let Some(where_pred) = where_pred.as_projection_clause()
40784078
&& let Some(failed_pred) = failed_pred.as_projection_clause()
4079-
&& let Some(found) = failed_pred.skip_binder().term.as_type()
4079+
&& let Some(failed_pred) = failed_pred.no_bound_vars()
4080+
&& let Some(found) = failed_pred.term.as_type()
40804081
{
40814082
type_diffs = vec![TypeError::Sorts(ty::error::ExpectedFound {
40824083
expected: where_pred
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Regression test for #145631
2+
3+
pub struct Foo {}
4+
5+
fn foo(foos: Vec<Foo>) {
6+
let foos = foos.iter().collect::<Vec<_>>();
7+
let bar = Bar {};
8+
bar.bar(foos);
9+
//~^ ERROR type mismatch resolving `<&Vec<&Foo> as IntoIterator>::Item == &Foo`
10+
}
11+
12+
struct Bar {}
13+
14+
impl Bar {
15+
pub fn bar<I>(&self, iter: I)
16+
where
17+
for<'a> &'a I: IntoIterator<Item = &'a Foo>,
18+
{
19+
}
20+
}
21+
22+
fn main() {}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error[E0271]: type mismatch resolving `<&Vec<&Foo> as IntoIterator>::Item == &Foo`
2+
--> $DIR/mismatched-bound-projection-predicate.rs:8:13
3+
|
4+
LL | bar.bar(foos);
5+
| --- ^^^^ expected `&Foo`, found `&&Foo`
6+
| |
7+
| required by a bound introduced by this call
8+
|
9+
= note: expected reference `&Foo`
10+
found reference `&&Foo`
11+
note: required by a bound in `Bar::bar`
12+
--> $DIR/mismatched-bound-projection-predicate.rs:17:37
13+
|
14+
LL | pub fn bar<I>(&self, iter: I)
15+
| --- required by a bound in this associated function
16+
LL | where
17+
LL | for<'a> &'a I: IntoIterator<Item = &'a Foo>,
18+
| ^^^^^^^^^^^^^^ required by this bound in `Bar::bar`
19+
20+
error: aborting due to 1 previous error
21+
22+
For more information about this error, try `rustc --explain E0271`.

0 commit comments

Comments
 (0)