Rust: Overflow on double nested container types

Created on 7 Jun 2016  路  3Comments  路  Source: rust-lang/rust

I have the following code:

https://play.rust-lang.org/?gist=b8c78d5084a9b9ab7c53a2a9faa022af&version=stable&backtrace=0

As it can be seen the #[test] works fine, but if I try to run a cargo test on it I get the following error on the doc_test:

failures:

---- vec::<&'a Vector>::add_0 stdout ----
error: overflow evaluating the requirement <&_ as std::ops::Add<_>>::Output [E0275]
:1:1: 1:1 note: consider adding a #![recursion_limit="128"] attribute to your crate
error: aborting due to previous error

It seems like which function will fail depends on the compiler. I have the impression that at home both implemententions of Add for &Vector will fail, but I might be mistaken and will update this issue when I get home.

This is the rust version I'm using here:

rustc 1.10.0-dev (14f61c87f 2016-04-18)
binary: rustc
commit-hash: 14f61c87ff02e57d565d4fab4ce790156c9a596e
commit-date: 2016-04-18
host: x86_64-unknown-linux-gnu
release: 1.10.0-dev

The discussion on the rust forums can be found here:
https://users.rust-lang.org/t/weird-problems-with-recursion-in-type-bounds-in-tests-on-libs/6101/4

update: I was mistaken, at home I get the same behavior. But like @mbrubeck said on the forum discussion, if I remove the last two Add impls everything works.

A-typesystem C-bug T-compiler

All 3 comments

In case it is useful, this much shorter program gives similar behaviour:
https://play.rust-lang.org/?gist=2f793999729aec2cd8274157f7012e5d&version=stable&backtrace=0

Compare this version, which compiles and runs just fine:
https://play.rust-lang.org/?gist=6ff433c8cc94c22985180210cc3a8e7d&version=stable&backtrace=0

Here's a further minimization of @apt1002 's program:

https://play.rust-lang.org/?gist=0a77e1bd0f8e539d8a85ee30ed63b1f6&version=stable&backtrace=0

A common thread on all these failing programs is that there are 2 layers of "containerization", whether that be &, Vector, or a wrapper struct.

Good idea to remove the lifetime nonsense. Much clearer.

I think we've both made errors! Mine was that "where Target: From<&'m T>" should have been "where Target: for<'a> From<&'a T>". I only just learned about this. Yours is that "(a.0).0" should be "C((a.0).0)".

The error message is unchanged in both cases, i.e. it still looks like a compiler bug. I think these examples should work, but at the very least the compiler is not giving the right error message.

Was this page helpful?
0 / 5 - 0 ratings