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

When call from out of crate, E0275 occurs #104981

Open
Toru3 opened this issue Nov 27, 2022 · 0 comments
Open

When call from out of crate, E0275 occurs #104981

Toru3 opened this issue Nov 27, 2022 · 0 comments
Labels
A-traits Area: Trait system C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@Toru3
Copy link

Toru3 commented Nov 27, 2022

I tried this code:

$ tree
.
├── Cargo.toml
└── src
    ├── bin
    │   └── a.rs
    └── lib.rs

2 directories, 3 files

Cargo.toml

[package]
name = "baz"
version = "0.1.0"
authors = []
edition = "2018"

[dependencies]

[features]
default = []
bar = []

src/lib.rs

use std::ops::Add;

#[derive(Clone, Debug)]
pub struct S<T>(pub T);

// If comment outed, no error
impl<T> Add<&S<T>> for &S<T>
where
    T: for<'x> From<<&'x T as Add>::Output>,
    for<'x> &'x T: Add,
{
    type Output = S<T>;
    fn add(self, _: &S<T>) -> Self::Output {
        unimplemented!()
    }
}

// If comment outed, no error
impl<T> Add<&S<T>> for S<T>
where
    T: for<'x> From<<&'x T as Add>::Output>,
    for<'x> &'x T: Add,
{
    type Output = Self;
    fn add(self, _: &S<T>) -> Self::Output {
        unimplemented!()
    }
}

impl<T> Add<S<T>> for S<T>
where
    T: for<'x> From<<&'x T as Add>::Output>,
    for<'x> &'x T: Add,
{
    type Output = Self;
    fn add(self, _: S<T>) -> Self::Output {
        unimplemented!()
    }
}

pub fn foo() {
    dbg!(S(2i32) + S(3i32)); // OK
}

src/bin/a.rs

fn main() {
    #[cfg(not(feature = "bar"))]
    {
        use baz::S;
        use std::ops::Add;
        dbg!(S(2i32) + S(3i32)); // E0275
        dbg!(S(2i32).add(S(3i32))); // E0275
        dbg!(std::ops::Add::<S<i32>>::add(S(2i32), S(3i32))); // OK
    }
    #[cfg(feature = "bar")]
    {
        use baz::foo;
        // suppress optimize
        let v = std::env::args().collect::<Vec<_>>();
        if v.len() == 42 {
            foo();
        }
        println!("Hello, world!");
    }
}

I expected to see this happen: no compile error

Instead, this happened: E0275

Meta

rustc --version --verbose:

rustc 1.67.0-nightly (b3bc6bf31 2022-11-24)
binary: rustc
commit-hash: b3bc6bf31265ac10946a0832092dbcedf9b26805
commit-date: 2022-11-24
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4
rustc 1.66.0-beta.2 (0040709e3 2022-11-20)
binary: rustc
commit-hash: 0040709e39bfa159d099ee14628ad4ac72f91406
commit-date: 2022-11-20
host: x86_64-unknown-linux-gnu
release: 1.66.0-beta.2
LLVM version: 15.0.2
rustc 1.65.0 (897e37553 2022-11-02)
binary: rustc
commit-hash: 897e37553bba8b42751c67658967889d11ecd120
commit-date: 2022-11-02
host: x86_64-unknown-linux-gnu
release: 1.65.0
LLVM version: 15.0.0
log nightly

$ rustc --version --verbose
rustc 1.67.0-nightly (b3bc6bf31 2022-11-24)
binary: rustc
commit-hash: b3bc6bf31265ac10946a0832092dbcedf9b26805
commit-date: 2022-11-24
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4
$ cargo clean
$ cargo run --bin a
   Compiling baz v0.1.0 (/home/Toru3/polynomial-ring2)
error[E0275]: overflow evaluating the requirement `for<'x> &'x Simd<_, _>: Add`
  |
  = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`a`)
  = note: required for `&'x S<Simd<_, _>>` to implement `for<'x> Add`
  = note: 127 redundant requirements hidden
  = note: required for `&'x S<S<S<S<S<...>>>>>` to implement `for<'x> Add`
  = note: the full type name has been written to '/home/Toru3/polynomial-ring2/target/debug/deps/a-84f17e47597c1027.long-type-12017482340628741203.txt'

For more information about this error, try `rustc --explain E0275`.
error: could not compile `baz` due to previous error
$ cargo clean
$ cargo run --bin a --features bar
   Compiling baz v0.1.0 (/home/Toru3/polynomial-ring2)
    Finished dev [unoptimized + debuginfo] target(s) in 0.68s
     Running `target/debug/a`
Hello, world!

log beta

$ rustc --version --verbose
rustc 1.66.0-beta.2 (0040709e3 2022-11-20)
binary: rustc
commit-hash: 0040709e39bfa159d099ee14628ad4ac72f91406
commit-date: 2022-11-20
host: x86_64-unknown-linux-gnu
release: 1.66.0-beta.2
LLVM version: 15.0.2
$ cargo clean
$ cargo run --bin a
   Compiling baz v0.1.0 (/home/Toru3/polynomial-ring2)
error[E0275]: overflow evaluating the requirement `for<'x> &'x Simd<_, _>: Add`
  |
  = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`a`)
  = note: required for `&'x S<Simd<_, _>>` to implement `for<'x> Add`
  = note: 127 redundant requirements hidden
  = note: required for `&'x S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<Simd<_, _>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>` to implement `for<'x> Add`

For more information about this error, try `rustc --explain E0275`.
error: could not compile `baz` due to previous error
$ cargo clean
$ cargo run --bin a --features bar
   Compiling baz v0.1.0 (/home/Toru3/polynomial-ring2)
    Finished dev [unoptimized + debuginfo] target(s) in 0.64s
     Running `target/debug/a`
Hello, world!

log stable

$ rustc --version --verbose
rustc 1.65.0 (897e37553 2022-11-02)
binary: rustc
commit-hash: 897e37553bba8b42751c67658967889d11ecd120
commit-date: 2022-11-02
host: x86_64-unknown-linux-gnu
release: 1.65.0
LLVM version: 15.0.0
$ cargo clean
$ cargo run --bin a
   Compiling baz v0.1.0 (/home/Toru3/polynomial-ring2)
error[E0275]: overflow evaluating the requirement `for<'x> &'x Simd<_, _>: Add`
  |
  = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`a`)
  = note: required for `&'x S<Simd<_, _>>` to implement `for<'x> Add`
  = note: 127 redundant requirements hidden
  = note: required for `&'x S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<Simd<_, _>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>` to implement `for<'x> Add`

For more information about this error, try `rustc --explain E0275`.
error: could not compile `baz` due to previous error
$ cargo clean
$ cargo run --bin a --features bar
   Compiling baz v0.1.0 (/home/Toru3/polynomial-ring2)
    Finished dev [unoptimized + debuginfo] target(s) in 0.66s
     Running `target/debug/a`
Hello, world!

@Toru3 Toru3 added the C-bug Category: This is a bug. label Nov 27, 2022
@ChrisDenton ChrisDenton added the needs-triage-legacy Old issue that were never triaged. Remove this label once the issue has been sufficiently triaged. label Jul 16, 2023
@fmease fmease added A-traits Area: Trait system E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example T-types Relevant to the types team, which will review and decide on the PR/issue. and removed needs-triage-legacy Old issue that were never triaged. Remove this label once the issue has been sufficiently triaged. labels Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-traits Area: Trait system C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example 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

3 participants