about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_parse/src/lexer/mod.rs2
-rw-r--r--tests/ui/lifetimes/raw/gen-lt.e2024.stderr8
-rw-r--r--tests/ui/lifetimes/raw/gen-lt.rs14
-rw-r--r--tests/ui/lifetimes/raw/lifetimes-eq.rs8
-rw-r--r--tests/ui/lifetimes/raw/macro-lt.rs12
-rw-r--r--tests/ui/lifetimes/raw/multiple-prefixes.rs6
-rw-r--r--tests/ui/lifetimes/raw/multiple-prefixes.stderr8
-rw-r--r--tests/ui/lifetimes/raw/prim-lt.rs8
-rw-r--r--tests/ui/lifetimes/raw/simple.rs21
-rw-r--r--tests/ui/lifetimes/raw/static-lt.rs8
-rw-r--r--tests/ui/lifetimes/raw/three-tokens.rs12
11 files changed, 106 insertions, 1 deletions
diff --git a/compiler/rustc_parse/src/lexer/mod.rs b/compiler/rustc_parse/src/lexer/mod.rs
index a680e2a3bc2..b7232ff21ca 100644
--- a/compiler/rustc_parse/src/lexer/mod.rs
+++ b/compiler/rustc_parse/src/lexer/mod.rs
@@ -301,7 +301,7 @@ impl<'psess, 'src> StringReader<'psess, 'src> {
 
                         token::Lifetime(sym, IdentIsRaw::Yes)
                     } else {
-                        // Otherwise, this is just `'r`. Warn about it though.
+                        // Otherwise, this should be parsed like `'r`. Warn about it though.
                         self.psess.buffer_lint(
                             RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX,
                             prefix_span,
diff --git a/tests/ui/lifetimes/raw/gen-lt.e2024.stderr b/tests/ui/lifetimes/raw/gen-lt.e2024.stderr
new file mode 100644
index 00000000000..232453df8ef
--- /dev/null
+++ b/tests/ui/lifetimes/raw/gen-lt.e2024.stderr
@@ -0,0 +1,8 @@
+error: lifetimes cannot use keyword names
+  --> $DIR/gen-lt.rs:11:11
+   |
+LL | fn gen_lt<'gen>() {}
+   |           ^^^^
+
+error: aborting due to 1 previous error
+
diff --git a/tests/ui/lifetimes/raw/gen-lt.rs b/tests/ui/lifetimes/raw/gen-lt.rs
new file mode 100644
index 00000000000..4f3ede5b4a2
--- /dev/null
+++ b/tests/ui/lifetimes/raw/gen-lt.rs
@@ -0,0 +1,14 @@
+//@ revisions: e2021 e2024
+
+//@[e2021] edition:2021
+//@[e2024] edition:2024
+//@[e2024] compile-flags: -Zunstable-options
+
+//@[e2021] check-pass
+
+fn raw_gen_lt<'r#gen>() {}
+
+fn gen_lt<'gen>() {}
+//[e2024]~^ ERROR lifetimes cannot use keyword names
+
+fn main() {}
diff --git a/tests/ui/lifetimes/raw/lifetimes-eq.rs b/tests/ui/lifetimes/raw/lifetimes-eq.rs
new file mode 100644
index 00000000000..dddafb829ba
--- /dev/null
+++ b/tests/ui/lifetimes/raw/lifetimes-eq.rs
@@ -0,0 +1,8 @@
+//@ edition: 2021
+//@ check-pass
+
+// Test that `'r#a` is `'a`.
+
+fn test<'r#a>(x: &'a ()) {}
+
+fn main() {}
diff --git a/tests/ui/lifetimes/raw/macro-lt.rs b/tests/ui/lifetimes/raw/macro-lt.rs
new file mode 100644
index 00000000000..d1167b00467
--- /dev/null
+++ b/tests/ui/lifetimes/raw/macro-lt.rs
@@ -0,0 +1,12 @@
+//@ check-pass
+//@ edition: 2021
+
+macro_rules! lifetime {
+    ($lt:lifetime) => {
+        fn hello<$lt>() {}
+    }
+}
+
+lifetime!('r#struct);
+
+fn main() {}
diff --git a/tests/ui/lifetimes/raw/multiple-prefixes.rs b/tests/ui/lifetimes/raw/multiple-prefixes.rs
new file mode 100644
index 00000000000..f335373d8a7
--- /dev/null
+++ b/tests/ui/lifetimes/raw/multiple-prefixes.rs
@@ -0,0 +1,6 @@
+//@ edition: 2021
+
+fn test(x: &'r#r#r ()) {}
+//~^ ERROR expected type, found `#`
+
+fn main() {}
diff --git a/tests/ui/lifetimes/raw/multiple-prefixes.stderr b/tests/ui/lifetimes/raw/multiple-prefixes.stderr
new file mode 100644
index 00000000000..8d5479e0a4f
--- /dev/null
+++ b/tests/ui/lifetimes/raw/multiple-prefixes.stderr
@@ -0,0 +1,8 @@
+error: expected type, found `#`
+  --> $DIR/multiple-prefixes.rs:3:17
+   |
+LL | fn test(x: &'r#r#r ()) {}
+   |                 ^ expected type
+
+error: aborting due to 1 previous error
+
diff --git a/tests/ui/lifetimes/raw/prim-lt.rs b/tests/ui/lifetimes/raw/prim-lt.rs
new file mode 100644
index 00000000000..ca45efb65fd
--- /dev/null
+++ b/tests/ui/lifetimes/raw/prim-lt.rs
@@ -0,0 +1,8 @@
+//@ check-pass
+//@ edition: 2021
+
+// Checks a primitive name can be defined as a lifetime.
+
+fn foo<'r#i32>() {}
+
+fn main() {}
diff --git a/tests/ui/lifetimes/raw/simple.rs b/tests/ui/lifetimes/raw/simple.rs
new file mode 100644
index 00000000000..6f70a272203
--- /dev/null
+++ b/tests/ui/lifetimes/raw/simple.rs
@@ -0,0 +1,21 @@
+//@ check-pass
+//@ edition: 2021
+
+fn foo<'r#struct>() {}
+
+fn hr<T>() where for<'r#struct> T: Into<&'r#struct ()> {}
+
+trait Foo<'r#struct> {}
+
+trait Bar<'r#struct> {
+    fn method(&'r#struct self) {}
+    fn method2(self: &'r#struct Self) {}
+}
+
+fn labeled() {
+    'r#struct: loop {
+        break 'r#struct;
+    }
+}
+
+fn main() {}
diff --git a/tests/ui/lifetimes/raw/static-lt.rs b/tests/ui/lifetimes/raw/static-lt.rs
new file mode 100644
index 00000000000..1fec7097dab
--- /dev/null
+++ b/tests/ui/lifetimes/raw/static-lt.rs
@@ -0,0 +1,8 @@
+//@ check-pass
+//@ edition: 2021
+
+// Makes sure that `'r#static` is `'static`
+
+const FOO: &'r#static str = "hello, world";
+
+fn main() {}
diff --git a/tests/ui/lifetimes/raw/three-tokens.rs b/tests/ui/lifetimes/raw/three-tokens.rs
new file mode 100644
index 00000000000..2ae54ebbcb5
--- /dev/null
+++ b/tests/ui/lifetimes/raw/three-tokens.rs
@@ -0,0 +1,12 @@
+//@ edition: 2015
+//@ check-pass
+// Ensure that we parse `'r#lt` as three tokens in edition 2015.
+
+macro_rules! ed2015 {
+    ('r # lt) => {};
+    ($lt:lifetime) => { compile_error!() };
+}
+
+ed2015!('r#lt);
+
+fn main() {}