Skip to content

Commit a9617b4

Browse files
Introduce distinct error codes for precise capturing
1 parent 9d1af81 commit a9617b4

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

compiler/rustc_error_codes/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,8 @@ E0795: 0795,
538538
E0796: 0796,
539539
E0797: 0797,
540540
E0798: 0798,
541+
E0799: 0799,
542+
E0800: 0800,
541543
);
542544
)
543545
}

compiler/rustc_hir_analysis/src/errors/precise_captures.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use rustc_errors::E0799;
12
use rustc_macros::Diagnostic;
23
use rustc_span::{Span, Symbol};
34

@@ -43,7 +44,7 @@ pub(crate) struct BadPreciseCapture {
4344
}
4445

4546
#[derive(Diagnostic)]
46-
#[diag(hir_analysis_precise_capture_self_alias)]
47+
#[diag(hir_analysis_precise_capture_self_alias, code = E0799)]
4748
pub(crate) struct PreciseCaptureSelfAlias {
4849
#[primary_span]
4950
pub span: Span,

compiler/rustc_resolve/src/late.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,8 @@ impl<'a> PathSource<'a> {
557557
match (self, has_unexpected_resolution) {
558558
(PathSource::Trait(_), true) => E0404,
559559
(PathSource::Trait(_), false) => E0405,
560-
// TODO:
561-
(PathSource::Type | PathSource::PreciseCapturingArg(..), true) => E0573,
562-
(PathSource::Type | PathSource::PreciseCapturingArg(..), false) => E0412,
560+
(PathSource::Type, true) => E0573,
561+
(PathSource::Type, false) => E0412,
563562
(PathSource::Struct, true) => E0574,
564563
(PathSource::Struct, false) => E0422,
565564
(PathSource::Expr(..), true) | (PathSource::Delegation, true) => E0423,
@@ -568,6 +567,8 @@ impl<'a> PathSource<'a> {
568567
(PathSource::Pat | PathSource::TupleStruct(..), false) => E0531,
569568
(PathSource::TraitItem(..), true) => E0575,
570569
(PathSource::TraitItem(..), false) => E0576,
570+
(PathSource::PreciseCapturingArg(..), true) => E0799,
571+
(PathSource::PreciseCapturingArg(..), false) => E0800,
571572
}
572573
}
573574
}

tests/ui/impl-trait/precise-capturing/bad-params.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0412]: cannot find type or const parameter `T` in this scope
1+
error[E0800]: cannot find type or const parameter `T` in this scope
22
--> $DIR/bad-params.rs:1:34
33
|
44
LL | fn missing() -> impl Sized + use<T> {}
@@ -17,19 +17,19 @@ LL | fn missing_self() -> impl Sized + use<Self> {}
1717
| |
1818
| `Self` not allowed in a function
1919

20-
error[E0573]: expected type or const parameter, found function `hello`
20+
error[E0799]: expected type or const parameter, found function `hello`
2121
--> $DIR/bad-params.rs:13:32
2222
|
2323
LL | fn hello() -> impl Sized + use<hello> {}
2424
| ^^^^^ not a type or const parameter
2525

26-
error[E0573]: expected type or const parameter, found local variable `x`
26+
error[E0799]: expected type or const parameter, found local variable `x`
2727
--> $DIR/bad-params.rs:16:35
2828
|
2929
LL | fn arg(x: ()) -> impl Sized + use<x> {}
3030
| ^ not a type or const parameter
3131

32-
error: `Self` can't be captured in `use<...>` precise captures list, since it is an alias
32+
error[E0799]: `Self` can't be captured in `use<...>` precise captures list, since it is an alias
3333
--> $DIR/bad-params.rs:9:48
3434
|
3535
LL | impl MyType {
@@ -39,5 +39,5 @@ LL | fn self_is_not_param() -> impl Sized + use<Self> {}
3939

4040
error: aborting due to 5 previous errors
4141

42-
Some errors have detailed explanations: E0411, E0412, E0573.
42+
Some errors have detailed explanations: E0411, E0799, E0800.
4343
For more information about an error, try `rustc --explain E0411`.

0 commit comments

Comments
 (0)