Skip to content

Commit 8c215e7

Browse files
committed
fix diagnostic regresssion
1 parent 9f7d0e9 commit 8c215e7

File tree

4 files changed

+21
-32
lines changed

4 files changed

+21
-32
lines changed

Diff for: compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -408,30 +408,35 @@ fn try_extract_error_from_region_constraints<'tcx>(
408408
mut region_var_origin: impl FnMut(RegionVid) -> RegionVariableOrigin,
409409
mut universe_of_region: impl FnMut(RegionVid) -> UniverseIndex,
410410
) -> Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>> {
411+
let placeholder_universe = match placeholder_region.kind() {
412+
ty::RePlaceholder(p) => p.universe,
413+
ty::ReVar(vid) => universe_of_region(vid),
414+
_ => ty::UniverseIndex::ROOT,
415+
};
411416
let matches =
412417
|a_region: Region<'tcx>, b_region: Region<'tcx>| match (a_region.kind(), b_region.kind()) {
413418
(RePlaceholder(a_p), RePlaceholder(b_p)) => a_p.bound == b_p.bound,
414419
_ => a_region == b_region,
415420
};
416-
let check = |constraint: &Constraint<'tcx>, cause: &SubregionOrigin<'tcx>, exact| {
417-
match *constraint {
421+
let mut check =
422+
|constraint: &Constraint<'tcx>, cause: &SubregionOrigin<'tcx>, exact| match *constraint {
418423
Constraint::RegSubReg(sub, sup)
419424
if ((exact && sup == placeholder_region)
420425
|| (!exact && matches(sup, placeholder_region)))
421426
&& sup != sub =>
422427
{
423428
Some((sub, cause.clone()))
424429
}
425-
// FIXME: Should this check the universe of the var?
426430
Constraint::VarSubReg(vid, sup)
427-
if ((exact && sup == placeholder_region)
428-
|| (!exact && matches(sup, placeholder_region))) =>
431+
if (exact
432+
&& sup == placeholder_region
433+
&& !universe_of_region(vid).can_name(placeholder_universe))
434+
|| (!exact && matches(sup, placeholder_region)) =>
429435
{
430436
Some((ty::Region::new_var(infcx.tcx, vid), cause.clone()))
431437
}
432438
_ => None,
433-
}
434-
};
439+
};
435440
let mut info = region_constraints
436441
.constraints
437442
.iter()

Diff for: tests/ui/higher-ranked/trait-bounds/hrtb-perfect-forwarding.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ where
4141
// isize>`, we require `T : for<'a> Bar<&'a isize>`, but the where
4242
// clause only specifies `T : Bar<&'b isize>`.
4343
foo_hrtb_bar_not(&mut t);
44-
//~^ ERROR mismatched types
44+
//~^ ERROR implementation of `Bar` is not general enough
4545
//~^^ ERROR lifetime may not live long enough
4646
}
4747

Diff for: tests/ui/higher-ranked/trait-bounds/hrtb-perfect-forwarding.stderr

+4-10
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,14 @@ note: due to current limitations in the borrow checker, this implies a `'static`
5353
LL | T: for<'a> Foo<&'a isize> + Bar<&'b isize>,
5454
| ^^^^^^^^^^^^^^^^^^^^^^
5555

56-
error[E0308]: mismatched types
56+
error: implementation of `Bar` is not general enough
5757
--> $DIR/hrtb-perfect-forwarding.rs:43:5
5858
|
5959
LL | foo_hrtb_bar_not(&mut t);
60-
| ^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
60+
| ^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Bar` is not general enough
6161
|
62-
= note: expected trait `for<'a> <T as Foo<&'a isize>>`
63-
found trait `for<'a> <T as Foo<&'a isize>>`
64-
note: the lifetime requirement is introduced here
65-
--> $DIR/hrtb-perfect-forwarding.rs:37:8
66-
|
67-
LL | T: for<'a> Foo<&'a isize> + Bar<&'b isize>,
68-
| ^^^^^^^^^^^^^^^^^^^^^^
62+
= note: `T` must implement `Bar<&'0 isize>`, for any lifetime `'0`...
63+
= note: ...but it actually implements `Bar<&'1 isize>`, for some specific lifetime `'1`
6964

7065
warning: function cannot return without recursing
7166
--> $DIR/hrtb-perfect-forwarding.rs:48:1
@@ -82,4 +77,3 @@ LL | foo_hrtb_bar_hrtb(&mut t);
8277

8378
error: aborting due to 2 previous errors; 4 warnings emitted
8479

85-
For more information about this error, try `rustc --explain E0308`.

Diff for: tests/ui/lifetimes/issue-79187-2.stderr

+4-14
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,8 @@ error[E0308]: mismatched types
5454
LL | take_foo(|a: &i32| a);
5555
| ^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
5656
|
57-
= note: expected trait `for<'a> <{closure@$DIR/issue-79187-2.rs:11:14: 11:23} as FnOnce<(&'a i32,)>>`
58-
found trait `for<'a> <{closure@$DIR/issue-79187-2.rs:11:14: 11:23} as FnOnce<(&'a i32,)>>`
59-
note: this closure does not fulfill the lifetime requirements
60-
--> $DIR/issue-79187-2.rs:11:14
61-
|
62-
LL | take_foo(|a: &i32| a);
63-
| ^^^^^^^^^
57+
= note: expected reference `&_`
58+
found reference `&_`
6459
note: the lifetime requirement is introduced here
6560
--> $DIR/issue-79187-2.rs:5:21
6661
|
@@ -73,13 +68,8 @@ error[E0308]: mismatched types
7368
LL | take_foo(|a: &i32| -> &i32 { a });
7469
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
7570
|
76-
= note: expected trait `for<'a> <{closure@$DIR/issue-79187-2.rs:14:14: 14:31} as FnOnce<(&'a i32,)>>`
77-
found trait `for<'a> <{closure@$DIR/issue-79187-2.rs:14:14: 14:31} as FnOnce<(&'a i32,)>>`
78-
note: this closure does not fulfill the lifetime requirements
79-
--> $DIR/issue-79187-2.rs:14:14
80-
|
81-
LL | take_foo(|a: &i32| -> &i32 { a });
82-
| ^^^^^^^^^^^^^^^^^
71+
= note: expected reference `&_`
72+
found reference `&_`
8373
note: the lifetime requirement is introduced here
8474
--> $DIR/issue-79187-2.rs:5:21
8575
|

0 commit comments

Comments
 (0)