Skip to content

Commit 08406ad

Browse files
Add some more tests
1 parent d642752 commit 08406ad

File tree

11 files changed

+106
-1
lines changed

11 files changed

+106
-1
lines changed

compiler/rustc_parse/src/lexer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ impl<'psess, 'src> StringReader<'psess, 'src> {
301301

302302
token::Lifetime(sym, IdentIsRaw::Yes)
303303
} else {
304-
// Otherwise, this is just `'r`. Warn about it though.
304+
// Otherwise, this should be parsed like `'r`. Warn about it though.
305305
self.psess.buffer_lint(
306306
RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX,
307307
prefix_span,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: lifetimes cannot use keyword names
2+
--> $DIR/gen-lt.rs:11:11
3+
|
4+
LL | fn gen_lt<'gen>() {}
5+
| ^^^^
6+
7+
error: aborting due to 1 previous error
8+

tests/ui/lifetimes/raw/gen-lt.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//@ revisions: e2021 e2024
2+
3+
//@[e2021] edition:2021
4+
//@[e2024] edition:2024
5+
//@[e2024] compile-flags: -Zunstable-options
6+
7+
//@[e2021] check-pass
8+
9+
fn raw_gen_lt<'r#gen>() {}
10+
11+
fn gen_lt<'gen>() {}
12+
//[e2024]~^ ERROR lifetimes cannot use keyword names
13+
14+
fn main() {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//@ edition: 2021
2+
//@ check-pass
3+
4+
// Test that `'r#a` is `'a`.
5+
6+
fn test<'r#a>(x: &'a ()) {}
7+
8+
fn main() {}

tests/ui/lifetimes/raw/macro-lt.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ check-pass
2+
//@ edition: 2021
3+
4+
macro_rules! lifetime {
5+
($lt:lifetime) => {
6+
fn hello<$lt>() {}
7+
}
8+
}
9+
10+
lifetime!('r#struct);
11+
12+
fn main() {}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//@ edition: 2021
2+
3+
fn test(x: &'r#r#r ()) {}
4+
//~^ ERROR expected type, found `#`
5+
6+
fn main() {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: expected type, found `#`
2+
--> $DIR/multiple-prefixes.rs:3:17
3+
|
4+
LL | fn test(x: &'r#r#r ()) {}
5+
| ^ expected type
6+
7+
error: aborting due to 1 previous error
8+

tests/ui/lifetimes/raw/prim-lt.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//@ check-pass
2+
//@ edition: 2021
3+
4+
// Checks a primitive name can be defined as a lifetime.
5+
6+
fn foo<'r#i32>() {}
7+
8+
fn main() {}

tests/ui/lifetimes/raw/simple.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//@ check-pass
2+
//@ edition: 2021
3+
4+
fn foo<'r#struct>() {}
5+
6+
fn hr<T>() where for<'r#struct> T: Into<&'r#struct ()> {}
7+
8+
trait Foo<'r#struct> {}
9+
10+
trait Bar<'r#struct> {
11+
fn method(&'r#struct self) {}
12+
fn method2(self: &'r#struct Self) {}
13+
}
14+
15+
fn labeled() {
16+
'r#struct: loop {
17+
break 'r#struct;
18+
}
19+
}
20+
21+
fn main() {}

tests/ui/lifetimes/raw/static-lt.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//@ check-pass
2+
//@ edition: 2021
3+
4+
// Makes sure that `'r#static` is `'static`
5+
6+
const FOO: &'r#static str = "hello, world";
7+
8+
fn main() {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ edition: 2015
2+
//@ check-pass
3+
// Ensure that we parse `'r#lt` as three tokens in edition 2015.
4+
5+
macro_rules! ed2015 {
6+
('r # lt) => {};
7+
($lt:lifetime) => { compile_error!() };
8+
}
9+
10+
ed2015!('r#lt);
11+
12+
fn main() {}

0 commit comments

Comments
 (0)