mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-21 22:34:05 +00:00
Introduce distinct error codes for precise capturing
This commit is contained in:
parent
26bdfefae1
commit
ae8b4607c6
19
compiler/rustc_error_codes/src/error_codes/E0799.md
Normal file
19
compiler/rustc_error_codes/src/error_codes/E0799.md
Normal file
@ -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.
|
11
compiler/rustc_error_codes/src/error_codes/E0800.md
Normal file
11
compiler/rustc_error_codes/src/error_codes/E0800.md
Normal file
@ -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.
|
@ -538,6 +538,8 @@ E0795: 0795,
|
||||
E0796: 0796,
|
||||
E0797: 0797,
|
||||
E0798: 0798,
|
||||
E0799: 0799,
|
||||
E0800: 0800,
|
||||
);
|
||||
)
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
4
tests/ui/error-codes/E0799.rs
Normal file
4
tests/ui/error-codes/E0799.rs
Normal file
@ -0,0 +1,4 @@
|
||||
fn test() -> impl Sized + use<main> {}
|
||||
//~^ ERROR E0799
|
||||
|
||||
fn main() {}
|
9
tests/ui/error-codes/E0799.stderr
Normal file
9
tests/ui/error-codes/E0799.stderr
Normal file
@ -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`.
|
4
tests/ui/error-codes/E0800.rs
Normal file
4
tests/ui/error-codes/E0800.rs
Normal file
@ -0,0 +1,4 @@
|
||||
fn test() -> impl Sized + use<Missing> {}
|
||||
//~^ ERROR E0800
|
||||
|
||||
fn main() {}
|
9
tests/ui/error-codes/E0800.stderr
Normal file
9
tests/ui/error-codes/E0800.stderr
Normal file
@ -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`.
|
@ -1,4 +1,4 @@
|
||||
error[E0412]: cannot find type or const parameter `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> {}
|
||||
@ -17,19 +17,19 @@ LL | fn missing_self() -> impl Sized + use<Self> {}
|
||||
| |
|
||||
| `Self` not allowed in a function
|
||||
|
||||
error[E0573]: expected type or const parameter, found function `hello`
|
||||
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[E0573]: expected type or const parameter, found local variable `x`
|
||||
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: `Self` can't be captured in `use<...>` precise captures list, since it is an alias
|
||||
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 {
|
||||
@ -39,5 +39,5 @@ LL | fn self_is_not_param() -> impl Sized + use<Self> {}
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0411, E0412, E0573.
|
||||
Some errors have detailed explanations: E0411, E0799, E0800.
|
||||
For more information about an error, try `rustc --explain E0411`.
|
||||
|
Loading…
Reference in New Issue
Block a user