Skip to content

Nonsensical error in rustc output. #75397

Closed
@zakarumych

Description

@zakarumych

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions