Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FP single-use-lifetimes with inherent_associated_types #111400

Closed
matthiaskrgr opened this issue May 9, 2023 · 0 comments · Fixed by #111444
Closed

FP single-use-lifetimes with inherent_associated_types #111400

matthiaskrgr opened this issue May 9, 2023 · 0 comments · Fixed by #111444
Labels
A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. F-inherent_associated_types `#![feature(inherent_associated_types)]`

Comments

@matthiaskrgr
Copy link
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
@matthiaskrgr matthiaskrgr added C-bug Category: This is a bug. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. F-inherent_associated_types `#![feature(inherent_associated_types)]` labels May 9, 2023
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue May 11, 2023
Only warn single-use lifetime when the binders match.

Fixes rust-lang#111400
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue May 11, 2023
Only warn single-use lifetime when the binders match.

Fixes rust-lang#111400
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue May 11, 2023
Only warn single-use lifetime when the binders match.

Fixes rust-lang#111400
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue May 11, 2023
Only warn single-use lifetime when the binders match.

Fixes rust-lang#111400
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue May 11, 2023
Only warn single-use lifetime when the binders match.

Fixes rust-lang#111400
@bors bors closed this as completed in 7c31df9 May 12, 2023
RalfJung pushed a commit to RalfJung/miri that referenced this issue May 12, 2023
Only warn single-use lifetime when the binders match.

Fixes rust-lang/rust#111400
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. F-inherent_associated_types `#![feature(inherent_associated_types)]`
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant