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

error[E0275]: "overflow evaluating the requirement" triggered by importing a path of length 2 #57854

Open
zhaofengli opened this issue Jan 23, 2019 · 15 comments
Labels
A-type-system Area: Type system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@zhaofengli
Copy link

zhaofengli commented Jan 23, 2019

This might be a duplicate of #39959. I'm posting a new issue here as the mechanism that the error is triggered significantly differs from that in the aforementioned issue.

Sample code

[package]
name = "example"
version = "0.1.0"
authors = ["Author"]
edition = "2018"

[dependencies]
tokio = "=0.1.14"
use std::fs::File;
use std::io::{Read, Write};
use std::path::Path;

// Comment this out... and everything will work fine
use thisdoesntexistyolo::haha;

struct Something<T: Read + Write> {
    thing: T,
}

impl<'a, T: 'a + Read + Write> Something<T>
where
    &'a T: Read,
{
    fn new(thing: T) -> Something<T> {
        Something { thing }
    }
}

fn main() {
    let file = File::open(Path::new("doesntmatter.txt")).unwrap();
    let mut st: Something<File> = Something::new(file);
}

(Playground)

error[E0432]: unresolved import `thisdoesntexistyolo`
 --> src/main.rs:6:5
  |
6 | use thisdoesntexistyolo::haha;
  |     ^^^^^^^^^^^^^^^^^^^ use of undeclared type or module `thisdoesntexistyolo`

warning: unused import: `thisdoesntexistyolo::haha`
 --> src/main.rs:6:5
  |
6 | use thisdoesntexistyolo::haha;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(unused_imports)] on by default

error[E0275]: overflow evaluating the requirement `_: std::marker::Sized`
  --> src/main.rs:23:35
   |
23 |     let mut st: Something<File> = Something::new(file);
   |                                   ^^^^^^^^^^^^^^
   |
   = help: consider adding a `#![recursion_limit="128"]` attribute to your crate
   = note: required because of the requirements on the impl of `std::io::Read` for `&tokio_reactor::poll_evented::PollEvented<_>`
   = note: required because of the requirements on the impl of `std::io::Read` for `&tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<_>>`
   = note: required because of the requirements on the impl of `std::io::Read` for `&tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<_>>>`
   = note: required because of the requirements on the impl of `std::io::Read` for `&tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<_>>>>`
[...]
   = note: required because of the requirements on the impl of `std::io::Read` for `&tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<_>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>`

Details

  • This issue will still occur if the imported package is real.
  • When use thisdoesntexistyolo::haha; is replaced with anything more than 2 levels deep like use thisdoesntexistyolo::a::b;, the code will compile without the error.
@csmoe
Copy link
Member

csmoe commented Jan 23, 2019

cc @shepmaster it seems a playground issue, cannot reproduce on a local machine.

@zhaofengli
Copy link
Author

I can reproduce it locally with Arch Linux's rustc:

rustc 1.32.0
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.32.0
LLVM version: 7.0

I wouldn't have used Playground if I weren't having issue on a local machine. However, I did some testing with other versions, and here are some interesting results:

  • 👎 arch rustc 1.32.0 reproduced
  • 👎 playground rustc 1.32.0 reproduced
  • 👍 rustup rustc 1.32.0 (9fda7c223 2019-01-16) cannot reproduce
  • 👍 rustup rustc 1.24.0 (4d90ac38c 2018-02-12) cannot reproduce
  • 👍 rustup rustc 1.33.0-nightly (4c2be9c97 2019-01-22) cannot reproduce

Looking at Arch Linux's build script for Rust, it appears to be a normal build with a custom config.toml.

@shepmaster
Copy link
Member

cannot reproduce on a local machine.

Have you added both the tokio and tar crates (based on the error messages)?

@shepmaster
Copy link
Member

Yes, adding just Tokio triggers this. I've updated the original comment.

@shepmaster shepmaster changed the title error[E0275]: overflow evaluating the requirement _: std::io::Read error[E0275]: "overflow evaluating the requirement" triggered by importing a non-existing module Jan 23, 2019
@shepmaster shepmaster changed the title error[E0275]: "overflow evaluating the requirement" triggered by importing a non-existing module error[E0275]: "overflow evaluating the requirement" triggered by importing a non-existing import Jan 23, 2019
@shepmaster
Copy link
Member

/cc @davidtwco does this feel like anything around the external crate trait suggestions you worked on?

@davidtwco
Copy link
Member

/cc @davidtwco does this feel like anything around the external crate trait suggestions you worked on?

I don't think so - the extern crate trait suggestions work (#55613) I've done hasn't landed (I feel like there was something like that I had done which landed, but I can't find it, so I suppose not).

@shepmaster
Copy link
Member

hasn't landed

Oh, heh, then pretty unlikely to be related 😊! Sorry to drag you in!

@zhaofengli
Copy link
Author

Looks like the bug definitely depends on a certain package (tokio) being pulled in, but does not necessarily require a non-existent import. In my original code, importing actix-web (use actix_web::{server, Query, State, App};) was what triggered this bug.

@shepmaster shepmaster changed the title error[E0275]: "overflow evaluating the requirement" triggered by importing a non-existing import error[E0275]: "overflow evaluating the requirement" triggered by importing a path of length 2 Jan 24, 2019
@shepmaster
Copy link
Member

but does not necessarily require a non-existent import

Oh, you said that in your original comment; sorry.

@Centril Centril added the A-type-system Area: Type system label Jan 24, 2019
@jonas-schievink jonas-schievink added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Jan 28, 2019
@hcpl
Copy link

hcpl commented Mar 21, 2019

I tried to minimize from my codebase while applying @zhaofengli's ideas, and came to this:

[package]
name = "example"
version = "0.1.0"
authors = ["Author"]
edition = "2018"

[dependencies]
tokio-reactor = "=0.1.9"
impl Foo {}

fn bar<R>(r: &R) {
    std::io::Read::read_exact(&mut r, &mut [])
    //std::io::copy(&mut r, unimplemented!())
    //std::io::BufReader::new(r)
}

Playground: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=a1e1abd1001d712519ac5f18f999bb3a.

Reproducible on latest stable, beta and nightly with either of the three lines in the body of foo.

All elements in this code are required to trigger the requirement evaluation overflow:

  • An unrelated impl for a non-existing type;
  • A generic function;
  • The parameter is a reference to a generic type;
  • Use of r as if it's std::io::Read.

Hope this unblocks the issue!

@hcpl
Copy link

hcpl commented Mar 21, 2019

Minimized even more to a standalone version, reproducible with just rustc:

struct PollEvented<E> {
    phantom: std::marker::PhantomData<E>,
}

impl<'a, E> std::io::Read for &'a PollEvented<E>
where
    &'a E: std::io::Read,
{
    fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
        unimplemented!()
    }
}

fn bar<R>(r: &R) {
    std::io::Read::read_exact(&mut r, &mut [])
    //std::io::copy(&mut r, unimplemented!())
    //std::io::BufReader::new(r)
}

which now looks very similar to #39959 (comment).

Playground: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=f0458c4cc719dcc848c4f3cc6242afba.

@elbaro
Copy link

elbaro commented Mar 29, 2019

Having the same problem. It does not even say which file/line is the problem.
rustc 1.35.0-nightly (82e2f3e 2019-03-20)

❯ cargo build
   Compiling proj v0.2.0 (../proj)
