From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- .../regions-fn-subtyping-return-static-fail.rs | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/test/ui/regions/regions-fn-subtyping-return-static-fail.rs (limited to 'src/test/ui/regions/regions-fn-subtyping-return-static-fail.rs') diff --git a/src/test/ui/regions/regions-fn-subtyping-return-static-fail.rs b/src/test/ui/regions/regions-fn-subtyping-return-static-fail.rs new file mode 100644 index 000000000..539221b5a --- /dev/null +++ b/src/test/ui/regions/regions-fn-subtyping-return-static-fail.rs @@ -0,0 +1,51 @@ +// In this fn, the type `F` is a function that takes a reference to a +// struct and returns another reference with the same lifetime. +// +// Meanwhile, the bare fn `foo` takes a reference to a struct with +// *ANY* lifetime and returns a reference with the 'static lifetime. +// This can safely be considered to be an instance of `F` because all +// lifetimes are sublifetimes of 'static. + +#![allow(dead_code)] +#![allow(unused_variables)] + +struct S; + +// Given 'cx, return 'cx +type F = for<'cx> fn(&'cx S) -> &'cx S; +fn want_F(f: F) {} + +// Given anything, return 'static +type G = for<'cx> fn(&'cx S) -> &'static S; +fn want_G(f: G) {} + +// Should meet both. +fn foo(x: &S) -> &'static S { + panic!() +} + +// Should meet both. +fn bar<'a, 'b>(x: &'a S) -> &'b S { + panic!() +} + +// Meets F, but not G. +fn baz(x: &S) -> &S { + panic!() +} + +fn supply_F() { + want_F(foo); + + want_F(bar); + + want_F(baz); +} + +fn supply_G() { + want_G(foo); + want_G(bar); + want_G(baz); //~ ERROR mismatched types +} + +pub fn main() {} -- cgit v1.2.3