Skip to content

Commit

Permalink
Add some more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Sep 6, 2024
1 parent 9791058 commit afa24f0
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/lifetimes/raw/gen-lt.e2024.stderr
Original file line number Diff line number Diff line change
@@ -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 changes: 14 additions & 0 deletions tests/ui/lifetimes/raw/gen-lt.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 8 additions & 0 deletions tests/ui/lifetimes/raw/lifetimes-eq.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//@ edition: 2021
//@ check-pass

// Test that `'r#a` is `'a`.

fn test<'r#a>(x: &'a ()) {}

fn main() {}
12 changes: 12 additions & 0 deletions tests/ui/lifetimes/raw/macro-lt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//@ check-pass
//@ edition: 2021

macro_rules! lifetime {
($lt:lifetime) => {
fn hello<$lt>() {}
}
}

lifetime!('r#struct);

fn main() {}
6 changes: 6 additions & 0 deletions tests/ui/lifetimes/raw/multiple-prefixes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//@ edition: 2021

fn test(x: &'r#r#r ()) {}
//~^ ERROR expected type, found `#`

fn main() {}
8 changes: 8 additions & 0 deletions tests/ui/lifetimes/raw/multiple-prefixes.stderr
Original file line number Diff line number Diff line change
@@ -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 changes: 8 additions & 0 deletions tests/ui/lifetimes/raw/prim-lt.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 21 additions & 0 deletions tests/ui/lifetimes/raw/simple.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 8 additions & 0 deletions tests/ui/lifetimes/raw/static-lt.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 12 additions & 0 deletions tests/ui/lifetimes/raw/three-tokens.rs
Original file line number Diff line number Diff line change
@@ -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() {}

0 comments on commit afa24f0

Please sign in to comment.