Skip to content

Commit 1ea8496

Browse files
authored
Rollup merge of #101022 - compiler-errors:issue-101020, r=jackh726
Erase late bound regions before comparing types in `suggest_dereferences` Fixes #101020
2 parents aa9bfde + 48b3d8a commit 1ea8496

File tree

4 files changed

+74
-5
lines changed

4 files changed

+74
-5
lines changed

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -2725,7 +2725,10 @@ impl<'tcx> TypeRelation<'tcx> for SameTypeModuloInfer<'_, 'tcx> {
27252725
a: ty::Region<'tcx>,
27262726
b: ty::Region<'tcx>,
27272727
) -> RelateResult<'tcx, ty::Region<'tcx>> {
2728-
if (a.is_var() && b.is_free_or_static()) || (b.is_var() && a.is_free_or_static()) || a == b
2728+
if (a.is_var() && b.is_free_or_static())
2729+
|| (b.is_var() && a.is_free_or_static())
2730+
|| (a.is_var() && b.is_var())
2731+
|| a == b
27292732
{
27302733
Ok(a)
27312734
} else {

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -690,13 +690,17 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
690690
real_trait_pred = parent_trait_pred;
691691
}
692692

693-
// Skipping binder here, remapping below
694-
let real_ty = real_trait_pred.self_ty().skip_binder();
695-
if self.can_eq(obligation.param_env, real_ty, arg_ty).is_err() {
693+
let real_ty = real_trait_pred.self_ty();
694+
// We `erase_late_bound_regions` here because `make_subregion` does not handle
695+
// `ReLateBound`, and we don't particularly care about the regions.
696+
if self
697+
.can_eq(obligation.param_env, self.tcx.erase_late_bound_regions(real_ty), arg_ty)
698+
.is_err()
699+
{
696700
continue;
697701
}
698702

699-
if let ty::Ref(region, base_ty, mutbl) = *real_ty.kind() {
703+
if let ty::Ref(region, base_ty, mutbl) = *real_ty.skip_binder().kind() {
700704
let mut autoderef = Autoderef::new(
701705
self,
702706
obligation.param_env,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#![feature(generic_associated_types)]
2+
3+
pub trait LendingIterator {
4+
type Item<'a>
5+
where
6+
Self: 'a;
7+
8+
fn consume<F>(self, _f: F)
9+
where
10+
Self: Sized,
11+
for<'a> Self::Item<'a>: FuncInput<'a, Self::Item<'a>>,
12+
{
13+
}
14+
}
15+
16+
impl<I: LendingIterator + ?Sized> LendingIterator for &mut I {
17+
type Item<'a> = I::Item<'a> where Self: 'a;
18+
}
19+
struct EmptyIter;
20+
impl LendingIterator for EmptyIter {
21+
type Item<'a> = &'a mut () where Self:'a;
22+
}
23+
pub trait FuncInput<'a, F>
24+
where
25+
F: Foo<Self>,
26+
Self: Sized,
27+
{
28+
}
29+
impl<'a, T, F: 'a> FuncInput<'a, F> for T where F: Foo<T> {}
30+
trait Foo<T> {}
31+
32+
fn map_test() {
33+
(&mut EmptyIter).consume(());
34+
//~^ ERROR the trait bound `for<'a> &'a mut (): Foo<&'a mut ()>` is not satisfied
35+
}
36+
37+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error[E0277]: the trait bound `for<'a> &'a mut (): Foo<&'a mut ()>` is not satisfied
2+
--> $DIR/issue-101020.rs:33:5
3+
|
4+
LL | (&mut EmptyIter).consume(());
5+
| ^^^^^^^^^^^^^^^^ ------- required by a bound introduced by this call
6+
| |
7+
| the trait `for<'a> Foo<&'a mut ()>` is not implemented for `&'a mut ()`
8+
|
9+
note: required for `&'a mut ()` to implement `for<'a> FuncInput<'a, &'a mut ()>`
10+
--> $DIR/issue-101020.rs:29:20
11+
|
12+
LL | impl<'a, T, F: 'a> FuncInput<'a, F> for T where F: Foo<T> {}
13+
| ^^^^^^^^^^^^^^^^ ^
14+
note: required by a bound in `LendingIterator::consume`
15+
--> $DIR/issue-101020.rs:11:33
16+
|
17+
LL | fn consume<F>(self, _f: F)
18+
| ------- required by a bound in this
19+
...
20+
LL | for<'a> Self::Item<'a>: FuncInput<'a, Self::Item<'a>>,
21+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `LendingIterator::consume`
22+
23+
error: aborting due to previous error
24+
25+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)