rustc_hir_analysis/errors/
precise_captures.rs1use rustc_errors::E0799;
2use rustc_macros::Diagnostic;
3use rustc_span::{Span, Symbol};
4
5#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
ParamNotCaptured where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
ParamNotCaptured {
opaque_span: __binding_0,
param_span: __binding_1,
kind: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`impl Trait` must mention all {$kind} parameters in scope in `use<...>`")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("currently, all {$kind} parameters are required to be mentioned in the precise captures list")));
;
diag.arg("kind", __binding_2);
diag.span(__binding_0);
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$kind} parameter is implicitly captured by this `impl Trait`")));
diag
}
}
}
}
};Diagnostic)]
6#[diag("`impl Trait` must mention all {$kind} parameters in scope in `use<...>`")]
7#[note(
8 "currently, all {$kind} parameters are required to be mentioned in the precise captures list"
9)]
10pub(crate) struct ParamNotCaptured {
11 #[primary_span]
12 pub opaque_span: Span,
13 #[label("{$kind} parameter is implicitly captured by this `impl Trait`")]
14 pub param_span: Span,
15 pub kind: &'static str,
16}
17
18#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
SelfTyNotCaptured where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
SelfTyNotCaptured {
opaque_span: __binding_0, trait_span: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`impl Trait` must mention the `Self` type of the trait in `use<...>`")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("currently, all type parameters are required to be mentioned in the precise captures list")));
;
diag.span(__binding_0);
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`Self` type parameter is implicitly captured by this `impl Trait`")));
diag
}
}
}
}
};Diagnostic)]
19#[diag("`impl Trait` must mention the `Self` type of the trait in `use<...>`")]
20#[note("currently, all type parameters are required to be mentioned in the precise captures list")]
21pub(crate) struct SelfTyNotCaptured {
22 #[primary_span]
23 pub opaque_span: Span,
24 #[label("`Self` type parameter is implicitly captured by this `impl Trait`")]
25 pub trait_span: Span,
26}
27
28#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
LifetimeNotCaptured where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
LifetimeNotCaptured {
use_span: __binding_0,
param_span: __binding_1,
opaque_span: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list")));
;
diag.span(__binding_0);
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this lifetime parameter is captured")));
diag.span_label(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime captured due to being mentioned in the bounds of the `impl Trait`")));
diag
}
}
}
}
};Diagnostic)]
29#[diag(
30 "`impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list"
31)]
32pub(crate) struct LifetimeNotCaptured {
33 #[primary_span]
34 pub use_span: Span,
35 #[label("this lifetime parameter is captured")]
36 pub param_span: Span,
37 #[label("lifetime captured due to being mentioned in the bounds of the `impl Trait`")]
38 pub opaque_span: Span,
39}
40
41#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
LifetimeImplicitlyCaptured where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
LifetimeImplicitlyCaptured {
opaque_span: __binding_0, param_span: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list")));
;
diag.span(__binding_0);
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("all lifetime parameters originating from a trait are captured implicitly")));
diag
}
}
}
}
};Diagnostic)]
42#[diag(
43 "`impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list"
44)]
45pub(crate) struct LifetimeImplicitlyCaptured {
46 #[primary_span]
47 pub opaque_span: Span,
48 #[label("all lifetime parameters originating from a trait are captured implicitly")]
49 pub param_span: Span,
50}
51
52#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
BadPreciseCapture where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
BadPreciseCapture {
span: __binding_0, kind: __binding_1, found: __binding_2 }
=> {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected {$kind} parameter in `use<...>` precise captures list, found {$found}")));
;
diag.arg("kind", __binding_1);
diag.arg("found", __binding_2);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
53#[diag("expected {$kind} parameter in `use<...>` precise captures list, found {$found}")]
54pub(crate) struct BadPreciseCapture {
55 #[primary_span]
56 pub span: Span,
57 pub kind: &'static str,
58 pub found: String,
59}
60
61#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
PreciseCaptureSelfAlias where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
PreciseCaptureSelfAlias {
span: __binding_0, self_span: __binding_1, what: __binding_2
} => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`Self` can't be captured in `use<...>` precise captures list, since it is an alias")));
diag.code(E0799);
;
diag.arg("what", __binding_2);
diag.span(__binding_0);
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`Self` is not a generic argument, but an alias to the type of the {$what}")));
diag
}
}
}
}
};Diagnostic)]
62#[diag("`Self` can't be captured in `use<...>` precise captures list, since it is an alias", code = E0799)]
63pub(crate) struct PreciseCaptureSelfAlias {
64 #[primary_span]
65 pub span: Span,
66 #[label("`Self` is not a generic argument, but an alias to the type of the {$what}")]
67 pub self_span: Span,
68 pub what: &'static str,
69}
70
71#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
DuplicatePreciseCapture where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
DuplicatePreciseCapture {
first_span: __binding_0,
name: __binding_1,
second_span: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot capture parameter `{$name}` twice")));
;
diag.arg("name", __binding_1);
diag.span(__binding_0);
diag.span_label(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("parameter captured again here")));
diag
}
}
}
}
};Diagnostic)]
72#[diag("cannot capture parameter `{$name}` twice")]
73pub(crate) struct DuplicatePreciseCapture {
74 #[primary_span]
75 pub first_span: Span,
76 pub name: Symbol,
77 #[label("parameter captured again here")]
78 pub second_span: Span,
79}
80
81#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
LifetimesMustBeFirst where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
LifetimesMustBeFirst {
lifetime_span: __binding_0,
name: __binding_1,
other_span: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime parameter `{$name}` must be listed before non-lifetime parameters")));
;
diag.arg("name", __binding_1);
diag.span(__binding_0);
diag.span_label(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("move the lifetime before this parameter")));
diag
}
}
}
}
};Diagnostic)]
82#[diag("lifetime parameter `{$name}` must be listed before non-lifetime parameters")]
83pub(crate) struct LifetimesMustBeFirst {
84 #[primary_span]
85 pub lifetime_span: Span,
86 pub name: Symbol,
87 #[label("move the lifetime before this parameter")]
88 pub other_span: Span,
89}