Skip to content

Types pass through generic functions in 1.49 on #80821

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

Closed
chrysn opened this issue Jan 8, 2021 · 3 comments
Closed

Types pass through generic functions in 1.49 on #80821

chrysn opened this issue Jan 8, 2021 · 3 comments

Comments

@chrysn
Copy link
Contributor

chrysn commented Jan 8, 2021

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).

@Aaron1011
Copy link
Member

I think this is related to #78893

@chrysn
Copy link
Contributor Author

chrysn commented Jan 8, 2021 via email

@chrysn
Copy link
Contributor Author

chrysn commented Jan 9, 2021

Closing as duplicate, see also #78893 (comment)

@chrysn chrysn closed this as completed Jan 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants