Add tests
This commit is contained in:
parent
3f97c6be8d
commit
c5d02237d3
9 changed files with 173 additions and 1 deletions
|
@ -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));
|
||||
|
|
7
tests/ui/feature-gates/feature-gate-unsafe-binders.rs
Normal file
7
tests/ui/feature-gates/feature-gate-unsafe-binders.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
#[cfg(any())]
|
||||
fn test() {
|
||||
let x: unsafe<> ();
|
||||
//~^ ERROR unsafe binder types are experimental
|
||||
}
|
||||
|
||||
fn main() {}
|
13
tests/ui/feature-gates/feature-gate-unsafe-binders.stderr
Normal file
13
tests/ui/feature-gates/feature-gate-unsafe-binders.stderr
Normal file
|
@ -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
tests/ui/unsafe-binders/expr.rs
Normal file
13
tests/ui/unsafe-binders/expr.rs
Normal file
|
@ -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
tests/ui/unsafe-binders/expr.stderr
Normal file
29
tests/ui/unsafe-binders/expr.stderr
Normal file
|
@ -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
tests/ui/unsafe-binders/lifetime-resolution.rs
Normal file
19
tests/ui/unsafe-binders/lifetime-resolution.rs
Normal file
|
@ -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
tests/ui/unsafe-binders/lifetime-resolution.stderr
Normal file
65
tests/ui/unsafe-binders/lifetime-resolution.stderr
Normal file
|
@ -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
tests/ui/unsafe-binders/simple.rs
Normal file
7
tests/ui/unsafe-binders/simple.rs
Normal file
|
@ -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
tests/ui/unsafe-binders/simple.stderr
Normal file
17
tests/ui/unsafe-binders/simple.stderr
Normal file
|
@ -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
|
||||
|
Loading…
Add table
Reference in a new issue