about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2024-09-15 17:34:25 -0400
committerMichael Goulet <michael@errs.io>2024-09-16 10:56:22 -0400
commitae8b4607c6c92164dce2e92f9496de189a43bc44 (patch)
tree48e337f4cf001bdf9e0de0a28b24942972b36fe7 /compiler
parent26bdfefae121061187a8206bc0d6702c968a62c0 (diff)
downloadrust-ae8b4607c6c92164dce2e92f9496de189a43bc44.tar.gz
rust-ae8b4607c6c92164dce2e92f9496de189a43bc44.zip
Introduce distinct error codes for precise capturing
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_error_codes/src/error_codes/E0799.md19
-rw-r--r--compiler/rustc_error_codes/src/error_codes/E0800.md11
-rw-r--r--compiler/rustc_error_codes/src/lib.rs2
-rw-r--r--compiler/rustc_hir_analysis/src/errors/precise_captures.rs3
-rw-r--r--compiler/rustc_resolve/src/late.rs7
5 files changed, 38 insertions, 4 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0799.md b/compiler/rustc_error_codes/src/error_codes/E0799.md
new file mode 100644
index 00000000000..38ebc840604
--- /dev/null
+++ b/compiler/rustc_error_codes/src/error_codes/E0799.md
@@ -0,0 +1,19 @@
+Something other than a type or const parameter has been used when one was
+expected.
+
+Erroneous code example:
+
+```compile_fail,E0799
+fn bad1() -> impl Sized + use<main> {}
+
+fn bad2(x: ()) -> impl Sized + use<x> {}
+
+fn main() {}
+```
+
+In the given examples, for `bad1`, the name `main` corresponds to a function
+rather than a type or const parameter. In `bad2`, the name `x` corresponds to
+a function argument rather than a type or const parameter.
+
+Only type and const parameters, including `Self`, may be captured by
+`use<...>` precise capturing bounds.
diff --git a/compiler/rustc_error_codes/src/error_codes/E0800.md b/compiler/rustc_error_codes/src/error_codes/E0800.md
new file mode 100644
index 00000000000..3e08cd499b7
--- /dev/null
+++ b/compiler/rustc_error_codes/src/error_codes/E0800.md
@@ -0,0 +1,11 @@
+A type or const parameter of the given name is not in scope.
+
+Erroneous code examples:
+
+```compile_fail,E0800
+fn missing() -> impl Sized + use<T> {}
+```
+
+To fix this error, please verify you didn't misspell the type or const
+parameter, or double-check if you forgot to declare the parameter in
+the list of generics.
diff --git a/compiler/rustc_error_codes/src/lib.rs b/compiler/rustc_error_codes/src/lib.rs
index 150f99a3ee7..d6f0206b0de 100644
--- a/compiler/rustc_error_codes/src/lib.rs
+++ b/compiler/rustc_error_codes/src/lib.rs
@@ -538,6 +538,8 @@ E0795: 0795,
 E0796: 0796,
 E0797: 0797,
 E0798: 0798,
+E0799: 0799,
+E0800: 0800,
         );
     )
 }
diff --git a/compiler/rustc_hir_analysis/src/errors/precise_captures.rs b/compiler/rustc_hir_analysis/src/errors/precise_captures.rs
index af2bb053c0a..b6cffb90805 100644
--- a/compiler/rustc_hir_analysis/src/errors/precise_captures.rs
+++ b/compiler/rustc_hir_analysis/src/errors/precise_captures.rs
@@ -1,3 +1,4 @@
+use rustc_errors::E0799;
 use rustc_macros::Diagnostic;
 use rustc_span::{Span, Symbol};
 
@@ -43,7 +44,7 @@ pub(crate) struct BadPreciseCapture {
 }
 
 #[derive(Diagnostic)]
-#[diag(hir_analysis_precise_capture_self_alias)]
+#[diag(hir_analysis_precise_capture_self_alias, code = E0799)]
 pub(crate) struct PreciseCaptureSelfAlias {
     #[primary_span]
     pub span: Span,
diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs
index 148f55986ba..4bf2cc287da 100644
--- a/compiler/rustc_resolve/src/late.rs
+++ b/compiler/rustc_resolve/src/late.rs
@@ -557,9 +557,8 @@ impl<'a> PathSource<'a> {
         match (self, has_unexpected_resolution) {
             (PathSource::Trait(_), true) => E0404,
             (PathSource::Trait(_), false) => E0405,
-            // TODO:
-            (PathSource::Type | PathSource::PreciseCapturingArg(..), true) => E0573,
-            (PathSource::Type | PathSource::PreciseCapturingArg(..), false) => E0412,
+            (PathSource::Type, true) => E0573,
+            (PathSource::Type, false) => E0412,
             (PathSource::Struct, true) => E0574,
             (PathSource::Struct, false) => E0422,
             (PathSource::Expr(..), true) | (PathSource::Delegation, true) => E0423,
@@ -568,6 +567,8 @@ impl<'a> PathSource<'a> {
             (PathSource::Pat | PathSource::TupleStruct(..), false) => E0531,
             (PathSource::TraitItem(..), true) => E0575,
             (PathSource::TraitItem(..), false) => E0576,
+            (PathSource::PreciseCapturingArg(..), true) => E0799,
+            (PathSource::PreciseCapturingArg(..), false) => E0800,
         }
     }
 }