Skip to content

rustc fails to see a bound that is present, but also requires that the bound not be present #41118

Open
@Twey

Description

@Twey

In certain cases, rustc will emit an error message on what appears to be valid code, claiming that

  • a bound that is present is not present, and must be present
  • but the bound is present and must not be present

Here is a MWE (or playground):

trait Foo<T> { type Quux; }
trait Bar<B> {
    type Baz;
    fn arthur() where B: Foo<Self::Baz>, B::Quux: Send;
}
impl<B> Bar<B> for () {
    type Baz = ();
    fn arthur() where B: Foo<()>, B::Quux: Send { }
}

This produces the pair of errors:

rustc 1.16.0 (30cf806ef 2017-03-10)
error[E0277]: the trait bound `B: Foo<()>` is not satisfied
 --> <anon>:8:5
  |
8 |     fn arthur() where B: Foo<()>, B::Quux: Send { }
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo<()>` is not implemented for `B`
  |
  = help: consider adding a `where B: Foo<()>` bound

error[E0276]: impl has stricter requirements than trait
 --> <anon>:8:5
  |
4 |     fn arthur() where B: Foo<Self::Baz>, B::Quux: Send;
  |     --------------------------------------------------- definition of `arthur` from trait
...
8 |     fn arthur() where B: Foo<()>, B::Quux: Send { }
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `B: Foo<()>`

error: aborting due to 2 previous errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-lazy-normalizationArea: Lazy normalization (tracking issue: #60471)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.fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions