Skip to content

Type inference recovery can infer unsized locals #22518

@Veykril

Description

@Veykril

Bit of a weird one and might be pointless to think about but in the following erroneous snippet

trait DynT {}
fn f(_: &dyn DynT) {}
fn main() {
    let unresolved = unresolved;
    f(&unresolved);
    unresolved.foo();
}

we assign dyn DynT to unresolved. I feel like this is a bad recovery, since we can't have unsized locals, imo it would be better in this case to fallback to an error type? Interestingly enough if we assign an error type reference to unresolved we also fall back to the same type instead of assigning an error type to the local, probably because unification takes over still.

cc @ChayimFriedman2 idk if you have opinions on this, if you think this is fine as is feel free to close :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-tytype system / type inference / traits / method resolutionC-bugCategory: bugS-unactionableIssue requires feedback, design decisions or is blocked on other work

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions