Skip to content

Commit f66558d

Browse files
Add tests for illegal use bound syntax
1 parent b1efe1a commit f66558d

File tree

10 files changed

+122
-5
lines changed

10 files changed

+122
-5
lines changed

compiler/rustc_ast_lowering/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ ast_lowering_never_pattern_with_guard =
128128
a guard on a never pattern will never be run
129129
.suggestion = remove this guard
130130
131-
ast_lowering_no_precise_captures_on_apit = `use<...>` precise capturing syntax not allowed on argument-position `impl Trait`
131+
ast_lowering_no_precise_captures_on_apit = `use<...>` precise capturing syntax not allowed in argument-position `impl Trait`
132132
133133
ast_lowering_previously_used_here = previously used here
134134

compiler/rustc_ast_passes/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ ast_passes_assoc_type_without_body =
1414
associated type in `impl` without body
1515
.suggestion = provide a definition for the type
1616
17-
ast_passes_precise_capturing_not_allowed_here = `use<...>` precise capturing syntax is not allowed in {$loc}
17+
ast_passes_precise_capturing_not_allowed_here = `use<...>` precise capturing syntax not allowed in {$loc}
1818
1919
ast_passes_at_least_one_trait = at least one trait must be specified
2020

compiler/rustc_ast_passes/src/ast_validation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
14241424
self.dcx().emit_err(errors::PreciseCapturingNotAllowedHere {
14251425
loc: ctxt.descr(),
14261426
span: *span,
1427-
})
1427+
});
14281428
}
14291429
},
14301430
}

tests/ui/impl-trait/precise-capturing/apit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
//~^ WARN the feature `precise_capturing` is incomplete
33

44
fn hello(_: impl Sized + use<>) {}
5-
//~^ ERROR `use<...>` precise capturing syntax not allowed on argument-position `impl Trait`
5+
//~^ ERROR `use<...>` precise capturing syntax not allowed in argument-position `impl Trait`
66

77
fn main() {}

tests/ui/impl-trait/precise-capturing/apit.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | #![feature(precise_capturing)]
77
= note: see issue #123432 <https://github.com/rust-lang/rust/issues/123432> for more information
88
= note: `#[warn(incomplete_features)]` on by default
99

10-
error: `use<...>` precise capturing syntax not allowed on argument-position `impl Trait`
10+
error: `use<...>` precise capturing syntax not allowed in argument-position `impl Trait`
1111
--> $DIR/apit.rs:4:26
1212
|
1313
LL | fn hello(_: impl Sized + use<>) {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#![feature(precise_capturing)]
2+
3+
fn dyn() -> &'static dyn use<> { &() }
4+
//~^ ERROR expected one of `!`, `(`, `::`, `<`, `where`, or `{`, found keyword `use`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: expected one of `!`, `(`, `::`, `<`, `where`, or `{`, found keyword `use`
2+
--> $DIR/dyn-use.rs:3:26
3+
|
4+
LL | fn dyn() -> &'static dyn use<> { &() }
5+
| ^^^ expected one of `!`, `(`, `::`, `<`, `where`, or `{`
6+
7+
error: aborting due to 1 previous error
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `precise_capturing` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/illegal-positions.rs:5:12
3+
|
4+
LL | #![feature(precise_capturing)]
5+
| ^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #123432 <https://github.com/rust-lang/rust/issues/123432> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
error: `use<...>` precise capturing syntax not allowed in supertrait bounds
2+
--> $DIR/illegal-positions.rs:9:12
3+
|
4+
LL | trait Foo: use<> {
5+
| ^^^^^
6+
7+
error: `use<...>` precise capturing syntax not allowed in bounds
8+
--> $DIR/illegal-positions.rs:11:33
9+
|
10+
LL | type Assoc: use<> where (): use<>;
11+
| ^^^^^
12+
13+
error: `use<...>` precise capturing syntax not allowed in bounds
14+
--> $DIR/illegal-positions.rs:11:17
15+
|
16+
LL | type Assoc: use<> where (): use<>;
17+
| ^^^^^
18+
19+
error: `use<...>` precise capturing syntax not allowed in bounds
20+
--> $DIR/illegal-positions.rs:17:11
21+
|
22+
LL | fn fun<T: use<>>(_: impl use<>) where (): use<> {}
23+
| ^^^^^
24+
25+
error: `use<...>` precise capturing syntax not allowed in bounds
26+
--> $DIR/illegal-positions.rs:17:43
27+
|
28+
LL | fn fun<T: use<>>(_: impl use<>) where (): use<> {}
29+
| ^^^^^
30+
31+
error: at least one trait must be specified
32+
--> $DIR/illegal-positions.rs:17:21
33+
|
34+
LL | fn fun<T: use<>>(_: impl use<>) where (): use<> {}
35+
| ^^^^^^^^^^
36+
37+
error: `use<...>` precise capturing syntax not allowed in `dyn` trait object bounds
38+
--> $DIR/illegal-positions.rs:24:25
39+
|
40+
LL | fn dynamic() -> Box<dyn use<>> {}
41+
| ^^^^^
42+
43+
warning: the feature `precise_capturing` is incomplete and may not be safe to use and/or cause compiler crashes
44+
--> $DIR/illegal-positions.rs:5:12
45+
|
46+
LL | #![feature(precise_capturing)]
47+
| ^^^^^^^^^^^^^^^^^
48+
|
49+
= note: see issue #123432 <https://github.com/rust-lang/rust/issues/123432> for more information
50+
= note: `#[warn(incomplete_features)]` on by default
51+
52+
error: `use<...>` precise capturing syntax not allowed in argument-position `impl Trait`
53+
--> $DIR/illegal-positions.rs:17:26
54+
|
55+
LL | fn fun<T: use<>>(_: impl use<>) where (): use<> {}
56+
| ^^^^^
57+
58+
error[E0224]: at least one trait is required for an object type
59+
--> $DIR/illegal-positions.rs:24:21
60+
|
61+
LL | fn dynamic() -> Box<dyn use<>> {}
62+
| ^^^^^^^^^
63+
64+
error: aborting due to 9 previous errors; 1 warning emitted
65+
66+
For more information about this error, try `rustc --explain E0224`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//@ revisions: real pre_expansion
2+
//@[pre_expansion] check-pass
3+
//@ edition: 2021
4+
5+
#![feature(precise_capturing)]
6+
//~^ WARN the feature `precise_capturing` is incomplete
7+
8+
#[cfg(real)]
9+
trait Foo: use<> {
10+
//[real]~^ ERROR `use<...>` precise capturing syntax not allowed
11+
type Assoc: use<> where (): use<>;
12+
//[real]~^ ERROR `use<...>` precise capturing syntax not allowed
13+
//[real]~| ERROR `use<...>` precise capturing syntax not allowed
14+
}
15+
16+
#[cfg(real)]
17+
fn fun<T: use<>>(_: impl use<>) where (): use<> {}
18+
//[real]~^ ERROR `use<...>` precise capturing syntax not allowed
19+
//[real]~| ERROR `use<...>` precise capturing syntax not allowed
20+
//[real]~| ERROR `use<...>` precise capturing syntax not allowed
21+
//[real]~| ERROR at least one trait must be specified
22+
23+
#[cfg(real)]
24+
fn dynamic() -> Box<dyn use<>> {}
25+
//[real]~^ ERROR `use<...>` precise capturing syntax not allowed in `dyn` trait object bounds
26+
//[real]~| ERROR at least one trait is required for an object type [E0224]
27+
28+
fn main() {}

0 commit comments

Comments
 (0)