Skip to content

Commit

Permalink
Add tests for illegal use bound syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Jun 18, 2024
1 parent b1efe1a commit f66558d
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 5 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ ast_lowering_never_pattern_with_guard =
a guard on a never pattern will never be run
.suggestion = remove this guard
ast_lowering_no_precise_captures_on_apit = `use<...>` precise capturing syntax not allowed on argument-position `impl Trait`
ast_lowering_no_precise_captures_on_apit = `use<...>` precise capturing syntax not allowed in argument-position `impl Trait`
ast_lowering_previously_used_here = previously used here
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ast_passes_assoc_type_without_body =
associated type in `impl` without body
.suggestion = provide a definition for the type
ast_passes_precise_capturing_not_allowed_here = `use<...>` precise capturing syntax is not allowed in {$loc}
ast_passes_precise_capturing_not_allowed_here = `use<...>` precise capturing syntax not allowed in {$loc}
ast_passes_at_least_one_trait = at least one trait must be specified
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
self.dcx().emit_err(errors::PreciseCapturingNotAllowedHere {
loc: ctxt.descr(),
span: *span,
})
});
}
},
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/impl-trait/precise-capturing/apit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
//~^ WARN the feature `precise_capturing` is incomplete

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

fn main() {}
2 changes: 1 addition & 1 deletion tests/ui/impl-trait/precise-capturing/apit.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | #![feature(precise_capturing)]
= note: see issue #123432 <https://github.com/rust-lang/rust/issues/123432> for more information
= note: `#[warn(incomplete_features)]` on by default

error: `use<...>` precise capturing syntax not allowed on argument-position `impl Trait`
error: `use<...>` precise capturing syntax not allowed in argument-position `impl Trait`
--> $DIR/apit.rs:4:26
|
LL | fn hello(_: impl Sized + use<>) {}
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/impl-trait/precise-capturing/dyn-use.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#![feature(precise_capturing)]

fn dyn() -> &'static dyn use<> { &() }
//~^ ERROR expected one of `!`, `(`, `::`, `<`, `where`, or `{`, found keyword `use`
8 changes: 8 additions & 0 deletions tests/ui/impl-trait/precise-capturing/dyn-use.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: expected one of `!`, `(`, `::`, `<`, `where`, or `{`, found keyword `use`
--> $DIR/dyn-use.rs:3:26
|
LL | fn dyn() -> &'static dyn use<> { &() }
| ^^^ expected one of `!`, `(`, `::`, `<`, `where`, or `{`

error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
warning: the feature `precise_capturing` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/illegal-positions.rs:5:12
|
LL | #![feature(precise_capturing)]
| ^^^^^^^^^^^^^^^^^
|
= note: see issue #123432 <https://github.com/rust-lang/rust/issues/123432> for more information
= note: `#[warn(incomplete_features)]` on by default

warning: 1 warning emitted

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
error: `use<...>` precise capturing syntax not allowed in supertrait bounds
--> $DIR/illegal-positions.rs:9:12
|
LL | trait Foo: use<> {
| ^^^^^

error: `use<...>` precise capturing syntax not allowed in bounds
--> $DIR/illegal-positions.rs:11:33
|
LL | type Assoc: use<> where (): use<>;
| ^^^^^

error: `use<...>` precise capturing syntax not allowed in bounds
--> $DIR/illegal-positions.rs:11:17
|
LL | type Assoc: use<> where (): use<>;
| ^^^^^

error: `use<...>` precise capturing syntax not allowed in bounds
--> $DIR/illegal-positions.rs:17:11
|
LL | fn fun<T: use<>>(_: impl use<>) where (): use<> {}
| ^^^^^

error: `use<...>` precise capturing syntax not allowed in bounds
--> $DIR/illegal-positions.rs:17:43
|
LL | fn fun<T: use<>>(_: impl use<>) where (): use<> {}
| ^^^^^

error: at least one trait must be specified
--> $DIR/illegal-positions.rs:17:21
|
LL | fn fun<T: use<>>(_: impl use<>) where (): use<> {}
| ^^^^^^^^^^

error: `use<...>` precise capturing syntax not allowed in `dyn` trait object bounds
--> $DIR/illegal-positions.rs:24:25
|
LL | fn dynamic() -> Box<dyn use<>> {}
| ^^^^^

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

error: `use<...>` precise capturing syntax not allowed in argument-position `impl Trait`
--> $DIR/illegal-positions.rs:17:26
|
LL | fn fun<T: use<>>(_: impl use<>) where (): use<> {}
| ^^^^^

error[E0224]: at least one trait is required for an object type
--> $DIR/illegal-positions.rs:24:21
|
LL | fn dynamic() -> Box<dyn use<>> {}
| ^^^^^^^^^

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

For more information about this error, try `rustc --explain E0224`.
28 changes: 28 additions & 0 deletions tests/ui/impl-trait/precise-capturing/illegal-positions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//@ revisions: real pre_expansion
//@[pre_expansion] check-pass
//@ edition: 2021

#![feature(precise_capturing)]
//~^ WARN the feature `precise_capturing` is incomplete

#[cfg(real)]
trait Foo: use<> {
//[real]~^ ERROR `use<...>` precise capturing syntax not allowed
type Assoc: use<> where (): use<>;
//[real]~^ ERROR `use<...>` precise capturing syntax not allowed
//[real]~| ERROR `use<...>` precise capturing syntax not allowed
}

#[cfg(real)]
fn fun<T: use<>>(_: impl use<>) where (): use<> {}
//[real]~^ ERROR `use<...>` precise capturing syntax not allowed
//[real]~| ERROR `use<...>` precise capturing syntax not allowed
//[real]~| ERROR `use<...>` precise capturing syntax not allowed
//[real]~| ERROR at least one trait must be specified

#[cfg(real)]
fn dynamic() -> Box<dyn use<>> {}
//[real]~^ ERROR `use<...>` precise capturing syntax not allowed in `dyn` trait object bounds
//[real]~| ERROR at least one trait is required for an object type [E0224]

fn main() {}

0 comments on commit f66558d

Please sign in to comment.