File tree Expand file tree Collapse file tree 5 files changed +144
-0
lines changed
src/test/ui/higher-rank-trait-bounds/normalize-under-binder Expand file tree Collapse file tree 5 files changed +144
-0
lines changed Original file line number Diff line number Diff line change 1+ // check-pass
2+ // edition:2018
3+
4+ type BoxFuture < T > = std:: pin:: Pin < Box < dyn std:: future:: Future < Output =T > > > ;
5+
6+ fn main ( ) {
7+ f ( ) ;
8+ }
9+
10+ async fn f ( ) {
11+ run ( "dependency" ) . await ;
12+ }
13+
14+ struct InMemoryStorage ;
15+
16+ struct User < ' dep > {
17+ dep : & ' dep str ,
18+ }
19+
20+ impl < ' a > StorageRequest < InMemoryStorage > for SaveUser < ' a > {
21+ fn execute ( & self ) -> BoxFuture < Result < ( ) , String > > {
22+ todo ! ( )
23+ }
24+ }
25+
26+ trait Storage {
27+ type Error ;
28+ }
29+
30+ impl Storage for InMemoryStorage {
31+ type Error = String ;
32+ }
33+
34+ trait StorageRequestReturnType {
35+ type Output ;
36+ }
37+
38+ trait StorageRequest < S : Storage > : StorageRequestReturnType {
39+ fn execute (
40+ & self ,
41+ ) -> BoxFuture < Result < <Self as StorageRequestReturnType >:: Output , <S as Storage >:: Error > > ;
42+ }
43+
44+ struct SaveUser < ' a > {
45+ name : & ' a str ,
46+ }
47+
48+ impl < ' a > StorageRequestReturnType for SaveUser < ' a > {
49+ type Output = ( ) ;
50+ }
51+
52+ impl < ' dep > User < ' dep > {
53+ async fn save < S > ( self )
54+ where
55+ S : Storage ,
56+ for < ' a > SaveUser < ' a > : StorageRequest < S > ,
57+ {
58+ SaveUser { name : "Joe" }
59+ . execute ( )
60+ . await ;
61+ }
62+ }
63+
64+ async fn run < S > ( dep : & str )
65+ where
66+ S : Storage ,
67+ for < ' a > SaveUser < ' a > : StorageRequest < S > ,
68+ {
69+ User { dep } . save ( ) . await ;
70+ }
Original file line number Diff line number Diff line change 1+ // check-pass
2+
3+ trait Bar {
4+ type Type ;
5+ }
6+ struct Foo < ' a > ( & ' a ( ) ) ;
7+ impl < ' a > Bar for Foo < ' a > {
8+ type Type = ( ) ;
9+ }
10+
11+ fn func < ' a > ( _: <Foo < ' a > as Bar >:: Type ) { }
12+ fn assert_is_func < A > ( _: fn ( A ) ) { }
13+
14+ fn test ( )
15+ where
16+ for < ' a > <Foo < ' a > as Bar >:: Type : Sized ,
17+ {
18+ assert_is_func ( func) ;
19+ }
20+
21+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ // check-pass
2+
3+ pub trait Indexable {
4+ type Idx ;
5+ }
6+ impl Indexable for u8 {
7+ type Idx = u8 ;
8+ }
9+ impl Indexable for u16 {
10+ type Idx = u16 ;
11+ }
12+
13+ pub trait Indexer < T : Indexable > : std:: ops:: Index < T :: Idx , Output = T > { }
14+
15+ trait StoreIndex : Indexer < u8 > + Indexer < u16 > { }
16+
17+ fn foo ( st : & impl StoreIndex ) -> & dyn StoreIndex {
18+ st as & dyn StoreIndex
19+ }
20+
21+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ #![ feature( unboxed_closures) ]
2+
3+ trait SomeTrait < ' a > {
4+ type Associated ;
5+ }
6+
7+ fn give_me_ice < T > ( ) {
8+ callee :: < fn ( & ( ) ) -> <T as SomeTrait < ' _ > >:: Associated > ( ) ;
9+ //~^ ERROR: the trait bound `T: SomeTrait<'_>` is not satisfied
10+ }
11+
12+ fn callee < T : Fn < ( & ' static ( ) , ) > > ( ) {
13+ println ! ( "{}" , std:: any:: type_name:: <<T as FnOnce <( & ' static ( ) , ) >>:: Output >( ) ) ;
14+ }
15+
16+ fn main ( ) {
17+ give_me_ice :: < ( ) > ( ) ;
18+ }
Original file line number Diff line number Diff line change 1+ error[E0277]: the trait bound `T: SomeTrait<'_>` is not satisfied
2+ --> $DIR/issue-85455.rs:8:5
3+ |
4+ LL | callee::<fn(&()) -> <T as SomeTrait<'_>>::Associated>();
5+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `SomeTrait<'_>` is not implemented for `T`
6+ |
7+ help: consider restricting type parameter `T`
8+ |
9+ LL | fn give_me_ice<T: SomeTrait<'_>>() {
10+ | +++++++++++++++
11+
12+ error: aborting due to previous error
13+
14+ For more information about this error, try `rustc --explain E0277`.
You can’t perform that action at this time.
0 commit comments