Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

ices/62529-09.rs: fixed with errors #916

Closed
wants to merge 1 commit into from

Conversation

github-actions[bot]
Copy link
Contributor

Issue: rust-lang/rust#62529

use std::marker::PhantomData;

// Borrowing encoding of paramaterized types from
// https://github.com/rust-lang/rfcs/blob/master/text/0195-associated-items.md#encoding-higher-kinded-types

trait TypeWithLifetime<'a> {
    type Type: Copy;
}

// type At<'a,T> where T: TypeWithLifetime<'a> = T::Type;

struct Str;

impl<'a> TypeWithLifetime<'a> for Str {
    type Type = &'a str;
}
    
trait Consumer<T> where T: for<'a> TypeWithLifetime<'a> {
    fn accept(&mut self, arg: <T as TypeWithLifetime>::Type);
}

impl Consumer<Str> for String {
    fn accept(&mut self, arg: &str) { self.push_str(arg) }
}

struct FilterConsumer<F,T,C> {
    function: F,
    consumer: C,
    phantom: PhantomData<T>,
}

impl<F,T,C> Consumer<T> for FilterConsumer<F,T,C> where F: Fn(<T as TypeWithLifetime>::Type) -> bool, T: for<'a> TypeWithLifetime<'a>, C: Consumer<T> {
    fn accept(&mut self, arg: <T as TypeWithLifetime>::Type) {
        if (self.function)(arg) { self.consumer.accept(arg) }
    }
}

fn main() {
    let mut consumer = FilterConsumer{
        function: |x:<Str as TypeWithLifetime>::Type| x.chars().all(char::is_alphabetic),
        consumer: String::new(),
        phantom: PhantomData,
    };
    consumer.accept("hi");
}
=== stdout ===
=== stderr ===
error[E0599]: the method `accept` exists for struct `FilterConsumer<[closure@/home/runner/work/glacier/glacier/ices/62529-09.rs:40:19: 40:89], _, String>`, but its trait bounds were not satisfied
  --> /home/runner/work/glacier/glacier/ices/62529-09.rs:44:14
   |
26 | struct FilterConsumer<F,T,C> {
   | ----------------------------
   | |
   | method `accept` not found for this
   | doesn't satisfy `_: Consumer<_>`
...
40 |         function: |x:<Str as TypeWithLifetime>::Type| x.chars().all(char::is_alphabetic),
   |                   ----------------------------------------------------------------------
   |                   |
   |                   doesn't satisfy `<_ as FnOnce<(<_ as TypeWithLifetime<'_>>::Type,)>>::Output = bool`
   |                   doesn't satisfy `_: Fn<(<_ as TypeWithLifetime<'_>>::Type,)>`
...
44 |     consumer.accept("hi");
   |              ^^^^^^ method cannot be called on `FilterConsumer<[closure@/home/runner/work/glacier/glacier/ices/62529-09.rs:40:19: 40:89], _, String>` due to unsatisfied trait bounds
   |
   = note: the following trait bounds were not satisfied:
           `<[closure@/home/runner/work/glacier/glacier/ices/62529-09.rs:40:19: 40:89] as FnOnce<(<_ as TypeWithLifetime<'_>>::Type,)>>::Output = bool`
           which is required by `FilterConsumer<[closure@/home/runner/work/glacier/glacier/ices/62529-09.rs:40:19: 40:89], _, String>: Consumer<_>`
           `[closure@/home/runner/work/glacier/glacier/ices/62529-09.rs:40:19: 40:89]: Fn<(<_ as TypeWithLifetime<'_>>::Type,)>`
           which is required by `FilterConsumer<[closure@/home/runner/work/glacier/glacier/ices/62529-09.rs:40:19: 40:89], _, String>: Consumer<_>`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0599`.
==============

=== stdout ===
=== stderr ===
error[E0599]: the method `accept` exists for struct `FilterConsumer<[closure@/home/runner/work/glacier/glacier/ices/62529-09.rs:40:19: 40:89], _, String>`, but its trait bounds were not satisfied
  --> /home/runner/work/glacier/glacier/ices/62529-09.rs:44:14
   |
26 | struct FilterConsumer<F,T,C> {
   | ----------------------------
   | |
   | method `accept` not found for this
   | doesn't satisfy `_: Consumer<_>`
...
40 |         function: |x:<Str as TypeWithLifetime>::Type| x.chars().all(char::is_alphabetic),
   |                   ----------------------------------------------------------------------
   |                   |
   |                   doesn't satisfy `<_ as FnOnce<(<_ as TypeWithLifetime<'_>>::Type,)>>::Output = bool`
   |                   doesn't satisfy `_: Fn<(<_ as TypeWithLifetime<'_>>::Type,)>`
...
44 |     consumer.accept("hi");
   |              ^^^^^^ method cannot be called on `FilterConsumer<[closure@/home/runner/work/glacier/glacier/ices/62529-09.rs:40:19: 40:89], _, String>` due to unsatisfied trait bounds
   |
   = note: the following trait bounds were not satisfied:
           `<[closure@/home/runner/work/glacier/glacier/ices/62529-09.rs:40:19: 40:89] as FnOnce<(<_ as TypeWithLifetime<'_>>::Type,)>>::Output = bool`
           which is required by `FilterConsumer<[closure@/home/runner/work/glacier/glacier/ices/62529-09.rs:40:19: 40:89], _, String>: Consumer<_>`
           `[closure@/home/runner/work/glacier/glacier/ices/62529-09.rs:40:19: 40:89]: Fn<(<_ as TypeWithLifetime<'_>>::Type,)>`
           which is required by `FilterConsumer<[closure@/home/runner/work/glacier/glacier/ices/62529-09.rs:40:19: 40:89], _, String>: Consumer<_>`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0599`.
==============
@Alexendoo Alexendoo closed this Aug 26, 2021
@Alexendoo Alexendoo deleted the autofix/ices/62529-09.rs branch August 29, 2021 12:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants