Skip to content

Commit fb6cec4

Browse files
committed
Revert to only using opportunistic_resolve_vars for existing places
1 parent 61157b3 commit fb6cec4

File tree

12 files changed

+47
-94
lines changed

12 files changed

+47
-94
lines changed

compiler/rustc_infer/src/infer/canonical/canonicalizer.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,22 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
322322
}
323323
}
324324

325-
ty::ReVar(_) => self.canonicalize_region_mode.canonicalize_free_region(self, r),
325+
ty::ReVar(vid) => {
326+
let resolved_vid = self
327+
.infcx
328+
.unwrap()
329+
.inner
330+
.borrow_mut()
331+
.unwrap_region_constraints()
332+
.opportunistic_resolve_var(vid);
333+
debug!(
334+
"canonical: region var found with vid {:?}, \
335+
opportunistically resolved to {:?}",
336+
vid, r
337+
);
338+
let r = self.tcx.reuse_or_mk_region(r, ty::ReVar(resolved_vid));
339+
self.canonicalize_region_mode.canonicalize_free_region(self, r)
340+
}
326341

327342
ty::ReStatic
328343
| ty::ReEarlyBound(..)

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,10 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
623623
}
624624
}
625625

626+
pub fn opportunistic_resolve_var(&mut self, rid: ty::RegionVid) -> ty::RegionVid {
627+
self.unification_table().find(rid).vid
628+
}
629+
626630
pub fn opportunistic_resolve_region(
627631
&mut self,
628632
tcx: TyCtxt<'tcx>,
@@ -692,8 +696,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
692696
&self,
693697
value_count: usize,
694698
) -> (Range<RegionVid>, Vec<RegionVariableOrigin>) {
695-
let range = RegionVid::from(value_count as u32)
696-
..RegionVid::from(self.unification_table.len() as u32);
699+
let range = RegionVid::from(value_count)..RegionVid::from(self.unification_table.len());
697700
(
698701
range.clone(),
699702
(range.start.index()..range.end.index())

compiler/rustc_infer/src/infer/resolve.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,18 @@ impl<'a, 'tcx> TypeFolder<'tcx> for OpportunisticRegionResolver<'a, 'tcx> {
8484
}
8585

8686
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
87-
let tcx = self.tcx();
88-
self.infcx
89-
.inner
90-
.borrow_mut()
91-
.unwrap_region_constraints()
92-
.opportunistic_resolve_region(tcx, r)
87+
match *r {
88+
ty::ReVar(rid) => {
89+
let resolved = self
90+
.infcx
91+
.inner
92+
.borrow_mut()
93+
.unwrap_region_constraints()
94+
.opportunistic_resolve_var(rid);
95+
self.tcx().reuse_or_mk_region(r, ty::ReVar(resolved))
96+
}
97+
_ => r,
98+
}
9399
}
94100

