Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Dec 10, 2024
1 parent b2d13c6 commit 9ddb85f
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 1 deletion.
4 changes: 3 additions & 1 deletion compiler/rustc_parse/src/parser/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,9 @@ impl<'a> Parser<'a> {
TyKind::Err(guar)
}
}
} else if self.check_keyword(kw::Unsafe) {
} else if self.check_keyword(kw::Unsafe)
&& self.look_ahead(1, |tok| matches!(tok.kind, token::Lt))
{
self.parse_unsafe_binder_ty()?
} else {
let msg = format!("expected type, found {}", super::token_descr(&self.token));
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/feature-gates/feature-gate-unsafe-binders.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#[cfg(any())]
fn test() {
let x: unsafe<> ();
//~^ ERROR unsafe binder types are experimental
}

fn main() {}
13 changes: 13 additions & 0 deletions tests/ui/feature-gates/feature-gate-unsafe-binders.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0658]: unsafe binder types are experimental
--> $DIR/feature-gate-unsafe-binders.rs:3:12
|
LL | let x: unsafe<> ();
| ^^^^^^^^^^^
|
= note: see issue #130516 <https://github.com/rust-lang/rust/issues/130516> for more information
= help: add `#![feature(unsafe_binders)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0658`.
13 changes: 13 additions & 0 deletions tests/ui/unsafe-binders/expr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![feature(unsafe_binders)]
//~^ WARN the feature `unsafe_binders` is incomplete

use std::unsafe_binder::{wrap_binder, unwrap_binder};

fn main() {
let x = 1;
let binder: unsafe<'a> &'a i32 = wrap_binder!(x);
//~^ ERROR unsafe binders are not yet implemented
//~| ERROR unsafe binders are not yet implemented
let rx = *unwrap_binder!(binder);
//~^ ERROR unsafe binders are not yet implemented
}
29 changes: 29 additions & 0 deletions tests/ui/unsafe-binders/expr.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
warning: the feature `unsafe_binders` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/expr.rs:1:12
|
LL | #![feature(unsafe_binders)]
| ^^^^^^^^^^^^^^
|
= note: see issue #130516 <https://github.com/rust-lang/rust/issues/130516> for more information
= note: `#[warn(incomplete_features)]` on by default

error: unsafe binders are not yet implemented
--> $DIR/expr.rs:8:17
|
LL | let binder: unsafe<'a> &'a i32 = wrap_binder!(x);
| ^^^^^^^^^^^^^^^^^^

error: unsafe binders are not yet implemented
--> $DIR/expr.rs:8:51
|
LL | let binder: unsafe<'a> &'a i32 = wrap_binder!(x);
| ^

error: unsafe binders are not yet implemented
--> $DIR/expr.rs:11:30
|
LL | let rx = *unwrap_binder!(binder);
| ^^^^^^

error: aborting due to 3 previous errors; 1 warning emitted

19 changes: 19 additions & 0 deletions tests/ui/unsafe-binders/lifetime-resolution.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#![feature(unsafe_binders)]
//~^ WARN the feature `unsafe_binders` is incomplete

fn foo<'a>() {
let good: unsafe<'b> &'a &'b ();
//~^ ERROR unsafe binders are not yet implemented

let missing: unsafe<> &'missing ();
//~^ ERROR unsafe binders are not yet implemented
//~| ERROR use of undeclared lifetime name `'missing`

fn inner<'b>() {
let outer: unsafe<> &'a &'b ();
//~^ ERROR unsafe binders are not yet implemented
//~| can't use generic parameters from outer item
}
}

fn main() {}
65 changes: 65 additions & 0 deletions tests/ui/unsafe-binders/lifetime-resolution.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
error[E0261]: use of undeclared lifetime name `'missing`
--> $DIR/lifetime-resolution.rs:8:28
|
LL | let missing: unsafe<> &'missing ();
| ^^^^^^^^ undeclared lifetime
|
= note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
help: consider making the type lifetime-generic with a new `'missing` lifetime
|
LL | let missing: unsafe<'missing, > &'missing ();
| +++++++++
help: consider introducing lifetime `'missing` here
|
LL | fn foo<'missing, 'a>() {
| +++++++++

error[E0401]: can't use generic parameters from outer item
--> $DIR/lifetime-resolution.rs:13:30
|
LL | fn foo<'a>() {
| -- lifetime parameter from outer item
...
LL | let outer: unsafe<> &'a &'b ();
| ^^ use of generic parameter from outer item
|
help: consider making the type lifetime-generic with a new `'a` lifetime
|
LL | let outer: unsafe<'a, > &'a &'b ();
| +++
help: consider introducing lifetime `'a` here
|
LL | fn inner<'a, 'b>() {
| +++

warning: the feature `unsafe_binders` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/lifetime-resolution.rs:1:12
|
LL | #![feature(unsafe_binders)]
| ^^^^^^^^^^^^^^
|
= note: see issue #130516 <https://github.com/rust-lang/rust/issues/130516> for more information
= note: `#[warn(incomplete_features)]` on by default

error: unsafe binders are not yet implemented
--> $DIR/lifetime-resolution.rs:5:15
|
LL | let good: unsafe<'b> &'a &'b ();
| ^^^^^^^^^^^^^^^^^^^^^

error: unsafe binders are not yet implemented
--> $DIR/lifetime-resolution.rs:8:18
|
LL | let missing: unsafe<> &'missing ();
| ^^^^^^^^^^^^^^^^^^^^^

error: unsafe binders are not yet implemented
--> $DIR/lifetime-resolution.rs:13:20
|
LL | let outer: unsafe<> &'a &'b ();
| ^^^^^^^^^^^^^^^^^^^

error: aborting due to 5 previous errors; 1 warning emitted

Some errors have detailed explanations: E0261, E0401.
For more information about an error, try `rustc --explain E0261`.
7 changes: 7 additions & 0 deletions tests/ui/unsafe-binders/simple.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![feature(unsafe_binders)]
//~^ WARN the feature `unsafe_binders` is incomplete

fn main() {
let x: unsafe<'a> &'a ();
//~^ ERROR unsafe binders are not yet implemented
}
17 changes: 17 additions & 0 deletions tests/ui/unsafe-binders/simple.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
warning: the feature `unsafe_binders` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/simple.rs:1:12
|
LL | #![feature(unsafe_binders)]
| ^^^^^^^^^^^^^^
|
= note: see issue #130516 <https://github.com/rust-lang/rust/issues/130516> for more information
= note: `#[warn(incomplete_features)]` on by default

error: unsafe binders are not yet implemented
--> $DIR/simple.rs:5:12
|
LL | let x: unsafe<'a> &'a ();
| ^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error; 1 warning emitted

0 comments on commit 9ddb85f

Please sign in to comment.