Skip to content

FP single-use-lifetimes with inherent_associated_types #111400

@matthiaskrgr

Description

@matthiaskrgr
Member

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

Activity

added
C-bugCategory: This is a bug.
A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`
D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.
on May 9, 2023
added a commit that references this issue on May 11, 2023
78964a6
added 4 commits that reference this issue on May 11, 2023
2651fff
8235798
7a674e4
3bacb85
added a commit that references this issue on May 12, 2023
7c31df9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @matthiaskrgr

      Issue actions

        FP single-use-lifetimes with inherent_associated_types · Issue #111400 · rust-lang/rust