Skip to content

calling impl Fn in defining scope #181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
compiler-errors opened this issue Apr 18, 2025 · 3 comments · May be fixed by rust-lang/rust#140496
Open

calling impl Fn in defining scope #181

compiler-errors opened this issue Apr 18, 2025 · 3 comments · May be fixed by rust-lang/rust#140496
Assignees
Labels
from-crater A regression found via a crater run, not part of our test suite

Comments

@compiler-errors
Copy link
Member

compiler-errors commented Apr 18, 2025

impacts multiple crates:

struct ShExCompactPrinter;

struct TripleExpr;

impl ShExCompactPrinter {
    fn pp_triple_expr(&self) -> impl Fn(&TripleExpr, &ShExCompactPrinter) + '_ {
        move |te, printer| {
            printer.pp_triple_expr()(te, printer);
        }
    }
}
error[E0282]: type annotations needed
 --> /home/mgx/test.rs:8:13
  |
8 |             printer.pp_triple_expr()(te, printer);
  |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type

error[E0618]: expected function, found `impl for<'a, 'b> Fn(&'a TripleExpr, &'b ShExCompactPrinter) + '_`
 --> /home/mgx/test.rs:8:13
  |
8 |             printer.pp_triple_expr()(te, printer);
  |             ^^^^^^^^^^^^^^^^^^^^^^^^-------------
  |             |
  |             call expression requires function

Has to do with recursive definition of opaque.

@compiler-errors

This comment has been minimized.

@lcnr lcnr added the from-crater A regression found via a crater run, not part of our test suite label Apr 19, 2025
@lcnr lcnr changed the title shex_compact regression calling impl Fn in defining scope Apr 25, 2025
@lcnr
Copy link
Contributor

lcnr commented Apr 29, 2025

fn foo() -> impl FnMut() -> usize {
    if false {
        let mut f = foo();
        f();
    }
    
    let mut state = 0;
    move || {
        state += 1;
        state
    }
}

@lcnr
Copy link
Contributor

lcnr commented Apr 29, 2025

fn foo() -> impl FnOnce() {
    if false {
        let mut f = foo();
        f();
    }
    
    let string = String::new();
    move || drop(string)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
from-crater A regression found via a crater run, not part of our test suite
Projects
Status: in progress
2 participants