Skip to content

Types pass through generic functions in 1.49 on #80821

Closed
@chrysn

Description

@chrysn

The following code compiles in 1.49 and newer (tested1.49 and two recent nightlies) but does not in 1.48 or older (easily testable with godbolt)

fn x<A, E>(_a: A) -> Result<(), E>
where
   A: T<E = E>
{
    Ok(())
}

struct X;

trait T {
    type E: core::fmt::Debug;
}

impl T for X {
    type E = ();
}

pub fn main() {
    let a = X;
    
    x(a).expect("Practically it will work, but how might it fail?");
}

with older versions giving "E doesn't implement Debug". It seems that in 1.49, the concrete E used as a consequence of how the X in a implements T is inferred by this version and used to satisfy the expect's requirement of implementing Debug.

I've gone through the change logs between 1.48 and 1.49, and nothing there hints at such behavior. If the change is unintentional, it should be known as a bug (because it'd produce regressions once it's flipped back). If it is intentional, it should be documented in the change log (can that be amended later on?) to make users with a keen eye for MSRVs aware it's there and compatibility with older versions can suffer (or I should get better at reading change logs).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions