Skip to content

overflow evaluating the requirement when trait bound is added #79807

@is8ac

Description

@is8ac

Source

pub trait Baz<S> {
    type Quaks;
}

impl Baz<[(); 8]> for bool {
    type Quaks = u8;
}

impl<T, S> Baz<[S; 3]> for T
where
    T: Baz<S>,
    <T as Baz<S>>::Quaks: Copy,
{
    type Quaks = [<T as Baz<S>>::Quaks; 3];
}

pub trait Bar
where
    Self: Sized,
    bool: Baz<Self>,
{
    fn foo(bits: <bool as Baz<Self>>::Quaks);
}

impl Bar for [(); 8] {
    fn foo(_: u8) {}
}

impl<S: Bar> Bar for [S; 3]
where
    bool: Baz<S>,
{
    fn foo(_: <bool as Baz<Self>>::Quaks) {}
}

fn main() {}

rustc overflow_demo.rs returns:

error[E0275]: overflow evaluating the requirement `bool: PackedElement<[_; 8]>`
  |
  = help: consider adding a `#![recursion_limit="256"]` attribute to your crate (`overflow_demo`)
  = note: required because of the requirements on the impl of `PackedElement<[[_; 8]; 8]>` for `bool`
  = note: 127 redundant requirements hidden
  = note: required because of the requirements on the impl of `PackedElement<[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[_; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]; 8]>` for `bool`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0275`.

Now remove the line

    <T as Baz<S>>::Quaks: Copy,

and it compiles without error. Copy can be replaced with most any other trait bound.

Separately, where as normally such overflow evaluating the requirement errors give a line number, here, no line number is given.

Meta

rustc --version --verbose:

rustc 1.48.0 (7eac88abb 2020-11-16)
binary: rustc
commit-hash: 7eac88abb2e57e752f3302f02be5f3ce3d7adfb4
commit-date: 2020-11-16
host: x86_64-unknown-linux-gnu
release: 1.48.0
LLVM version: 11.0

Approximately the same behavior in nightly

rustc 1.50.0-nightly (5be3f9f10 2020-12-03)
binary: rustc
commit-hash: 5be3f9f10e9fd59ea03816840a6051413fbdefae
commit-date: 2020-12-03
host: x86_64-unknown-linux-gnu
release: 1.50.0-nightly

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions