forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
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 rust-lang#88640 - SkiFire13:tests-for-85499, r=jackh726
Add tests for issues fixed by rust-lang#85499 Closes rust-lang#80706 Closes rust-lang#80956 Closes rust-lang#81809 Closes rust-lang#85455
- Loading branch information
Showing
5 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-80706.rs
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,70 @@ | ||
// check-pass | ||
// edition:2018 | ||
|
||
type BoxFuture<T> = std::pin::Pin<Box<dyn std::future::Future<Output=T>>>; | ||
|
||
fn main() { | ||
f(); | ||
} | ||
|
||
async fn f() { | ||
run("dependency").await; | ||
} | ||
|
||
struct InMemoryStorage; | ||
|
||
struct User<'dep> { | ||
dep: &'dep str, | ||
} | ||
|
||
impl<'a> StorageRequest<InMemoryStorage> for SaveUser<'a> { | ||
fn execute(&self) -> BoxFuture<Result<(), String>> { | ||
todo!() | ||
} | ||
} | ||
|
||
trait Storage { | ||
type Error; | ||
} | ||
|
||
impl Storage for InMemoryStorage { | ||
type Error = String; | ||
} | ||
|
||
trait StorageRequestReturnType { | ||
type Output; | ||
} | ||
|
||
trait StorageRequest<S: Storage>: StorageRequestReturnType { | ||
fn execute( | ||
&self, | ||
) -> BoxFuture<Result<<Self as StorageRequestReturnType>::Output, <S as Storage>::Error>>; | ||
} | ||
|
||
struct SaveUser<'a> { | ||
name: &'a str, | ||
} | ||
|
||
impl<'a> StorageRequestReturnType for SaveUser<'a> { | ||
type Output = (); | ||
} | ||
|
||
impl<'dep> User<'dep> { | ||
async fn save<S>(self) | ||
where | ||
S: Storage, | ||
for<'a> SaveUser<'a>: StorageRequest<S>, | ||
{ | ||
SaveUser { name: "Joe" } | ||
.execute() | ||
.await; | ||
} | ||
} | ||
|
||
async fn run<S>(dep: &str) | ||
where | ||
S: Storage, | ||
for<'a> SaveUser<'a>: StorageRequest<S>, | ||
{ | ||
User { dep }.save().await; | ||
} |
21 changes: 21 additions & 0 deletions
21
src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-80956.rs
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,21 @@ | ||
// check-pass | ||
|
||
trait Bar { | ||
type Type; | ||
} | ||
struct Foo<'a>(&'a ()); | ||
impl<'a> Bar for Foo<'a> { | ||
type Type = (); | ||
} | ||
|
||
fn func<'a>(_: <Foo<'a> as Bar>::Type) {} | ||
fn assert_is_func<A>(_: fn(A)) {} | ||
|
||
fn test() | ||
where | ||
for<'a> <Foo<'a> as Bar>::Type: Sized, | ||
{ | ||
assert_is_func(func); | ||
} | ||
|
||
fn main() {} |
21 changes: 21 additions & 0 deletions
21
src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-81809.rs
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,21 @@ | ||
// check-pass | ||
|
||
pub trait Indexable { | ||
type Idx; | ||
} | ||
impl Indexable for u8 { | ||
type Idx = u8; | ||
} | ||
impl Indexable for u16 { | ||
type Idx = u16; | ||
} | ||
|
||
pub trait Indexer<T: Indexable>: std::ops::Index<T::Idx, Output = T> {} | ||
|
||
trait StoreIndex: Indexer<u8> + Indexer<u16> {} | ||
|
||
fn foo(st: &impl StoreIndex) -> &dyn StoreIndex { | ||
st as &dyn StoreIndex | ||
} | ||
|
||
fn main() {} |
18 changes: 18 additions & 0 deletions
18
src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-85455.rs
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,18 @@ | ||
#![feature(unboxed_closures)] | ||
|
||
trait SomeTrait<'a> { | ||
type Associated; | ||
} | ||
|
||
fn give_me_ice<T>() { | ||
callee::<fn(&()) -> <T as SomeTrait<'_>>::Associated>(); | ||
//~^ ERROR: the trait bound `T: SomeTrait<'_>` is not satisfied | ||
} | ||
|
||
fn callee<T: Fn<(&'static (),)>>() { | ||
println!("{}", std::any::type_name::<<T as FnOnce<(&'static (),)>>::Output>()); | ||
} | ||
|
||
fn main() { | ||
give_me_ice::<()>(); | ||
} |
14 changes: 14 additions & 0 deletions
14
src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-85455.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,14 @@ | ||
error[E0277]: the trait bound `T: SomeTrait<'_>` is not satisfied | ||
--> $DIR/issue-85455.rs:8:5 | ||
| | ||
LL | callee::<fn(&()) -> <T as SomeTrait<'_>>::Associated>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `SomeTrait<'_>` is not implemented for `T` | ||
| | ||
help: consider restricting type parameter `T` | ||
| | ||
LL | fn give_me_ice<T: SomeTrait<'_>>() { | ||
| +++++++++++++++ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |