Skip to content

closures accept ill-formed inputs #104478

Open
@aliemjay

Description

@aliemjay

Both of these closures should fail borrowck: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=e9855ecda2f9427454cebce7738e598d

struct MyTy<T: Trait>(T);
trait Trait {}
impl Trait for &'static str {}
fn wf<T>(_: T) {}

fn test() {
    let _: for<'x> fn(MyTy<&'x str>) = |_| {}; // PASS!
    
    // but it should fail for the same reason this fails:
    let _: for<'x> fn(MyTy<&'x str>) = |x| wf(x); // FAIL
}

I think we should simply do WF-checking of closure input/output types in the closure environment, but doing so would cause accidental breakages due to #104477. So #104477 should be resolved first.

@rustbot label A-NLL NLL-sound C-bug T-types A-borrow-checker

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-NLLArea: Non-lexical lifetimes (NLL)A-borrow-checkerArea: The borrow checkerC-bugCategory: This is a bug.NLL-soundWorking towards the "invalid code does not compile" goalT-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions