Skip to content

Bounds in HRTB are ignored #42181

Closed
@djzin

Description

@djzin

The syntax where for<'b: 'a> ... is permitted without warning, however the : 'a bound is not used to prove the identity; I would expect the following to compile:

trait Trait {}

impl Trait for &'static () {}

fn f<'a>(_: &'a ()) where for<'b: 'a> &'b () : Trait {}

fn main() {
    static X: &'static () = &();
    f::<'static>(X)
}

but it fails with

rustc 1.17.0 (56124baa9 2017-04-24)
error[E0277]: the trait bound `for<'b> &'b (): Trait` is not satisfied
 --> <anon>:9:5
  |
9 |     f::<'static>(X)
  |     ^^^^^^^^^^^^ the trait `for<'b> Trait` is not implemented for `&'b ()`
  |
  = help: the following implementations were found:
            <&'static () as Trait>
  = note: required by `f`

error: aborting due to previous error

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.P-mediumMedium priorityT-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