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

Overflow evaluation when using a wrapper function #117883

Open
danielmasny opened this issue Nov 13, 2023 · 1 comment
Open

Overflow evaluation when using a wrapper function #117883

danielmasny opened this issue Nov 13, 2023 · 1 comment
Labels
C-bug Category: This is a bug. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@danielmasny
Copy link

I tried this code:

pub struct AdditiveShare<T>(T);

pub trait SharedValue {}

pub trait IntoIteratorB {
    fn into_iter_b(&self) {}
}

impl <'a, T> IntoIteratorB for &'a AdditiveShare<T>
    where
        &'a T: IntoIteratorB,
        T: SharedValue,
{}


fn addition<'a, T>(x: &'a AdditiveShare<T>)
    where
            &'a T: IntoIteratorB,
            T: SharedValue,
{
    addition_circuit(x);
}

fn addition_circuit<'a, T>(x: &'a AdditiveShare<T>)
    where
            &'a T: IntoIteratorB,
            T: SharedValue,
{
    x.into_iter_b();
}

impl SharedValue for u32{}

impl<'a> IntoIteratorB for &'a u32{
    fn into_iter_b(&self){}
}

fn main ()
{
    let u=AdditiveShare(0u32);
    (&u).into_iter_b();
    println!("Hello, world!");
}

I expected to see this happen: that it would compile

Instead, this happened: error[E0275]: overflow evaluating the requirement &AdditiveShare<_>: IntoIteratorB

Interestingly, commenting out the wrapper function does not result in a compilation error:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=887c6cfabce6e3eb64b561d278f28807

however, this does:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=d3d7e05d015b3eb397eb8fe5b7433f6a

It might be related to #39959, however this code works when commenting out the wrapper function.

Meta

rustc --version --verbose:

rustc 1.75.0-nightly (fdaaaf9f9 2023-11-08)
binary: rustc
commit-hash: fdaaaf9f923281ab98b865259aa40fbf93d72c7a
commit-date: 2023-11-08
host: aarch64-apple-darwin
release: 1.75.0-nightly
LLVM version: 17.0.4
Backtrace

<backtrace>

@danielmasny danielmasny added the C-bug Category: This is a bug. label Nov 13, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 13, 2023
@compiler-errors
Copy link
Member

(For the record: this works with the new trait solver, -Ztrait-solver=next, because of the non-fatal overflow. I don't recommend users try building their code with that, yet, since it's still pretty broken.)

@compiler-errors compiler-errors added the fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. label Nov 13, 2023
@saethlin saethlin added T-types Relevant to the types team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Nov 13, 2023
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. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants