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

ices/71955.rs: fixed with errors #923

Closed
wants to merge 1 commit into from

Conversation

github-actions[bot]
Copy link
Contributor

Issue: rust-lang/rust#71955

trait Parser<'s> {
    type Output;
    
    fn call(&self, input: &'s str) -> (&'s str, Self::Output);
}

impl<'s, F, T> Parser<'s> for F
where F: Fn(&'s str) -> (&'s str, T) {
    type Output = T;
    fn call(&self, input: &'s str) -> (&'s str, T) {
        self(input)
    }
}

fn foo<F1, F2>(
    f1: F1,
    base: &'static str,
    f2: F2
) 
where 
    F1: for<'a> Parser<'a>,
    F2: FnOnce(&<F1 as Parser>::Output) -> bool
{
    let s: String = base.to_owned();
    let str_ref = s.as_ref();
    let (remaining, produced) = f1.call(str_ref);
    assert!(f2(&produced));
    assert_eq!(remaining.len(), 0);
}

struct Wrapper<'a>(&'a str);

fn main() {
    fn bar<'a>(s: &'a str) -> (&'a str, &'a str) {
        (&s[..1], &s[..])
    }
    
    fn baz<'a>(s: &'a str) -> (&'a str, Wrapper<'a>) {
        (&s[..1], Wrapper(&s[..]))
    }
    
    foo(bar, "string", |s| s.len() == 5);
    foo(baz, "string", |s| s.0.len() == 5);
}
=== stdout ===
=== stderr ===
error[E0271]: type mismatch resolving `<for<'a> fn(&'a str) -> (&'a str, &'a str) {bar} as FnOnce<(&str,)>>::Output == (&str, <for<'a> fn(&'a str) -> (&'a str, &'a str) {bar} as Parser<'_>>::Output)`
  --> /home/runner/work/glacier/glacier/ices/71955.rs:42:5
   |
42 |     foo(bar, "string", |s| s.len() == 5);
   |     ^^^ expected associated type, found `&str`
   |
   = note: expected tuple `(&str, <for<'a> fn(&'a str) -> (&'a str, &'a str) {bar} as Parser<'_>>::Output)`
              found tuple `(&str, &str)`
   = help: consider constraining the associated type `<for<'a> fn(&'a str) -> (&'a str, &'a str) {bar} as Parser<'_>>::Output` to `&str` or calling a method that returns `<for<'a> fn(&'a str) -> (&'a str, &'a str) {bar} as Parser<'_>>::Output`
   = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
note: required because of the requirements on the impl of `Parser<'_>` for `for<'a> fn(&'a str) -> (&'a str, &'a str) {bar}`
  --> /home/runner/work/glacier/glacier/ices/71955.rs:7:16
   |
7  | impl<'s, F, T> Parser<'s> for F
   |                ^^^^^^^^^^     ^
note: required by a bound in `foo`
  --> /home/runner/work/glacier/glacier/ices/71955.rs:22:9
   |
