Skip to content

Commit c5d0223

Browse files
Add tests
1 parent 3f97c6b commit c5d0223

File tree

9 files changed

+173
-1
lines changed

9 files changed

+173
-1
lines changed

Diff for: compiler/rustc_parse/src/parser/ty.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,9 @@ impl<'a> Parser<'a> {
348348
TyKind::Err(guar)
349349
}
350350
}
351-
} else if self.check_keyword(kw::Unsafe) {
351+
} else if self.check_keyword(kw::Unsafe)
352+
&& self.look_ahead(1, |tok| matches!(tok.kind, token::Lt))
353+
{
352354
self.parse_unsafe_binder_ty()?
353355
} else {
354356
let msg = format!("expected type, found {}", super::token_descr(&self.token));
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#[cfg(any())]
2+
fn test() {
3+
let x: unsafe<> ();
4+
//~^ ERROR unsafe binder types are experimental
5+
}
6+
7+
fn main() {}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0658]: unsafe binder types are experimental
2+
--> $DIR/feature-gate-unsafe-binders.rs:3:12
3+
|
4+
LL | let x: unsafe<> ();
5+
| ^^^^^^^^^^^
6+
|
7+
= note: see issue #130516 <https://github.com/rust-lang/rust/issues/130516> for more information
8+
= help: add `#![feature(unsafe_binders)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
11+
error: aborting due to 1 previous error
12+
13+
For more information about this error, try `rustc --explain E0658`.

Diff for: tests/ui/unsafe-binders/expr.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(unsafe_binders)]
2+
//~^ WARN the feature `unsafe_binders` is incomplete
3+
4+
use std::unsafe_binder::{wrap_binder, unwrap_binder};
5+
6+
fn main() {
7+
let x = 1;
8+
let binder: unsafe<'a> &'a i32 = wrap_binder!(x);
9+
//~^ ERROR unsafe binders are not yet implemented
10+
//~| ERROR unsafe binders are not yet implemented
11+
let rx = *unwrap_binder!(binder);
12+
//~^ ERROR unsafe binders are not yet implemented
13+
}

Diff for: tests/ui/unsafe-binders/expr.stderr

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
warning: the feature `unsafe_binders` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/expr.rs:1:12
3+
|
4+
LL | #![feature(unsafe_binders)]
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #130516 <https://github.com/rust-lang/rust/issues/130516> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
error: unsafe binders are not yet implemented
11+
--> $DIR/expr.rs:8:17
12+
|
13+
LL | let binder: unsafe<'a> &'a i32 = wrap_binder!(x);
14+
| ^^^^^^^^^^^^^^^^^^
15+
16+
error: unsafe binders are not yet implemented
17+
--> $DIR/expr.rs:8:51
18+
|
19+
LL | let binder: unsafe<'a> &'a i32 = wrap_binder!(x);
20+
| ^
21+
22+
error: unsafe binders are not yet implemented
23+
--> $DIR/expr.rs:11:30
24+
|
25+
LL | let rx = *unwrap_binder!(binder);
26+
| ^^^^^^
27+
28+
error: aborting due to 3 previous errors; 1 warning emitted
29+

Diff for: tests/ui/unsafe-binders/lifetime-resolution.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![feature(unsafe_binders)]
2+
//~^ WARN the feature `unsafe_binders` is incomplete
3+
4+
fn foo<'a>() {
5+
let good: unsafe<'b> &'a &'b ();
6+
//~^ ERROR unsafe binders are not yet implemented
7+
8+
let missing: unsafe<> &'missing ();
9+
//~^ ERROR unsafe binders are not yet implemented
10+
//~| ERROR use of undeclared lifetime name `'missing`
11+
12+
fn inner<'b>() {
13+
let outer: unsafe<> &'a &'b ();
14+
//~^ ERROR unsafe binders are not yet implemented
15+
//~| can't use generic parameters from outer item
16+
}
17+
}
18+
19+
fn main() {}

Diff for: tests/ui/unsafe-binders/lifetime-resolution.stderr

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
error[E0261]: use of undeclared lifetime name `'missing`
2+
--> $DIR/lifetime-resolution.rs:8:28
3+
|
4+
LL | let missing: unsafe<> &'missing ();
5+
| ^^^^^^^^ undeclared lifetime
6+
|
7+
= note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
8+
help: consider making the type lifetime-generic with a new `'missing` lifetime
9+
|
10+
LL | let missing: unsafe<'missing, > &'missing ();
11+
| +++++++++
12+
help: consider introducing lifetime `'missing` here
13+
|
14+
LL | fn foo<'missing, 'a>() {
15+
| +++++++++
16+
17+
error[E0401]: can't use generic parameters from outer item
18+
--> $DIR/lifetime-resolution.rs:13:30
19+
|
20+
LL | fn foo<'a>() {
21+
| -- lifetime parameter from outer item
22+
...
23+
LL | let outer: unsafe<> &'a &'b ();
24+
| ^^ use of generic parameter from outer item
25+
|
26+
help: consider making the type lifetime-generic with a new `'a` lifetime
27+
|
28+
LL | let outer: unsafe<'a, > &'a &'b ();
29+
| +++
30+
help: consider introducing lifetime `'a` here
31+
|
32+
LL | fn inner<'a, 'b>() {
33+
| +++
34+
35+
warning: the feature `unsafe_binders` is incomplete and may not be safe to use and/or cause compiler crashes
36+
--> $DIR/lifetime-resolution.rs:1:12
37+
|
38+
LL | #![feature(unsafe_binders)]
39+
| ^^^^^^^^^^^^^^
40+
|
41+
= note: see issue #130516 <https://github.com/rust-lang/rust/issues/130516> for more information
42+
= note: `#[warn(incomplete_features)]` on by default
43+
44+
error: unsafe binders are not yet implemented
45+
--> $DIR/lifetime-resolution.rs:5:15
46+
|
47+
LL | let good: unsafe<'b> &'a &'b ();
48+
| ^^^^^^^^^^^^^^^^^^^^^
49+
50+
error: unsafe binders are not yet implemented
51+
--> $DIR/lifetime-resolution.rs:8:18
52+
|
53+
LL | let missing: unsafe<> &'missing ();
54+
| ^^^^^^^^^^^^^^^^^^^^^
55+
56+
error: unsafe binders are not yet implemented
57+
--> $DIR/lifetime-resolution.rs:13:20
58+
|
59+
LL | let outer: unsafe<> &'a &'b ();
60+
| ^^^^^^^^^^^^^^^^^^^
61+
62+
error: aborting due to 5 previous errors; 1 warning emitted
63+
64+
Some errors have detailed explanations: E0261, E0401.
65+
For more information about an error, try `rustc --explain E0261`.

Diff for: tests/ui/unsafe-binders/simple.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![feature(unsafe_binders)]
2+
//~^ WARN the feature `unsafe_binders` is incomplete
3+
4+
fn main() {
5+
let x: unsafe<'a> &'a ();
6+
//~^ ERROR unsafe binders are not yet implemented
7+
}

Diff for: tests/ui/unsafe-binders/simple.stderr

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
warning: the feature `unsafe_binders` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/simple.rs:1:12
3+
|
4+
LL | #![feature(unsafe_binders)]
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #130516 <https://github.com/rust-lang/rust/issues/130516> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
error: unsafe binders are not yet implemented
11+
--> $DIR/simple.rs:5:12
12+
|
13+
LL | let x: unsafe<'a> &'a ();
14+
| ^^^^^^^^^^^^^^^^^
15+
16+
error: aborting due to 1 previous error; 1 warning emitted
17+

0 commit comments

Comments
 (0)