Skip to content

borrowck can impact type inference #22

@lcnr

Description

@lcnr

opaque types + leak check is somewaht tragic

struct SendIfEq<'a, 'b>(Option<*mut (&'a (), &'b ())>);
unsafe impl<'a> Send for SendIfEq<'a, 'a> {}

trait Trait<'a, 'hr> {}
impl<'a, 'hr, F, R> Trait<'a, 'hr> for F
where
    F: FnOnce(&'a (), &'hr ()) -> R,
    R: Send,
{}

trait HigherRanked<'a, T> {}
impl<'a, F: for<'hr> Trait<'a, 'hr>> HigherRanked<'a, u32> for F {}
impl<'a, F> HigherRanked<'a, i32> for F {}

fn check_bound<'a, T>(_: impl HigherRanked<'a, T>) -> T { todo!() }

fn different<'a, 'b>(_: &'a (), _: &'b ()) -> impl Sized {
    SendIfEq::<'a, 'b>(None)
}

fn equal<'a, 'b>(_: &'a (), _: &'b ()) -> impl Sized {
    SendIfEq::<'a, 'a>(None)
}

fn ok() {
    check_bound(different);
}

fn ambig() {
    check_bound(equal);
}

fn ok currently compiles with -Znext-solver while ambig never does. I think that's because the leak check in evaluate is quite jank and we don't return constraints from nested trait goals.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions