diff --git a/tests/ui/higher-ranked/hr-fn-ptr-trait-impl-mismatch-29061.rs b/tests/ui/higher-ranked/hr-fn-ptr-trait-impl-mismatch-29061.rs new file mode 100644 index 0000000000000..8ff3cd5cdb694 --- /dev/null +++ b/tests/ui/higher-ranked/hr-fn-ptr-trait-impl-mismatch-29061.rs @@ -0,0 +1,33 @@ +//! Regression test for . +//! +//! 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) {} + +trait NotHR {} +impl<'a> NotHR for fn(&'a ()) {} +fn not_hr(_: 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() {} diff --git a/tests/ui/higher-ranked/hr-fn-ptr-trait-impl-mismatch-29061.stderr b/tests/ui/higher-ranked/hr-fn-ptr-trait-impl-mismatch-29061.stderr new file mode 100644 index 0000000000000..19a63fb6fb6a6 --- /dev/null +++ b/tests/ui/higher-ranked/hr-fn-ptr-trait-impl-mismatch-29061.stderr @@ -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 +