Add some more tests

This commit is contained in:
Michael Goulet 2024-06-13 20:56:28 -04:00
parent 97910580aa
commit afa24f0180
11 changed files with 106 additions and 1 deletions

View file

@ -301,7 +301,7 @@ impl<'psess, 'src> StringReader<'psess, 'src> {
token::Lifetime(sym, IdentIsRaw::Yes) token::Lifetime(sym, IdentIsRaw::Yes)
} else { } 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( self.psess.buffer_lint(
RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX, RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX,
prefix_span, prefix_span,

View file

@ -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

View file

@ -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() {}

View file

@ -0,0 +1,8 @@
//@ edition: 2021
//@ check-pass
// Test that `'r#a` is `'a`.
fn test<'r#a>(x: &'a ()) {}
fn main() {}

View file

@ -0,0 +1,12 @@
//@ check-pass
//@ edition: 2021
macro_rules! lifetime {
($lt:lifetime) => {
fn hello<$lt>() {}
}
}
lifetime!('r#struct);
fn main() {}

View file

@ -0,0 +1,6 @@
//@ edition: 2021
fn test(x: &'r#r#r ()) {}
//~^ ERROR expected type, found `#`
fn main() {}

View file

@ -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

View file

@ -0,0 +1,8 @@
//@ check-pass
//@ edition: 2021
// Checks a primitive name can be defined as a lifetime.
fn foo<'r#i32>() {}
fn main() {}

View file

@ -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() {}

View file

@ -0,0 +1,8 @@
//@ check-pass
//@ edition: 2021
// Makes sure that `'r#static` is `'static`
const FOO: &'r#static str = "hello, world";
fn main() {}

View file

@ -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() {}