95101
fn fold_const(&mut self, ct: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {

src/test/ui/associated-types/associated-types-eq-hr.rs

-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ pub fn call_tuple_two() {
102102
tuple_two::<Tuple>();
103103
//~^ ERROR implementation of `TheTrait` is not general enough
104104
//~| ERROR implementation of `TheTrait` is not general enough
105-
//~| ERROR mismatched types
106-
//~| ERROR mismatched types
107105
}
108106

109107
pub fn call_tuple_three() {

src/test/ui/associated-types/associated-types-eq-hr.stderr

+3-32
Original file line numberDiff line numberDiff line change
@@ -46,34 +46,6 @@ LL | tuple_one::<Tuple>();
4646
= note: `Tuple` must implement `TheTrait<(&'0 isize, &'1 isize)>`, for any two lifetimes `'0` and `'1`...
4747
= note: ...but it actually implements `TheTrait<(&'2 isize, &'2 isize)>`, for some specific lifetime `'2`
4848

49-
error[E0308]: mismatched types
50-
--> $DIR/associated-types-eq-hr.rs:102:5
51-
|
52-
LL | tuple_two::<Tuple>();
53-
| ^^^^^^^^^^^^^^^^^^ lifetime mismatch
54-
|
55-
= note: expected reference `&'x isize`
56-
found reference `&'y isize`
57-
note: the lifetime requirement is introduced here
58-
--> $DIR/associated-types-eq-hr.rs:66:53
59-
|
60-
LL | T: for<'x, 'y> TheTrait<(&'x isize, &'y isize), A = &'y isize>,
61-
| ^^^^^^^^^^^^^
62-
63-
error[E0308]: mismatched types
64-
--> $DIR/associated-types-eq-hr.rs:102:5
65-
|
66-
LL | tuple_two::<Tuple>();
67-
| ^^^^^^^^^^^^^^^^^^ lifetime mismatch
68-
|
69-
= note: expected reference `&'x isize`
70-
found reference `&'y isize`
71-
note: the lifetime requirement is introduced here
72-
--> $DIR/associated-types-eq-hr.rs:66:53
73-
|
74-
LL | T: for<'x, 'y> TheTrait<(&'x isize, &'y isize), A = &'y isize>,
75-
| ^^^^^^^^^^^^^
76-
7749
error: implementation of `TheTrait` is not general enough
7850
--> $DIR/associated-types-eq-hr.rs:102:5
7951
|
@@ -93,15 +65,14 @@ LL | tuple_two::<Tuple>();
9365
= note: ...but it actually implements `TheTrait<(&'2 isize, &'2 isize)>`, for some specific lifetime `'2`
9466

9567
error: implementation of `TheTrait` is not general enough
96-
--> $DIR/associated-types-eq-hr.rs:114:5
68+
--> $DIR/associated-types-eq-hr.rs:112:5
9769
|
9870
LL | tuple_four::<Tuple>();
9971
| ^^^^^^^^^^^^^^^^^^^ implementation of `TheTrait` is not general enough
10072
|
10173
= note: `Tuple` must implement `TheTrait<(&'0 isize, &'1 isize)>`, for any two lifetimes `'0` and `'1`...
10274
= note: ...but it actually implements `TheTrait<(&'2 isize, &'2 isize)>`, for some specific lifetime `'2`
10375

104-
error: aborting due to 9 previous errors
76+
error: aborting due to 7 previous errors
10577

106-
Some errors have detailed explanations: E0271, E0308.
107-
For more information about an error, try `rustc --explain E0271`.
78+
For more information about this error, try `rustc --explain E0271`.

src/test/ui/hrtb/issue-62203-hrtb-ice.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | let v = Unit2.m(
99
= help: consider constraining the associated type `<_ as Ty<'_>>::V` to `Unit4`
1010
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
1111

12-
error[E0271]: type mismatch resolving `<[closure@$DIR/issue-62203-hrtb-ice.rs:42:17: 42:39] as FnOnce<((&'r u8,),)>>::Output == Unit3`
12+
error[E0271]: type mismatch resolving `<[closure@$DIR/issue-62203-hrtb-ice.rs:42:17: 42:39] as FnOnce<((&u8,),)>>::Output == Unit3`
1313
--> $DIR/issue-62203-hrtb-ice.rs:38:19
1414
|
1515
LL | let v = Unit2.m(

src/test/ui/rfc1623.rs

-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ static SOME_STRUCT: &SomeStruct = &SomeStruct {
2323
bar: &Bar { bools: &[true, true] },
2424
f: &id,
2525
//~^ ERROR implementation of `FnOnce` is not general enough
26-
//~^^ mismatched types
27-
//~^^^ mismatched types
28-
//~^^^^ mismatched types
29-
//~^^^^^ mismatched types
3026
};
3127

3228
// very simple test for a 'static static with default lifetime

src/test/ui/rfc1623.stderr

+1-38
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,3 @@
1-
error[E0308]: mismatched types
2-
--> $DIR/rfc1623.rs:24:8
3-
|
4-
LL | f: &id,
5-
| ^^^ one type is more general than the other
6-
|
7-
= note: expected reference `&'a Foo<'b>`
8-
found reference `&'a Foo<'b>`
9-
10-
error[E0308]: mismatched types
11-
--> $DIR/rfc1623.rs:24:8
12-
|
13-
LL | f: &id,
14-
| ^^^ one type is more general than the other
15-
|
16-
= note: expected reference `&'a Foo<'b>`
17-
found reference `&'a Foo<'b>`
18-
19-
error[E0308]: mismatched types
20-
--> $DIR/rfc1623.rs:24:8
21-
|
22-
LL | f: &id,
23-
| ^^^ one type is more general than the other
24-
|
25-
= note: expected reference `&'a Foo<'b>`
26-
found reference `&'a Foo<'b>`
27-
28-
error[E0308]: mismatched types
29-
--> $DIR/rfc1623.rs:24:8
30-
|
31-
LL | f: &id,
32-
| ^^^ one type is more general than the other
33-
|
34-
= note: expected reference `&'a Foo<'b>`
35-
found reference `&'a Foo<'b>`
36-
371
error: implementation of `FnOnce` is not general enough
382
--> $DIR/rfc1623.rs:24:8
393
|
@@ -43,6 +7,5 @@ LL | f: &id,
437
= note: `fn(&'2 Foo<'_>) -> &'2 Foo<'_> {id::<&'2 Foo<'_>>}` must implement `FnOnce<(&'1 Foo<'b>,)>`, for any lifetime `'1`...
448
= note: ...but it actually implements `FnOnce<(&'2 Foo<'_>,)>`, for some specific lifetime `'2`
459

46-
error: aborting due to 5 previous errors
10+
error: aborting due to previous error
4711

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

src/test/ui/traits/inductive-overflow/lifetime.rs

+2
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ fn main() {
2626
// Should only be a few notes.
2727
is_send::<X<C<'static>>>();
2828
//~^ ERROR overflow evaluating
29+
//~| 2 redundant requirements hidden
30+
//~| required because of
2931
}

src/test/ui/traits/inductive-overflow/lifetime.stderr

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0275]: overflow evaluating the requirement `Box<X<C<'static>>>: NotAuto`
1+
error[E0275]: overflow evaluating the requirement `Box<X<C<'_>>>: NotAuto`
22
--> $DIR/lifetime.rs:27:5
33
|
44
LL | fn is_send<S: NotAuto>() {}
@@ -7,11 +7,13 @@ LL | fn is_send<S: NotAuto>() {}
77
LL | is_send::<X<C<'static>>>();
88
| ^^^^^^^^^^^^^^^^^^^^^^^^
99
|
10-
note: required because of the requirements on the impl of `NotAuto` for `X<C<'static>>`
10+
note: required because of the requirements on the impl of `NotAuto` for `X<C<'_>>`
1111
--> $DIR/lifetime.rs:19:12
1212
|
1313
LL | impl<T: Y> NotAuto for X<T> where T::P: NotAuto {}
1414
| ^^^^^^^ ^^^^
15+
= note: 2 redundant requirements hidden
16+
= note: required because of the requirements on the impl of `NotAuto` for `X<C<'static>>`
1517

1618
error: aborting due to previous error
1719

src/test/ui/type-alias-impl-trait/issue-60371.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ trait Bug {
99
impl Bug for &() {
1010
type Item = impl Bug; //~ ERROR `impl Trait` in type aliases is unstable
1111
//~^ ERROR the trait bound `(): Bug` is not satisfied
12-
//~^^ ERROR the trait bound
12+
//~^^ ERROR could not find defining uses
1313

1414
const FUN: fn() -> Self::Item = || ();
1515
//~^ ERROR type alias impl trait is not permitted here

src/test/ui/type-alias-impl-trait/issue-60371.stderr

+2-5
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,11 @@ LL | type Item = impl Bug;
2525
= help: the following implementations were found:
2626
<&() as Bug>
2727

28-
error[E0277]: the trait bound `(): Bug` is not satisfied
28+
error: could not find defining uses
2929
--> $DIR/issue-60371.rs:10:17
3030
|
3131
LL | type Item = impl Bug;
32-
| ^^^^^^^^ the trait `Bug` is not implemented for `()`
33-
|
34-
= help: the following implementations were found:
35-
<&() as Bug>
32+
| ^^^^^^^^
3633

3734
error: aborting due to 4 previous errors
3835

0 commit comments

Comments
 (0)