error[E0275]: overflow evaluating the requirement `&tokio_reactor::poll_evented::PollEvented<_>: std::io::Write`
  |
  = help: consider adding a `#![recursion_limit="10"]` attribute to your crate
  = note: required because of the requirements on the impl of `std::io::Write` for `&tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<_>>`
  = note: required because of the requirements on the impl of `std::io::Write` for `&tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<_>>>`
  = note: required because of the requirements on the impl of `std::io::Write` for `&tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<_>>>>`
  = note: required because of the requirements on the impl of `tokio_io::async_write::AsyncWrite` for `&tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<_>>>>>`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0275`.
error: Could not compile `proj`.

To learn more, run the command again with --verbose.

@leshow
Copy link
Contributor

leshow commented Apr 10, 2019

I am also having this issue, on both stable (1.33) and nightly (1.35).

error[E0275]: overflow evaluating the requirement `_: std::marker::Sized`
  |
  = help: consider adding a `#![recursion_limit="128"]` attribute to your crate
  = note: required because of the requirements on the impl of `std::io::Read` for `&tokio_reactor::poll_evented::PollEvented<_>`
  = note: required because of the requirements on the impl of `std::io::Read` for `&tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<_>>`

With the following:

use futures::{try_ready, Async, Future, Poll};
use serde::de::DeserializeOwned;
use tokio::io::{read_exact, AsyncRead};

use std::{io, marker::PhantomData};

#[derive(Debug)]
pub struct Bar<R> {
    stream: R,
}


impl<R> Future for Bar<R>
where
    R: AsyncRead,
{
    type Item = Foo;
    type Error = io::Error;
    fn poll(&mut self) -> Poll<Self::Item, io::Error> {
        let mut buf = [0_u8; 14];
// if you comment out the following line, error goes away:
       let (rd, init) = try_ready!(read_exact(&self.stream, &mut buf).poll());

        Ok(Async::Ready(Foo { }))
    }
}

pub struct Foo {}

It appears to be read_exact that's causing the error. I've provided a minimal version of code with it breaking.

Is there anyway to get around this? The API of what I'm trying to build gets pretty gross if I can't use a generic type param.

edit: playground link https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=7817e212b23d8618e9e42e4cd9061109

@hcpl
Copy link

hcpl commented Apr 10, 2019

@leshow the problem is that there is no impl<'a, T: AsyncRead> AsyncRead for &'a T which would allow your code to work, instead there are specialized impls for a few &'a Foo with Foo being concrete types (here and here). I'm pretty sure this is why rustc goes into infinite recursion by trying to match the parameter R in your code with &PollEvented<R> which in turn matches &PollEvented<PollEvented<R>> etc.

The solution is to use &mut self.stream instead: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=8e9ad05ea7a4c0f473146241a47b3e4c. It works because of impl<'a, T> AsyncRead for &'a mut T where T: AsyncRead + ?Sized.

teddywing added a commit to teddywing/git-suggestion that referenced this issue Aug 5, 2020
We can't read from the original file, because we want to be able to use
that as the writer in `apply()`.

Previously, this would result in the original file simply being
truncated, as we weren't reading from the correct file.

To fix this, we need to give `apply_to()` both a reader and a writer.
Now, in `apply()`, we can pass it the temporary file to read, and the
original to write to.

Used a `Path` as an input to `apply_to()` instead of a `Read`er because
I got an error that didn't really make sense to me when I did so:

    error[E0275]: overflow evaluating the requirement `&tokio_reactor::poll_evented::PollEvented<_>: std::io::Read`
      |
      = help: consider adding a `#![recursion_limit="256"]` attribute to your crate (`git_suggested_patch`)
      = note: required because of the requirements on the impl of `std::io::Read` for `&tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<_>>`
      = note: required because of the requirements on the impl of `std::io::Read` for `&tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<tokio_reactor::poll_evented::PollEvented<_>>>`

A search for the error message turned up a few active issues:

- rust-lang/rust#57854
- rust-lang/rust#62755
- rust-lang/rust#39959

The above issues indicate that this could come from having a variable
with an inferred type. However, for the moment the issue isn't resolved,
and the error message doesn't indicate where the problem is actually
coming from. As I was unable to track down the source of the problem, I
decided not to bother using a `Read` argument.
@estebank
Copy link
Contributor

estebank commented Aug 4, 2021

The original report no longer emits E0275, it only complains about the invalid use, as it should:

error[E0432]: unresolved import `thisdoesntexistyolo`
 --> src/main.rs:6:5
  |
6 | use thisdoesntexistyolo::haha;
  |     ^^^^^^^^^^^^^^^^^^^ use of undeclared crate or module `thisdoesntexistyolo`

The minimized report now looks like this:

error[E0412]: cannot find type `Foo` in this scope
 --> src/lib.rs:1:6
  |
1 | impl Foo {}
  |      ^^^ not found in this scope

error[E0277]: the trait bound `&R: std::io::Read` is not satisfied
   --> src/lib.rs:4:13
    |
4   |     let _ = std::io::Read::read_exact(&mut r, &mut []);
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::io::Read` is not implemented for `&R`
    |
note: required by `read_exact`
help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement
    |
3   | fn bar<R>(r: &R) where &R: std::io::Read {
    |                  ^^^^^^^^^^^^^^^^^^^^^^^

error[E0277]: the trait bound `&R: std::io::Read` is not satisfied
  --> src/lib.rs:5:13
   |
5  |     let _ = std::io::copy(&mut r, unimplemented!());
   |             ^^^^^^^^^^^^^ the trait `std::io::Read` is not implemented for `&R`
   |
help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement
   |
3  | fn bar<R>(r: &R) where &R: std::io::Read {
   |                  ^^^^^^^^^^^^^^^^^^^^^^^

warning: unreachable call
 --> src/lib.rs:5:13
  |
5 |     let _ = std::io::copy(&mut r, unimplemented!());
  |             ^^^^^^^^^^^^^         ---------------- any code following this expression is unreachable
  |             |
  |             unreachable call
  |
  = note: `#[warn(unreachable_code)]` on by default

error[E0277]: the trait bound `&R: std::io::Read` is not satisfied
  --> src/lib.rs:6:37
   |
6  |     let _ = std::io::BufReader::new(r);
   |                                     ^ the trait `std::io::Read` is not implemented for `&R`
   |
note: required by `BufReader::<R>::new`
help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement
   |
3  | fn bar<R>(r: &R) where &R: std::io::Read {
   |                  ^^^^^^^^^^^^^^^^^^^^^^^

If we apply the suggestions naively, we get further errors:

error[E0637]: `&` without an explicit lifetime name cannot be used here
 --> src/lib.rs:3:24
  |
3 | fn bar<R>(r: &R) where &R: std::io::Read {
  |                        ^ explicit lifetime name needed here

error[E0310]: the parameter type `R` may not live long enough
 --> src/lib.rs:3:28
  |
3 | fn bar<R>(r: &R) where &R: std::io::Read {
  |        -                   ^^^^^^^^^^^^^ ...so that the reference type `&'static R` does not outlive the data it points at
  |        |
  |        help: consider adding an explicit lifetime bound...: `R: 'static`

But if we fix those, we get (which I believe is reasonable):

error[E0412]: cannot find type `Foo` in this scope
 --> src/lib.rs:1:6
  |
1 | impl Foo {}
  |      ^^^ not found in this scope

warning: unreachable call
 --> src/lib.rs:5:13
  |
5 |     let _ = std::io::copy(&mut r, unimplemented!());
  |             ^^^^^^^^^^^^^         ---------------- any code following this expression is unreachable
  |             |
  |             unreachable call
  |
  = note: `#[warn(unreachable_code)]` on by default

error[E0283]: type annotations needed
  --> src/lib.rs:5:13
   |
5  |     let _ = std::io::copy(&mut r, unimplemented!());
   |             ^^^^^^^^^^^^^ cannot infer type for type parameter `W` declared on the function `copy`
   |
   = note: cannot satisfy `_: std::io::Write`
help: consider specifying the type arguments in the function call
   |
5  |     let _ = std::io::copy::<R, W>(&mut r, unimplemented!());
   |                          ^^^^^^^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

10 participants