Skip to content
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

Regression of "mismatched types" error on trait method call with multiple candidates #101066

Closed
divergentdave opened this issue Aug 27, 2022 · 2 comments · Fixed by #100966
Closed
Assignees
Labels
C-bug Category: This is a bug. P-critical Critical priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@divergentdave
Copy link
Contributor

Code

I tried this code:

pub trait FieldElement {
    type Integer: TryFrom<usize, Error = std::num::TryFromIntError>;

    fn valid_integer_try_from<N>(i: N) -> Result<Self::Integer, ()>
    where
        Self::Integer: TryFrom<N>,
    {
        Self::Integer::try_from(i).map_err(|_| ())
    }
}

I expected to see this happen: Successful compilation.

Instead, this happened: I now get the following compiler error.

error[E0308]: mismatched types
   --> src/lib.rs:8:33
    |
4   |     fn valid_integer_try_from<N>(i: N) -> Result<Self::Integer, ()>
    |                               - this type parameter
...
8   |         Self::Integer::try_from(i).map_err(|_| ())
    |         ----------------------- ^ expected `usize`, found type parameter `N`
    |         |
    |         arguments to this function are incorrect
    |
    = note:        expected type `usize`
            found type parameter `N`
note: associated function defined here
   --> /home/david/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/convert/mod.rs:478:8
    |
478 |     fn try_from(value: T) -> Result<Self, Self::Error>;
    |        ^^^^^^^^

For more information about this error, try `rustc --explain E0308`.
error: could not compile `nightly-prio-regression` due to previous error

Version it worked on

It most recently worked on: stable channel Rust 1.63.0, and nightly-2022-08-17.

Version with regression

searched nightlies: from nightly-2022-08-11 to nightly-2022-08-26
regressed nightly: nightly-2022-08-18
searched commit range: 86c6ebe...9c20b2a
regressed commit: 9c20b2a

bisected with cargo-bisect-rustc v0.6.4

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc 

@rustbot modify labels: +regression-from-stable-to-nightly -regression-untriaged

While reducing this example, I noticed that the following changes to the code will make the error go away:

  • Replacing the function call with N::try_into(i)
  • Deleting the specification of Error in the associated type's trait bound
  • Adding the same Error specification in the where clause's trait bound
@divergentdave divergentdave added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Aug 27, 2022
@rustbot rustbot added I-prioritize Issue: Indicates that prioritization has been requested for this issue. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. and removed regression-untriaged Untriaged performance or correctness regression. labels Aug 27, 2022
@compiler-errors
Copy link
Member

This is caused by #100652, and therefore fixed by #100966.

@apiraino
Copy link
Contributor

WG-prioritization assigning priority (Zulip discussion) to add visibility to the relevant pr fixing it

@rustbot label -I-prioritize +P-critical t-compiler

@rustbot rustbot added P-critical Critical priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Aug 31, 2022
@bors bors closed this as completed in 0209485 Sep 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. P-critical Critical priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants