-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make nll higher ranked equate use bidirectional subtyping in invarian…
…t context
- Loading branch information
1 parent
ef8c4ce
commit 6a75a17
Showing
7 changed files
with
162 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// A regression test for #97156 | ||
|
||
type One = for<'a> fn(&'a (), &'a ()); | ||
type Two = for<'a, 'b> fn(&'a (), &'b ()); | ||
|
||
mod my_api { | ||
use std::any::Any; | ||
use std::marker::PhantomData; | ||
|
||
pub struct Foo<T: 'static> { | ||
a: &'static dyn Any, | ||
_p: PhantomData<*mut T>, // invariant, the type of the `dyn Any` | ||
} | ||
|
||
impl<T: 'static> Foo<T> { | ||
pub fn deref(&self) -> &'static T { | ||
match self.a.downcast_ref::<T>() { | ||
None => unsafe { std::hint::unreachable_unchecked() }, | ||
Some(a) => a, | ||
} | ||
} | ||
|
||
pub fn new(a: T) -> Foo<T> { | ||
Foo::<T> { a: Box::leak(Box::new(a)), _p: PhantomData } | ||
} | ||
} | ||
} | ||
|
||
use my_api::*; | ||
|
||
fn main() { | ||
let foo = Foo::<One>::new((|_, _| ()) as One); | ||
foo.deref(); | ||
let foo: Foo<Two> = foo; | ||
//~^ ERROR mismatched types [E0308] | ||
//~| ERROR mismatched types [E0308] | ||
foo.deref(); | ||
} |
22 changes: 22 additions & 0 deletions
22
tests/ui/higher-ranked/higher-ranked-lifetime-equality.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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/higher-ranked-lifetime-equality.rs:34:25 | ||
| | ||
LL | let foo: Foo<Two> = foo; | ||
| ^^^ one type is more general than the other | ||
| | ||
= note: expected struct `my_api::Foo<for<'a, 'b> fn(&'a (), &'b ())>` | ||
found struct `my_api::Foo<for<'a> fn(&'a (), &'a ())>` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/higher-ranked-lifetime-equality.rs:34:25 | ||
| | ||
LL | let foo: Foo<Two> = foo; | ||
| ^^^ one type is more general than the other | ||
| | ||
= note: expected struct `my_api::Foo<for<'a, 'b> fn(&'a (), &'b ())>` | ||
found struct `my_api::Foo<for<'a> fn(&'a (), &'a ())>` | ||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/hr-fn-aau-eq-abu.rs:18:53 | ||
| | ||
LL | let a: Cell<for<'a, 'b> fn(&'a u32, &'b u32)> = make_cell_aa(); | ||
| ^^^^^^^^^^^^^^ one type is more general than the other | ||
| | ||
= note: expected struct `Cell<for<'a, 'b> fn(&'a _, &'b _)>` | ||
found struct `Cell<for<'a> fn(&'a _, &'a _)>` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/hr-fn-aau-eq-abu.rs:18:53 | ||
| | ||
LL | let a: Cell<for<'a, 'b> fn(&'a u32, &'b u32)> = make_cell_aa(); | ||
| ^^^^^^^^^^^^^^ one type is more general than the other | ||
| | ||
= note: expected struct `Cell<for<'a, 'b> fn(&'a _, &'b _)>` | ||
found struct `Cell<for<'a> fn(&'a _, &'a _)>` | ||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |