summaryrefslogtreecommitdiffstats
path: root/tests/ui/nll/mir_check_cast_reify.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/nll/mir_check_cast_reify.rs
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/nll/mir_check_cast_reify.rs')
-rw-r--r--tests/ui/nll/mir_check_cast_reify.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/ui/nll/mir_check_cast_reify.rs b/tests/ui/nll/mir_check_cast_reify.rs
new file mode 100644
index 000000000..951459911
--- /dev/null
+++ b/tests/ui/nll/mir_check_cast_reify.rs
@@ -0,0 +1,39 @@
+#![allow(dead_code)]
+
+// Test that we relate the type of the fn type to the type of the fn
+// ptr when doing a `ReifyFnPointer` cast.
+//
+// This test is a bit tortured, let me explain:
+//
+
+// The `where 'a: 'a` clause here ensures that `'a` is early bound,
+// which is needed below to ensure that this test hits the path we are
+// concerned with.
+fn foo<'a>(x: &'a u32) -> &'a u32
+where
+ 'a: 'a,
+{
+ panic!()
+}
+
+fn bar<'a>(x: &'a u32) -> &'static u32 {
+ // Here, the type of `foo` is `typeof(foo::<'x>)` for some fresh variable `'x`.
+ // During NLL region analysis, this will get renumbered to `typeof(foo::<'?0>)`
+ // where `'?0` is a new region variable.
+ //
+ // (Note that if `'a` on `foo` were late-bound, the type would be
+ // `typeof(foo)`, which would interact differently with because
+ // the renumbering later.)
+ //
+ // This type is then coerced to a fn type `fn(&'?1 u32) -> &'?2
+ // u32`. Here, the `'?1` and `'?2` will have been created during
+ // the NLL region renumbering.
+ //
+ // The MIR type checker must therefore relate `'?0` to `'?1` and `'?2`
+ // as part of checking the `ReifyFnPointer`.
+ let f: fn(_) -> _ = foo;
+ f(x)
+ //~^ ERROR lifetime may not live long enough
+}
+
+fn main() {}