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

Nonsensical error in rustc output. #75397

Closed
zakarumych opened this issue Aug 11, 2020 · 2 comments
Closed

Nonsensical error in rustc output. #75397

zakarumych opened this issue Aug 11, 2020 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait 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

@zakarumych
Copy link
Contributor

Given a code with few issues I got completely unrelated error bound to line with one of those issues.

I tried this code:

#![recursion_limit="8"] // default value makes compilation longer.

extern crate num_traits; // 0.2.12

struct Foo(u8);

#[repr(transparent)]
struct Bar(Foo);

impl Bar {
    fn cast(foo: &mut Foo) -> &mut Self {
        unsafe { &*(foo as *mut _ as *mut _) } // It should be error about coercing `&_` to `&mut _`
    }
}

impl Baz {} // If you delete this, or replace `Baz` with existing type - weired error vanishes.

I expected to see this happen:

error[E0308]: mismatched types
  --> src/lib.rs:12:18
   |
12 |         unsafe { &*(foo as *mut _ as *mut _) } // It should be error about coercing `&_` to `&mut _`
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^ types differ in mutability
   |
   = note: expected mutable reference `&mut Bar`
                      found reference `&_`

Instead, this happened:

error[E0275]: overflow evaluating the requirement `&num_rational::Ratio<_>: num_traits::Pow<u128>`
  --> src/lib.rs:12:18
   |
12 |         unsafe { &*(foo as *mut _ as *mut _) } // It should be error about coercing `&_` to `&mut _`
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: consider adding a `#![recursion_limit="16"]` attribute to your crate (`playground`)
   = note: required because of the requirements on the impl of `num_traits::Pow<u128>` for `&num_rational::Ratio<num_rational::Ratio<_>>`
   = note: required because of the requirements on the impl of `num_traits::Pow<u128>` for `&num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<_>>>`
   = note: required because of the requirements on the impl of `num_traits::Pow<u128>` for `&num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<_>>>>`
   = note: required because of the requirements on the impl of `num_traits::Pow<u128>` for `&num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<_>>>>>`
   = note: required because of the requirements on the impl of `num_traits::Pow<u128>` for `&num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<_>>>>>>`
   = note: required because of the requirements on the impl of `num_traits::Pow<u128>` for `&num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<_>>>>>>>`
   = note: required because of the requirements on the impl of `num_traits::Pow<u128>` for `&num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<_>>>>>>>>`
   = note: required because of the requirements on the impl of `num_traits::Pow<&i128>` for `&num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<_>>>>>>>>>`

Meta

Simplified reproduction.
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=4ded409a017da7b3d6d0a4dcbfc1bebb

@zakarumych zakarumych added the C-bug Category: This is a bug. label Aug 11, 2020
@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-trait-system Area: Trait system labels Aug 11, 2020
@rukai
Copy link
Contributor

rukai commented Sep 5, 2020

I also hit this issue on stable rust 1.46
I wasnt able to reproduce it with a smaller sample. (Although I didnt try super hard)
But for me it occurred when I passed the result of String::as_ref to a function expecting a String.

   Compiling canon_collision v0.0.1 (/home/rukai2/Projects/Crates/canon_collision/canon_collision/canon_collision)
error[E0275]: overflow evaluating the requirement `&num_rational::Ratio<_>: entity::item::_IMPL_NUM_FromPrimitive_FOR_ItemAction::_num_traits::Pow<u32>`
   --> canon_collision/src/game.rs:104:56
    |
104 |                     ty: EntityType::Player(Player::new(fighter.as_ref(), team, i, &stage, &package, &setup.rules)),
    |                                                        ^^^^^^^^^^^^^^^^
    |
    = help: consider adding a `#![recursion_limit="256"]` attribute to your crate (`canon_collision`)
    = note: required because of the requirements on the impl of `entity::item::_IMPL_NUM_FromPrimitive_FOR_ItemAction::_num_traits::Pow<u32>` for `&num_rational::Ratio<num_rational::Ratio<_>>`
    = note: required because of the requirements on the impl of `entity::item::_IMPL_NUM_FromPrimitive_FOR_ItemAction::_num_traits::Pow<u32>` for `&num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<_>>>`
    = note: required because of the requirements on the impl of `entity::item::_IMPL_NUM_FromPrimitive_FOR_ItemAction::_num_traits::Pow<u32>` for `&num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<_>>>>`
    = note: required because of the requirements on the impl of `entity::item::_IMPL_NUM_FromPrimitive_FOR_ItemAction::_num_traits::Pow<u32>` for `&num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<_>>>>>`
    = note: required because of the requirements on the impl of `entity::item::_IMPL_NUM_FromPrimitive_FOR_ItemAction::_num_traits::Pow<u32>` for `&num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<_>>>>>>`
    = note: required because of the requirements on the impl of `entity::item::_IMPL_NUM_FromPrimitive_FOR_ItemAction::_num_traits::Pow<u32>` for `&num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<_>>>>>>>`
    = note: required because of the requirements on the impl of `entity::item::_IMPL_NUM_FromPrimitive_FOR_ItemAction::_num_traits::Pow<u32>` for `&num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<_>>>>>>>>`
    = note: required because of the requirements on the impl of `entity::item::_IMPL_NUM_FromPrimitive_FOR_ItemAction::_num_traits::Pow<u32>` for `&num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<_>>>>>>>>>`
    = note: required because of the requirements on the impl of `entity::item::_IMPL_NUM_FromPrimitive_FOR_ItemAction::_num_traits::Pow<u32>` for `&num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<_>>>>>>>>>>`
    = note: required because of the requirements on the impl of `entity::item::_IMPL_NUM_FromPrimitive_FOR_ItemAction::_num_traits::Pow<u32>` for `&num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<_>>>>>>>>>>>`
    = note: required because of the requirements on the impl of `entity::item::_IMPL_NUM_FromPrimitive_FOR_ItemAction::_num_traits::Pow<u32>` for `&num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<_>>>>>>>>>>>>`
    = note: required because of the requirements on the impl of `entity::item::_IMPL_NUM_FromPrimitive_FOR_ItemAction::_num_traits::Pow<u32>` for `&num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<_>>>>>>>>>>>>>`
    = note: required because of the requirements on the impl of `entity::item::_IMPL_NUM_FromPrimitive_FOR_ItemAction::_num_traits::Pow<u32>` for `&num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<_>>>>>>>>>>>>>>`
    = note: required because of the requirements on the impl of `entity::item::_IMPL_NUM_FromPrimitive_FOR_ItemAction::_num_traits::Pow<u32>` for `&num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<_>>>>>>>>>>>>>>>`
    = note: required because of the requirements on the impl of `entity::item::_IMPL_NUM_FromPrimitive_FOR_ItemAction::_num_traits::Pow<u32>` for `&num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<_>>>>>>>>>>>>>>>>`
    = note: required because of the requirements on the impl of `entity::item::_IMPL_NUM_FromPrimitive_FOR_ItemAction::_num_traits::Pow<u32>` for `&num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<_>>>>>>>>>>>>>>>>>`
    = note: required because of the requirements on the impl of `entity::item::_IMPL_NUM_FromPrimitive_FOR_ItemAction::_num_traits::Pow<u32>` for `&num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<_>>>>>>>>>>>>>>>>>>`
    = note: required because of the requirements on the impl of `entity::item::_IMPL_NUM_FromPrimitive_FOR_ItemAction::_num_traits::Pow<u32>` for `&num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<_>>>>>>>>>>>>>>>>>>>`
    = note: required because of the requirements on the impl of `entity::item::_IMPL_NUM_FromPrimitive_FOR_ItemAction::_num_traits::Pow<u32>` for `&num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<_>>>>>>>>>>>>>>>>>>>>`
    = note: required because of the requirements on the impl of `entity::item::_IMPL_NUM_FromPrimitive_FOR_ItemAction::_num_traits::Pow<u32>` for `&num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<_>>>>>>>>>>>>>>>>>>>>>`
    = note: required because of the requirements on the impl of `entity::item::_IMPL_NUM_FromPrimitive_FOR_ItemAction::_num_traits::Pow<u32>` for `&num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<_>>>>>>>>>>>>>>>>>>>>>>`
    = note: required because of the requirements on the impl of `entity::item::_IMPL_NUM_FromPrimitive_FOR_ItemAction::_num_traits::Pow<u32>` for `&num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<num_rational::Ratio<_>>>>>>>>>>>>>>>>>>>>>>>`

@estebank
Copy link
Contributor

estebank commented Oct 9, 2021

Now that #89576 has landed, I think this issue can be resolved. Can you try to reproduce with a recent nightly? If it's still present, please reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait 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

4 participants