Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions tests/ui/higher-ranked/hr-fn-ptr-trait-impl-mismatch-29061.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//! Regression test for <https://github.com/rust-lang/rust/issues/29061>.
//!
//! A trait implemented for a higher-ranked fn pointer is not implemented for a fn pointer
//! with a specific lifetime, and vice versa. The errors now spell out which form the impl
//! applies to instead of just saying the bound is unsatisfied.

//@ edition: 2024

#![allow(dead_code)]

fn x(_: &()) {}

trait HR {}
impl HR for fn(&()) {}
fn hr<T: HR>(_: T) {}

trait NotHR {}
impl<'a> NotHR for fn(&'a ()) {}
fn not_hr<T: NotHR>(_: T) {}

fn a<'a>() {
let not_hr_func: fn(&'a ()) = x;
let hr_func: fn(&()) = x;
let hr_func2: for<'b> fn(&'b ()) = x;
hr(not_hr_func);
//~^ ERROR implementation of `HR` is not general enough
not_hr(hr_func);
//~^ ERROR implementation of `NotHR` is not general enough
not_hr(hr_func2);
//~^ ERROR implementation of `NotHR` is not general enough
}

fn main() {}
29 changes: 29 additions & 0 deletions tests/ui/higher-ranked/hr-fn-ptr-trait-impl-mismatch-29061.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
error: implementation of `HR` is not general enough
--> $DIR/hr-fn-ptr-trait-impl-mismatch-29061.rs:25:5
|
LL | hr(not_hr_func);
| ^^^^^^^^^^^^^^^ implementation of `HR` is not general enough
|
= note: `HR` would have to be implemented for the type `fn(&'0 ())`, for some specific lifetime `'0`...
= note: ...but `HR` is actually implemented for the type `for<'a> fn(&'a ())`

error: implementation of `NotHR` is not general enough
--> $DIR/hr-fn-ptr-trait-impl-mismatch-29061.rs:27:5
|
LL | not_hr(hr_func);
| ^^^^^^^^^^^^^^^ implementation of `NotHR` is not general enough
|
= note: `NotHR` would have to be implemented for the type `for<'a> fn(&'a ())`
= note: ...but `NotHR` is actually implemented for the type `fn(&'0 ())`, for some specific lifetime `'0`

error: implementation of `NotHR` is not general enough
--> $DIR/hr-fn-ptr-trait-impl-mismatch-29061.rs:29:5
|
LL | not_hr(hr_func2);
| ^^^^^^^^^^^^^^^^ implementation of `NotHR` is not general enough
|
= note: `NotHR` would have to be implemented for the type `for<'b> fn(&'b ())`
= note: ...but `NotHR` is actually implemented for the type `fn(&'0 ())`, for some specific lifetime `'0`

error: aborting due to 3 previous errors

Loading