Closed
Description
Given the following code snippet:
use num_rational as _;
struct Foo;
impl Foo {
fn downcast<W>(&self) -> &W {
todo!()
}
}
struct Other;
fn main() {
let other: &mut Other = Foo.downcast();
}
One would expect the code to error, explaining that the types differ in mutability (we will come back to this in a moment).
However, it instead leaves a long and confusing error:
error[E0275]: overflow evaluating the requirement `&Ratio<_>: num_traits::pow::Pow<u32>`
--> src/main.rs:14:29
|
14 | let other: &mut Other = Foo.downcast();
| ^^^^^^^^^^^^^^
|
= help: consider adding a `#![recursion_limit="256"]` attribute to your crate (`bug`)
= note: required because of the requirements on the impl of `num_traits::pow::Pow<u32>` for `&Ratio<Ratio<_>>`
= note: 127 redundant requirements hidden
= note: required because of the requirements on the impl of `num_traits::pow::Pow<&i32>` for `&Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<Ratio<_>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0275`.
error: could not compile `bug`
To learn more, run the command again with --verbose.
If you follow the suggestion of increasing the recursion limit each time, it will eventually segfault once you have #![recursion_limit="2048"]
error: could not compile `bug`
Caused by:
process didn't exit successfully: `rustc --crate-name bug --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=f6406766fb3e32c0 -C extra-filename=-f6406766fb3e32c0 --out-dir /home/zippy/bug/target/debug/deps -C incremental=/home/zippy/bug/target/debug/incremental -L dependency=/home/zippy/bug/target/debug/deps --extern num_rational=/home/zippy/bug/target/debug/deps/libnum_rational-13f69084195ac9b5.rlib` (signal: 11, SIGSEGV: invalid memory reference)
Furthermore, removing the import of num-rational
leads to the program erroring as expected
error[E0308]: mismatched types
--> src/main.rs:12:29
|
12 | let other: &mut Other = Foo.downcast();
| ---------- ^^^^^^^^^^^^^^ types differ in mutability
| |
| expected due to this
|
= note: expected mutable reference `&mut Other`
found reference `&_`
For more information about this error, try `rustc --explain E0308`.
error: could not compile `bug` due to previous error
Meta
rustc --version --verbose
:
rustc 1.57.0-nightly (addb4da68 2021-09-25)
binary: rustc
commit-hash: addb4da686a97da46159f0123cb6cdc2ce3d7fdb
commit-date: 2021-09-25
host: x86_64-unknown-linux-gnu
release: 1.57.0-nightly
LLVM version: 13.0.0
This error exists on stable, too.
Backtrace
The code doesn't compile, and as such there's no backtrace