diff options
| author | Jubilee <workingjubilee@gmail.com> | 2025-06-08 17:17:57 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-08 17:17:57 -0700 |
| commit | 29ef4c87421a46cbf53432af9bd55edd32088dbd (patch) | |
| tree | 9f905b4dbacd9fd4cee7817599a285403bc35ea4 | |
| parent | 48667ddd5a659b3e258436e7cd0ed8c2a5ada4ad (diff) | |
| parent | 143354c52b1dd8ba7c665c123fd7ed0f2396d7b4 (diff) | |
| download | rust-29ef4c87421a46cbf53432af9bd55edd32088dbd.tar.gz rust-29ef4c87421a46cbf53432af9bd55edd32088dbd.zip | |
Rollup merge of #142183 - Kivooeo:30904-test, r=compiler-errors
Added test for 30904 Test that was deleted by mistake in this commit https://github.com/rust-lang/rust/commit/564c78a6981174b32079f576eb6e7f965a13945e#diff-85d65712084246fc61f287664eef63b0b25ba0a5c8b69a4a59a9454b6a3ebac4 The original issue is still open and the problem is not solved (if this is even a problem, but the error is still here at least)
| -rw-r--r-- | tests/ui/unboxed-closures/fn-traits-hrtb-coercion.rs | 39 | ||||
| -rw-r--r-- | tests/ui/unboxed-closures/fn-traits-hrtb-coercion.stderr | 14 |
2 files changed, 53 insertions, 0 deletions
diff --git a/tests/ui/unboxed-closures/fn-traits-hrtb-coercion.rs b/tests/ui/unboxed-closures/fn-traits-hrtb-coercion.rs new file mode 100644 index 00000000000..4a08bf28bf3 --- /dev/null +++ b/tests/ui/unboxed-closures/fn-traits-hrtb-coercion.rs @@ -0,0 +1,39 @@ +//! Test for issue <github.com/rust-lang/rust/issues/30904> +//! Related to higher-ranked lifetime inference with unboxed closures and FnOnce. + +#![feature(fn_traits, unboxed_closures)] + +fn test<F: for<'x> FnOnce<(&'x str,)>>(_: F) {} + +struct Compose<F, G>(F, G); + +impl<T, F, G> FnOnce<(T,)> for Compose<F, G> +where + F: FnOnce<(T,)>, + G: FnOnce<(F::Output,)>, +{ + type Output = G::Output; + extern "rust-call" fn call_once(self, (x,): (T,)) -> G::Output { + (self.1)((self.0)(x)) + } +} + +struct Str<'a>(&'a str); + +fn mk_str<'a>(s: &'a str) -> Str<'a> { + Str(s) +} + +fn main() { + let _: for<'a> fn(&'a str) -> Str<'a> = mk_str; + let _: for<'a> fn(&'a str) -> Str<'a> = Str; + //~^ ERROR: mismatched types + + test(|_: &str| {}); + test(mk_str); + test(Str); + + test(Compose(|_: &str| {}, |_| {})); + test(Compose(mk_str, |_| {})); + test(Compose(Str, |_| {})); +} diff --git a/tests/ui/unboxed-closures/fn-traits-hrtb-coercion.stderr b/tests/ui/unboxed-closures/fn-traits-hrtb-coercion.stderr new file mode 100644 index 00000000000..a31d99f45d5 --- /dev/null +++ b/tests/ui/unboxed-closures/fn-traits-hrtb-coercion.stderr @@ -0,0 +1,14 @@ +error[E0308]: mismatched types + --> $DIR/fn-traits-hrtb-coercion.rs:29:45 + | +LL | let _: for<'a> fn(&'a str) -> Str<'a> = Str; + | ------------------------------ ^^^ one type is more general than the other + | | + | expected due to this + | + = note: expected fn pointer `for<'a> fn(&'a _) -> Str<'a>` + found struct constructor `fn(&_) -> Str<'_> {Str::<'_>}` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`. |
