-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #58056 - nikomatsakis:issue-57843-universe-leak, r=pnkf…
…elix make generalization code create new variables in correct universe In our type inference system, when we "generalize" a type T to become a suitable value for a type variable V, we sometimes wind up creating new inference variables. So, for example, if we are making V be some subtype of `&'X u32`, then we might instantiate V with `&'Y u32`. This generalized type is then related `&'Y u32 <: &'X u32`, resulting in a region constriant `'Y: 'X`. Previously, however, we were making these fresh variables like `'Y` in the "current universe", but they should be created in the universe of V. Moreover, we sometimes cheat in an invariant context and avoid creating fresh variables if we know the result must be equal -- we can only do that when the universes work out. Fixes #57843 r? @pnkfelix
- Loading branch information
Showing
16 changed files
with
150 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/test/ui/associated-types/cache/project-fn-ret-invariant.transmute.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
src/test/ui/associated-types/higher-ranked-projection.bad.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
error: implementation of `Mirror` is not general enough | ||
error[E0308]: mismatched types | ||
--> $DIR/higher-ranked-projection.rs:25:5 | ||
| | ||
LL | foo(()); | ||
| ^^^ | ||
| ^^^ one type is more general than the other | ||
| | ||
= note: Due to a where-clause on `foo`, | ||
= note: `Mirror` would have to be implemented for the type `&'0 ()`, for any lifetime `'0` | ||
= note: but `Mirror` is actually implemented for the type `&'1 ()`, for some specific lifetime `'1` | ||
= note: expected type `&'a ()` | ||
found type `&()` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
error: implementation of `Foo` is not general enough | ||
error[E0308]: mismatched types | ||
--> $DIR/hrtb-perfect-forwarding.rs:46:5 | ||
| | ||
LL | foo_hrtb_bar_not(&mut t); //~ ERROR not general enough | ||
| ^^^^^^^^^^^^^^^^ | ||
LL | foo_hrtb_bar_not(&mut t); //~ ERROR mismatched types | ||
| ^^^^^^^^^^^^^^^^ one type is more general than the other | ||
| | ||
= note: Due to a where-clause on `foo_hrtb_bar_not`, | ||
= note: `&mut T` must implement `Foo<&'0 isize>`, for any lifetime `'0` | ||
= note: but `&mut T` actually implements `Foo<&'1 isize>`, for some specific lifetime `'1` | ||
= note: expected type `Bar<&'a isize>` | ||
found type `Bar<&'b isize>` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Regression test for an ICE that occurred with the universes code: | ||
// | ||
// The signature of the closure `|_|` was being inferred to | ||
// `exists<'r> fn(&'r u8)`. This should result in a type error since | ||
// the signature `for<'r> fn(&'r u8)` is required. However, due to a | ||
// bug in the type variable generalization code, the placeholder for | ||
// `'r` was leaking out into the writeback phase, causing an ICE. | ||
|
||
trait ClonableFn<T> { | ||
fn clone(&self) -> Box<dyn Fn(T)>; | ||
} | ||
|
||
impl<T, F: 'static> ClonableFn<T> for F | ||
where F: Fn(T) + Clone { | ||
fn clone(&self) -> Box<dyn Fn(T)> { | ||
Box::new(self.clone()) | ||
} | ||
} | ||
|
||
struct Foo(Box<dyn for<'a> ClonableFn<&'a bool>>); | ||
|
||
fn main() { | ||
Foo(Box::new(|_| ())); //~ ERROR mismatched types | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/issue-57843.rs:23:9 | ||
| | ||
LL | Foo(Box::new(|_| ())); //~ ERROR mismatched types | ||
| ^^^^^^^^^^^^^^^^ one type is more general than the other | ||
| | ||
= note: expected type `std::ops::FnOnce<(&'a bool,)>` | ||
found type `std::ops::FnOnce<(&bool,)>` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |