about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-09-16 14:59:29 +0000
committerbors <bors@rust-lang.org>2024-09-16 14:59:29 +0000
commit3a22be33db27e4f90e95dfaad301af400386efc1 (patch)
tree48e337f4cf001bdf9e0de0a28b24942972b36fe7 /tests
parent13b5a4e43b92cf738acad403ea56900947f9d37b (diff)
parentae8b4607c6c92164dce2e92f9496de189a43bc44 (diff)
downloadrust-3a22be33db27e4f90e95dfaad301af400386efc1.tar.gz
rust-3a22be33db27e4f90e95dfaad301af400386efc1.zip
Auto merge of #130414 - compiler-errors:precise-capturing-arg-valid, r=jieyouxu
Do precise capturing arg validation in resolve

Moves the validation of precise capturing args (`use<T, N>`) out of `resolve_bound_vars` and into `rustc_resolve`. This both simplifies the impl and fixes a bug when we have `use<arg>` where `arg` is one of the function args.

This also introduces new error codes specifically for precise capturing, to avoid reusing the other error codes which are not as accurate.

Fixes #130399
Diffstat (limited to 'tests')
-rw-r--r--tests/crashes/130399.rs5
-rw-r--r--tests/ui/error-codes/E0799.rs4
-rw-r--r--tests/ui/error-codes/E0799.stderr9
-rw-r--r--tests/ui/error-codes/E0800.rs4
-rw-r--r--tests/ui/error-codes/E0800.stderr9
-rw-r--r--tests/ui/impl-trait/precise-capturing/bad-params.rs9
-rw-r--r--tests/ui/impl-trait/precise-capturing/bad-params.stderr28
7 files changed, 49 insertions, 19 deletions
diff --git a/tests/crashes/130399.rs b/tests/crashes/130399.rs
deleted file mode 100644
index 2248c8c0124..00000000000
--- a/tests/crashes/130399.rs
+++ /dev/null
@@ -1,5 +0,0 @@
-//@ known-bug: rust-lang/rust#130399
-
-fn elided(main: &()) -> impl Sized + use<main> {}
-
-fn main() {}
diff --git a/tests/ui/error-codes/E0799.rs b/tests/ui/error-codes/E0799.rs
new file mode 100644
index 00000000000..a1e5b532669
--- /dev/null
+++ b/tests/ui/error-codes/E0799.rs
@@ -0,0 +1,4 @@
+fn test() -> impl Sized + use<main> {}
+//~^ ERROR E0799
+
+fn main() {}
diff --git a/tests/ui/error-codes/E0799.stderr b/tests/ui/error-codes/E0799.stderr
new file mode 100644
index 00000000000..3639424e466
--- /dev/null
+++ b/tests/ui/error-codes/E0799.stderr
@@ -0,0 +1,9 @@
+error[E0799]: expected type or const parameter, found function `main`
+  --> $DIR/E0799.rs:1:31
+   |
+LL | fn test() -> impl Sized + use<main> {}
+   |                               ^^^^ not a type or const parameter
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0799`.
diff --git a/tests/ui/error-codes/E0800.rs b/tests/ui/error-codes/E0800.rs
new file mode 100644
index 00000000000..6112157feca
--- /dev/null
+++ b/tests/ui/error-codes/E0800.rs
@@ -0,0 +1,4 @@
+fn test() -> impl Sized + use<Missing> {}
+//~^ ERROR E0800
+
+fn main() {}
diff --git a/tests/ui/error-codes/E0800.stderr b/tests/ui/error-codes/E0800.stderr
new file mode 100644
index 00000000000..282981a9173
--- /dev/null
+++ b/tests/ui/error-codes/E0800.stderr
@@ -0,0 +1,9 @@
+error[E0800]: cannot find type or const parameter `Missing` in this scope
+  --> $DIR/E0800.rs:1:31
+   |
+LL | fn test() -> impl Sized + use<Missing> {}
+   |                               ^^^^^^^ not found in this scope
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0800`.
diff --git a/tests/ui/impl-trait/precise-capturing/bad-params.rs b/tests/ui/impl-trait/precise-capturing/bad-params.rs
index 17b517abd74..d1ec48df48c 100644
--- a/tests/ui/impl-trait/precise-capturing/bad-params.rs
+++ b/tests/ui/impl-trait/precise-capturing/bad-params.rs
@@ -1,8 +1,8 @@
 fn missing() -> impl Sized + use<T> {}
-//~^ ERROR cannot find type `T` in this scope
+//~^ ERROR cannot find type or const parameter `T` in this scope
 
 fn missing_self() -> impl Sized + use<Self> {}
-//~^ ERROR cannot find type `Self` in this scope
+//~^ ERROR cannot find type or const parameter `Self` in this scope
 
 struct MyType;
 impl MyType {
@@ -11,6 +11,9 @@ impl MyType {
 }
 
 fn hello() -> impl Sized + use<hello> {}
-//~^ ERROR expected type or const parameter in `use<...>` precise captures list, found function
+//~^ ERROR expected type or const parameter, found function `hello`
+
+fn arg(x: ()) -> impl Sized + use<x> {}
+//~^ ERROR expected type or const parameter, found local variable `x`
 
 fn main() {}
diff --git a/tests/ui/impl-trait/precise-capturing/bad-params.stderr b/tests/ui/impl-trait/precise-capturing/bad-params.stderr
index 06ccf356948..07ada8da300 100644
--- a/tests/ui/impl-trait/precise-capturing/bad-params.stderr
+++ b/tests/ui/impl-trait/precise-capturing/bad-params.stderr
@@ -1,4 +1,4 @@
-error[E0412]: cannot find type `T` in this scope
+error[E0800]: cannot find type or const parameter `T` in this scope
   --> $DIR/bad-params.rs:1:34
    |
 LL | fn missing() -> impl Sized + use<T> {}
@@ -9,7 +9,7 @@ help: you might be missing a type parameter
 LL | fn missing<T>() -> impl Sized + use<T> {}
    |           +++
 
-error[E0411]: cannot find type `Self` in this scope
+error[E0411]: cannot find type or const parameter `Self` in this scope
   --> $DIR/bad-params.rs:4:39
    |
 LL | fn missing_self() -> impl Sized + use<Self> {}
@@ -17,7 +17,19 @@ LL | fn missing_self() -> impl Sized + use<Self> {}
    |    |
    |    `Self` not allowed in a function
 
-error: `Self` can't be captured in `use<...>` precise captures list, since it is an alias
+error[E0799]: expected type or const parameter, found function `hello`
+  --> $DIR/bad-params.rs:13:32
+   |
+LL | fn hello() -> impl Sized + use<hello> {}
+   |                                ^^^^^ not a type or const parameter
+
+error[E0799]: expected type or const parameter, found local variable `x`
+  --> $DIR/bad-params.rs:16:35
+   |
+LL | fn arg(x: ()) -> impl Sized + use<x> {}
+   |                                   ^ not a type or const parameter
+
+error[E0799]: `Self` can't be captured in `use<...>` precise captures list, since it is an alias
   --> $DIR/bad-params.rs:9:48
    |
 LL | impl MyType {
@@ -25,13 +37,7 @@ LL | impl MyType {
 LL |     fn self_is_not_param() -> impl Sized + use<Self> {}
    |                                                ^^^^
 
-error: expected type or const parameter in `use<...>` precise captures list, found function
-  --> $DIR/bad-params.rs:13:32
-   |
-LL | fn hello() -> impl Sized + use<hello> {}
-   |                                ^^^^^
-
-error: aborting due to 4 previous errors
+error: aborting due to 5 previous errors
 
-Some errors have detailed explanations: E0411, E0412.
+Some errors have detailed explanations: E0411, E0799, E0800.
 For more information about an error, try `rustc --explain E0411`.