15 | fn foo<F1, F2>(
   |    --- required by a bound in this
...
22 |     F2: FnOnce(&<F1 as Parser>::Output) -> bool
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `foo`

error[E0271]: type mismatch resolving `<for<'a> fn(&'a str) -> (&'a str, Wrapper<'a>) {baz} as FnOnce<(&str,)>>::Output == (&str, <for<'a> fn(&'a str) -> (&'a str, Wrapper<'a>) {baz} as Parser<'_>>::Output)`
  --> /home/runner/work/glacier/glacier/ices/71955.rs:43:5
   |
43 |     foo(baz, "string", |s| s.0.len() == 5);
   |     ^^^ expected associated type, found struct `Wrapper`
   |
   = note: expected tuple `(&str, <for<'a> fn(&'a str) -> (&'a str, Wrapper<'a>) {baz} as Parser<'_>>::Output)`
              found tuple `(&str, Wrapper<'_>)`
   = help: consider constraining the associated type `<for<'a> fn(&'a str) -> (&'a str, Wrapper<'a>) {baz} as Parser<'_>>::Output` to `Wrapper<'_>` or calling a method that returns `<for<'a> fn(&'a str) -> (&'a str, Wrapper<'a>) {baz} as Parser<'_>>::Output`
   = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
note: required because of the requirements on the impl of `Parser<'_>` for `for<'a> fn(&'a str) -> (&'a str, Wrapper<'a>) {baz}`
  --> /home/runner/work/glacier/glacier/ices/71955.rs:7:16
   |
7  | impl<'s, F, T> Parser<'s> for F
   |                ^^^^^^^^^^     ^
note: required by a bound in `foo`
  --> /home/runner/work/glacier/glacier/ices/71955.rs:22:9
   |
15 | fn foo<F1, F2>(
   |    --- required by a bound in this
...
22 |     F2: FnOnce(&<F1 as Parser>::Output) -> bool
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `foo`

error: aborting due to 2 previous errors

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

=== stdout ===
=== stderr ===
error[E0271]: type mismatch resolving `<for<'a> fn(&'a str) -> (&'a str, &'a str) {bar} as FnOnce<(&str,)>>::Output == (&str, <for<'a> fn(&'a str) -> (&'a str, &'a str) {bar} as Parser<'_>>::Output)`
  --> /home/runner/work/glacier/glacier/ices/71955.rs:42:5
   |
42 |     foo(bar, "string", |s| s.len() == 5);
   |     ^^^ expected associated type, found `&str`
   |
   = note: expected tuple `(&str, <for<'a> fn(&'a str) -> (&'a str, &'a str) {bar} as Parser<'_>>::Output)`
              found tuple `(&str, &str)`
   = help: consider constraining the associated type `<for<'a> fn(&'a str) -> (&'a str, &'a str) {bar} as Parser<'_>>::Output` to `&str` or calling a method that returns `<for<'a> fn(&'a str) -> (&'a str, &'a str) {bar} as Parser<'_>>::Output`
   = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
note: required because of the requirements on the impl of `Parser<'_>` for `for<'a> fn(&'a str) -> (&'a str, &'a str) {bar}`
  --> /home/runner/work/glacier/glacier/ices/71955.rs:7:16
   |
7  | impl<'s, F, T> Parser<'s> for F
   |                ^^^^^^^^^^     ^
note: required by a bound in `foo`
  --> /home/runner/work/glacier/glacier/ices/71955.rs:22:9
   |
15 | fn foo<F1, F2>(
   |    --- required by a bound in this
...
22 |     F2: FnOnce(&<F1 as Parser>::Output) -> bool
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `foo`

error[E0271]: type mismatch resolving `<for<'a> fn(&'a str) -> (&'a str, Wrapper<'a>) {baz} as FnOnce<(&str,)>>::Output == (&str, <for<'a> fn(&'a str) -> (&'a str, Wrapper<'a>) {baz} as Parser<'_>>::Output)`
  --> /home/runner/work/glacier/glacier/ices/71955.rs:43:5
   |
43 |     foo(baz, "string", |s| s.0.len() == 5);
   |     ^^^ expected associated type, found struct `Wrapper`
   |
   = note: expected tuple `(&str, <for<'a> fn(&'a str) -> (&'a str, Wrapper<'a>) {baz} as Parser<'_>>::Output)`
              found tuple `(&str, Wrapper<'_>)`
   = help: consider constraining the associated type `<for<'a> fn(&'a str) -> (&'a str, Wrapper<'a>) {baz} as Parser<'_>>::Output` to `Wrapper<'_>` or calling a method that returns `<for<'a> fn(&'a str) -> (&'a str, Wrapper<'a>) {baz} as Parser<'_>>::Output`
   = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
note: required because of the requirements on the impl of `Parser<'_>` for `for<'a> fn(&'a str) -> (&'a str, Wrapper<'a>) {baz}`
  --> /home/runner/work/glacier/glacier/ices/71955.rs:7:16
   |
7  | impl<'s, F, T> Parser<'s> for F
   |                ^^^^^^^^^^     ^
note: required by a bound in `foo`
  --> /home/runner/work/glacier/glacier/ices/71955.rs:22:9
   |
15 | fn foo<F1, F2>(
   |    --- required by a bound in this
...
22 |     F2: FnOnce(&<F1 as Parser>::Output) -> bool
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `foo`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0271`.
==============
@Alexendoo Alexendoo closed this Aug 29, 2021
@Alexendoo Alexendoo deleted the autofix/ices/71955.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