about summary refs log tree commit diff
path: root/tests/ui/consts
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-08-19 23:27:50 +0000
committerMichael Goulet <michael@errs.io>2023-08-20 00:21:47 +0000
commitfad7d220fd2daefe8ee778b8cafbbeaf2dda4fc5 (patch)
tree5f623258dc5138acbc9cb12f9626d12f8de40f9a /tests/ui/consts
parent6ef7d16be0fb9d6ecf300c27990f4bff49d22d46 (diff)
downloadrust-fad7d220fd2daefe8ee778b8cafbbeaf2dda4fc5.tar.gz
rust-fad7d220fd2daefe8ee778b8cafbbeaf2dda4fc5.zip
Warn on elided lifetimes in associated constants
Diffstat (limited to 'tests/ui/consts')
-rw-r--r--tests/ui/consts/assoc-const-elided-lifetime.rs19
-rw-r--r--tests/ui/consts/assoc-const-elided-lifetime.stderr33
2 files changed, 52 insertions, 0 deletions
diff --git a/tests/ui/consts/assoc-const-elided-lifetime.rs b/tests/ui/consts/assoc-const-elided-lifetime.rs
new file mode 100644
index 00000000000..10cd33a8fed
--- /dev/null
+++ b/tests/ui/consts/assoc-const-elided-lifetime.rs
@@ -0,0 +1,19 @@
+#![deny(elided_lifetimes_in_associated_constant)]
+
+use std::marker::PhantomData;
+
+struct Foo<'a> {
+    x: PhantomData<&'a ()>,
+}
+
+impl<'a> Foo<'a> {
+    const FOO: Foo<'_> = Foo { x: PhantomData::<&()> };
+    //~^ ERROR `'_` cannot be used here
+    //~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+
+    const BAR: &() = &();
+    //~^ ERROR `&` without an explicit lifetime name cannot be used here
+    //~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+}
+
+fn main() {}
diff --git a/tests/ui/consts/assoc-const-elided-lifetime.stderr b/tests/ui/consts/assoc-const-elided-lifetime.stderr
new file mode 100644
index 00000000000..a1eeaff4ba8
--- /dev/null
+++ b/tests/ui/consts/assoc-const-elided-lifetime.stderr
@@ -0,0 +1,33 @@
+error: `'_` cannot be used here
+  --> $DIR/assoc-const-elided-lifetime.rs:10:20
+   |
+LL |     const FOO: Foo<'_> = Foo { x: PhantomData::<&()> };
+   |                    ^^
+   |
+   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+   = note: for more information, see issue #115010 <https://github.com/rust-lang/rust/issues/115010>
+note: the lint level is defined here
+  --> $DIR/assoc-const-elided-lifetime.rs:1:9
+   |
+LL | #![deny(elided_lifetimes_in_associated_constant)]
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+help: use the `'static` lifetime
+   |
+LL |     const FOO: Foo<'static> = Foo { x: PhantomData::<&()> };
+   |                    ~~~~~~~
+
+error: `&` without an explicit lifetime name cannot be used here
+  --> $DIR/assoc-const-elided-lifetime.rs:14:16
+   |
+LL |     const BAR: &() = &();
+   |                ^
+   |
+   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+   = note: for more information, see issue #115010 <https://github.com/rust-lang/rust/issues/115010>
+help: use the `'static` lifetime
+   |
+LL |     const BAR: &'static () = &();
+   |                 +++++++
+
+error: aborting due to 2 previous errors
+