about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2024-06-05 16:31:12 -0400
committerMichael Goulet <michael@errs.io>2024-06-17 22:35:25 -0400
commitf66558d2bfe2bbfac14f8c0472a300bbd5234ce2 (patch)
treec65e93429beadc0c2a41aea81e356bd6d6cf2992
parentb1efe1ab5d10c5dc0462445273ca4e42dea3c5e3 (diff)
downloadrust-f66558d2bfe2bbfac14f8c0472a300bbd5234ce2.tar.gz
rust-f66558d2bfe2bbfac14f8c0472a300bbd5234ce2.zip
Add tests for illegal use bound syntax
-rw-r--r--compiler/rustc_ast_lowering/messages.ftl2
-rw-r--r--compiler/rustc_ast_passes/messages.ftl2
-rw-r--r--compiler/rustc_ast_passes/src/ast_validation.rs2
-rw-r--r--tests/ui/impl-trait/precise-capturing/apit.rs2
-rw-r--r--tests/ui/impl-trait/precise-capturing/apit.stderr2
-rw-r--r--tests/ui/impl-trait/precise-capturing/dyn-use.rs4
-rw-r--r--tests/ui/impl-trait/precise-capturing/dyn-use.stderr8
-rw-r--r--tests/ui/impl-trait/precise-capturing/illegal-positions.pre_expansion.stderr11
-rw-r--r--tests/ui/impl-trait/precise-capturing/illegal-positions.real.stderr66
-rw-r--r--tests/ui/impl-trait/precise-capturing/illegal-positions.rs28
10 files changed, 122 insertions, 5 deletions
diff --git a/compiler/rustc_ast_lowering/messages.ftl b/compiler/rustc_ast_lowering/messages.ftl
index 10efe6fba65..7d81e45d314 100644
--- a/compiler/rustc_ast_lowering/messages.ftl
+++ b/compiler/rustc_ast_lowering/messages.ftl
@@ -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
 
diff --git a/compiler/rustc_ast_passes/messages.ftl b/compiler/rustc_ast_passes/messages.ftl
index af27429b508..518ac9256a1 100644
--- a/compiler/rustc_ast_passes/messages.ftl
+++ b/compiler/rustc_ast_passes/messages.ftl
@@ -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
 
diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs
index 04c06e76e9c..de96bdd557f 100644
--- a/compiler/rustc_ast_passes/src/ast_validation.rs
+++ b/compiler/rustc_ast_passes/src/ast_validation.rs
@@ -1424,7 +1424,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
                     self.dcx().emit_err(errors::PreciseCapturingNotAllowedHere {
                         loc: ctxt.descr(),
                         span: *span,
-                    })
+                    });
                 }
             },
         }
diff --git a/tests/ui/impl-trait/precise-capturing/apit.rs b/tests/ui/impl-trait/precise-capturing/apit.rs
index 98e7da4e34a..961438c9d87 100644
--- a/tests/ui/impl-trait/precise-capturing/apit.rs
+++ b/tests/ui/impl-trait/precise-capturing/apit.rs
@@ -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() {}
diff --git a/tests/ui/impl-trait/precise-capturing/apit.stderr b/tests/ui/impl-trait/precise-capturing/apit.stderr
index b676ed260cb..431c619bef7 100644
--- a/tests/ui/impl-trait/precise-capturing/apit.stderr
+++ b/tests/ui/impl-trait/precise-capturing/apit.stderr
@@ -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<>) {}
diff --git a/tests/ui/impl-trait/precise-capturing/dyn-use.rs b/tests/ui/impl-trait/precise-capturing/dyn-use.rs
new file mode 100644
index 00000000000..ce7a0f3c7b2
--- /dev/null
+++ b/tests/ui/impl-trait/precise-capturing/dyn-use.rs
@@ -0,0 +1,4 @@
+#![feature(precise_capturing)]
+
+fn dyn() -> &'static dyn use<> { &() }
+//~^ ERROR expected one of `!`, `(`, `::`, `<`, `where`, or `{`, found keyword `use`
diff --git a/tests/ui/impl-trait/precise-capturing/dyn-use.stderr b/tests/ui/impl-trait/precise-capturing/dyn-use.stderr
new file mode 100644
index 00000000000..5519633de1f
--- /dev/null
+++ b/tests/ui/impl-trait/precise-capturing/dyn-use.stderr
@@ -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
+
diff --git a/tests/ui/impl-trait/precise-capturing/illegal-positions.pre_expansion.stderr b/tests/ui/impl-trait/precise-capturing/illegal-positions.pre_expansion.stderr
new file mode 100644
index 00000000000..7364dc7ffcf
--- /dev/null
+++ b/tests/ui/impl-trait/precise-capturing/illegal-positions.pre_expansion.stderr
@@ -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
+
diff --git a/tests/ui/impl-trait/precise-capturing/illegal-positions.real.stderr b/tests/ui/impl-trait/precise-capturing/illegal-positions.real.stderr
new file mode 100644
index 00000000000..35fda00a7cb
--- /dev/null
+++ b/tests/ui/impl-trait/precise-capturing/illegal-positions.real.stderr
@@ -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`.
diff --git a/tests/ui/impl-trait/precise-capturing/illegal-positions.rs b/tests/ui/impl-trait/precise-capturing/illegal-positions.rs
new file mode 100644
index 00000000000..58f7a02cd87
--- /dev/null
+++ b/tests/ui/impl-trait/precise-capturing/illegal-positions.rs
@@ -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() {}