Add some more tests
This commit is contained in:
parent
97910580aa
commit
afa24f0180
11 changed files with 106 additions and 1 deletions
|
@ -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,
|
||||||
|
|
8
tests/ui/lifetimes/raw/gen-lt.e2024.stderr
Normal file
8
tests/ui/lifetimes/raw/gen-lt.e2024.stderr
Normal 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
|
||||||
|
|
14
tests/ui/lifetimes/raw/gen-lt.rs
Normal file
14
tests/ui/lifetimes/raw/gen-lt.rs
Normal 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() {}
|
8
tests/ui/lifetimes/raw/lifetimes-eq.rs
Normal file
8
tests/ui/lifetimes/raw/lifetimes-eq.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
//@ edition: 2021
|
||||||
|
//@ check-pass
|
||||||
|
|
||||||
|
// Test that `'r#a` is `'a`.
|
||||||
|
|
||||||
|
fn test<'r#a>(x: &'a ()) {}
|
||||||
|
|
||||||
|
fn main() {}
|
12
tests/ui/lifetimes/raw/macro-lt.rs
Normal file
12
tests/ui/lifetimes/raw/macro-lt.rs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
//@ check-pass
|
||||||
|
//@ edition: 2021
|
||||||
|
|
||||||
|
macro_rules! lifetime {
|
||||||
|
($lt:lifetime) => {
|
||||||
|
fn hello<$lt>() {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lifetime!('r#struct);
|
||||||
|
|
||||||
|
fn main() {}
|
6
tests/ui/lifetimes/raw/multiple-prefixes.rs
Normal file
6
tests/ui/lifetimes/raw/multiple-prefixes.rs
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
//@ edition: 2021
|
||||||
|
|
||||||
|
fn test(x: &'r#r#r ()) {}
|
||||||
|
//~^ ERROR expected type, found `#`
|
||||||
|
|
||||||
|
fn main() {}
|
8
tests/ui/lifetimes/raw/multiple-prefixes.stderr
Normal file
8
tests/ui/lifetimes/raw/multiple-prefixes.stderr
Normal 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
|
||||||
|
|
8
tests/ui/lifetimes/raw/prim-lt.rs
Normal file
8
tests/ui/lifetimes/raw/prim-lt.rs
Normal 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() {}
|
21
tests/ui/lifetimes/raw/simple.rs
Normal file
21
tests/ui/lifetimes/raw/simple.rs
Normal 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() {}
|
8
tests/ui/lifetimes/raw/static-lt.rs
Normal file
8
tests/ui/lifetimes/raw/static-lt.rs
Normal 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() {}
|
12
tests/ui/lifetimes/raw/three-tokens.rs
Normal file
12
tests/ui/lifetimes/raw/three-tokens.rs
Normal 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() {}
|
Loading…
Add table
Add a link
Reference in a new issue