Skip to content

FP single-use-lifetimes with inherent_associated_types #111400

Closed
@matthiaskrgr

Description

@matthiaskrgr

I tried this code:

// check-pass

#![feature(inherent_associated_types)]
#![allow(incomplete_features)]

struct Foo<T>(T);

impl<'a> Foo<fn(&'a ())> {
    type Assoc = &'a ();
}

trait Other {}
impl Other for u32 {}

fn bar(_: for<'a> fn(Foo<fn(&'a ())>::Assoc)) {}

fn main() {}

rustc issue-109790.rs -Wsingle-use-lifetimes:

warning: lifetime parameter `'a` only used once
  --> issue-109790.rs:15:15
   |
15 | fn bar(_: for<'a> fn(Foo<fn(&'a ())>::Assoc)) {}
   |               ^^             -- ...is used only here
   |               |
   |               this lifetime...
   |
   = note: requested on the command line with `-W single-use-lifetimes`
help: elide the single-use lifetime
   |
15 - fn bar(_: for<'a> fn(Foo<fn(&'a ())>::Assoc)) {}
15 + fn bar(_: fn(Foo<fn(&())>::Assoc)) {}
....

I expected to see this happen: explanation
suggestion compiles:

#![feature(inherent_associated_types)]
#![allow(incomplete_features)]

struct Foo<T>(T);

impl<'a> Foo<fn(&'a ())> {
    type Assoc = &'a ();
}

trait Other {}
impl Other for u32 {}

fn bar(_: fn(Foo<fn(& ())>::Assoc)) {}

fn main() {}

Instead, this happened: explanation
Suggestion does not compile:

error: higher-ranked subtype error
  --> issue-109790.rs:15:1
   |
15 | fn bar(_: fn(Foo<fn(& ())>::Assoc)) {}
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

Meta

rustc --version --verbose:

rustc 1.71.0-nightly (2f2c438dc 2023-05-08)
binary: rustc
commit-hash: 2f2c438dce75d8cc532c3baa849eeddc0901802c
commit-date: 2023-05-08
host: x86_64-unknown-linux-gnu
release: 1.71.0-nightly
LLVM version: 16.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.F-inherent_associated_types`#![feature(inherent_associated_types)]`

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions