1use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
2use rustc_errors::codes::*;
3use rustc_errors::formatting::DiagMessageAddArg;
4use rustc_errors::{
5 Applicability, Diag, DiagCtxtHandle, DiagMessage, DiagStyledString, Diagnostic,
6 EmissionGuarantee, IntoDiagArg, Level, MultiSpan, Subdiagnostic, msg,
7};
8use rustc_hir::def::DefKind;
9use rustc_hir::def_id::{DefId, LocalDefId};
10use rustc_hir::intravisit::{Visitor, VisitorExt, walk_ty};
11use rustc_hir::{self as hir, AmbigArg, FnRetTy, GenericParamKind, Node};
12use rustc_macros::{Diagnostic, Subdiagnostic};
13use rustc_middle::ty::print::{PrintTraitRefExt as _, TraitRefPrintOnlyTraitPath};
14use rustc_middle::ty::{self, Binder, ClosureKind, FnSig, GenericArg, Region, Ty, TyCtxt};
15use rustc_span::{BytePos, Ident, Span, Symbol, kw, sym};
16
17use crate::error_reporting::infer::ObligationCauseAsDiagArg;
18use crate::error_reporting::infer::need_type_info::UnderspecifiedArgKind;
19use crate::error_reporting::infer::nice_region_error::placeholder_error::Highlighted;
20
21pub mod note_and_explain;
22
23#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
UnableToConstructConstantValue<'a> 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 {
UnableToConstructConstantValue {
span: __binding_0, unevaluated: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unable to construct a constant value for the unevaluated constant {$unevaluated}")));
;
diag.arg("unevaluated", __binding_1);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
24#[diag("unable to construct a constant value for the unevaluated constant {$unevaluated}")]
25pub struct UnableToConstructConstantValue<'a> {
26 #[primary_span]
27 pub span: Span,
28 pub unevaluated: ty::UnevaluatedConst<'a>,
29}
30
31#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
NoValueInOnUnimplemented 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 {
NoValueInOnUnimplemented { span: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this attribute must have a value")));
diag.code(E0232);
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("e.g. `#[rustc_on_unimplemented(message=\"foo\")]`")));
;
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected value here")));
diag
}
}
}
}
};Diagnostic)]
32#[diag("this attribute must have a value", code = E0232)]
33#[note("e.g. `#[rustc_on_unimplemented(message=\"foo\")]`")]
34pub struct NoValueInOnUnimplemented {
35 #[primary_span]
36 #[label("expected value here")]
37 pub span: Span,
38}
39
40pub struct NegativePositiveConflict<'tcx> {
41 pub impl_span: Span,
42 pub trait_desc: ty::TraitRef<'tcx>,
43 pub self_ty: Option<Ty<'tcx>>,
44 pub negative_impl_span: Result<Span, Symbol>,
45 pub positive_impl_span: Result<Span, Symbol>,
46}
47
48impl<G: EmissionGuarantee> Diagnostic<'_, G> for NegativePositiveConflict<'_> {
49 #[track_caller]
50 fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
51 let mut diag = Diag::new(
52 dcx,
53 level,
54 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("found both positive and negative implementation of trait `{$trait_desc}`{$self_desc ->\n [none] {\"\"}\n *[default] {\" \"}for type `{$self_desc}`\n }:"))msg!(
55 "found both positive and negative implementation of trait `{$trait_desc}`{$self_desc ->
56 [none] {\"\"}
57 *[default] {\" \"}for type `{$self_desc}`
58 }:"
59 ),
60 );
61 diag.arg("trait_desc", self.trait_desc.print_only_trait_path().to_string());
62 diag.arg("self_desc", self.self_ty.map_or_else(|| "none".to_string(), |ty| ty.to_string()));
63 diag.span(self.impl_span);
64 diag.code(E0751);
65 match self.negative_impl_span {
66 Ok(span) => {
67 diag.span_label(span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("negative implementation here"))msg!("negative implementation here"));
68 }
69 Err(cname) => {
70 diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("negative implementation in crate `{$negative_impl_cname}`"))msg!("negative implementation in crate `{$negative_impl_cname}`"));
71 diag.arg("negative_impl_cname", cname.to_string());
72 }
73 }
74 match self.positive_impl_span {
75 Ok(span) => {
76 diag.span_label(span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("positive implementation here"))msg!("positive implementation here"));
77 }
78 Err(cname) => {
79 diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("positive implementation in crate `{$positive_impl_cname}`"))msg!("positive implementation in crate `{$positive_impl_cname}`"));
80 diag.arg("positive_impl_cname", cname.to_string());
81 }
82 }
83 diag
84 }
85}
86
87#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
InherentProjectionNormalizationOverflow 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 {
InherentProjectionNormalizationOverflow {
span: __binding_0, ty: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("overflow evaluating associated type `{$ty}`")));
;
diag.arg("ty", __binding_1);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
88#[diag("overflow evaluating associated type `{$ty}`")]
89pub struct InherentProjectionNormalizationOverflow {
90 #[primary_span]
91 pub span: Span,
92 pub ty: String,
93}
94
95pub enum AdjustSignatureBorrow {
96 Borrow { to_borrow: Vec<(Span, String)> },
97 RemoveBorrow { remove_borrow: Vec<(Span, String)> },
98}
99
100impl Subdiagnostic for AdjustSignatureBorrow {
101 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
102 match self {
103 AdjustSignatureBorrow::Borrow { to_borrow } => {
104 diag.arg("borrow_len", to_borrow.len());
105 diag.multipart_suggestion(
106 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider adjusting the signature so it borrows its {$borrow_len ->\n [one] argument\n *[other] arguments\n }"))msg!(
107 "consider adjusting the signature so it borrows its {$borrow_len ->
108 [one] argument
109 *[other] arguments
110 }"
111 ),
112 to_borrow,
113 Applicability::MaybeIncorrect,
114 );
115 }
116 AdjustSignatureBorrow::RemoveBorrow { remove_borrow } => {
117 diag.arg("remove_borrow_len", remove_borrow.len());
118 diag.multipart_suggestion(
119 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider adjusting the signature so it does not borrow its {$remove_borrow_len ->\n [one] argument\n *[other] arguments\n }"))msg!(
120 "consider adjusting the signature so it does not borrow its {$remove_borrow_len ->
121 [one] argument
122 *[other] arguments
123 }"
124 ),
125 remove_borrow,
126 Applicability::MaybeIncorrect,
127 );
128 }
129 }
130 }
131}
132
133#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
ClosureKindMismatch 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 {
ClosureKindMismatch {
closure_span: __binding_0,
expected: __binding_1,
found: __binding_2,
cause_span: __binding_3,
trait_prefix: __binding_4,
fn_once_label: __binding_5,
fn_mut_label: __binding_6 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected a closure that implements the `{$trait_prefix}{$expected}` trait, but this closure only implements `{$trait_prefix}{$found}`")));
diag.code(E0525);
;
diag.arg("expected", __binding_1);
diag.arg("found", __binding_2);
diag.arg("trait_prefix", __binding_4);
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this closure implements `{$trait_prefix}{$found}`, not `{$trait_prefix}{$expected}`")));
diag.span_label(__binding_3,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the requirement to implement `{$trait_prefix}{$expected}` derives from here")));
if let Some(__binding_5) = __binding_5 {
diag.subdiagnostic(__binding_5);
}
if let Some(__binding_6) = __binding_6 {
diag.subdiagnostic(__binding_6);
}
diag
}
}
}
}
};Diagnostic)]
134#[diag("expected a closure that implements the `{$trait_prefix}{$expected}` trait, but this closure only implements `{$trait_prefix}{$found}`", code = E0525)]
135pub struct ClosureKindMismatch {
136 #[primary_span]
137 #[label("this closure implements `{$trait_prefix}{$found}`, not `{$trait_prefix}{$expected}`")]
138 pub closure_span: Span,
139 pub expected: ClosureKind,
140 pub found: ClosureKind,
141 #[label("the requirement to implement `{$trait_prefix}{$expected}` derives from here")]
142 pub cause_span: Span,
143
144 pub trait_prefix: &'static str,
145
146 #[subdiagnostic]
147 pub fn_once_label: Option<ClosureFnOnceLabel>,
148
149 #[subdiagnostic]
150 pub fn_mut_label: Option<ClosureFnMutLabel>,
151}
152
153#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for ClosureFnOnceLabel {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
ClosureFnOnceLabel {
span: __binding_0,
place: __binding_1,
trait_prefix: __binding_2 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("place".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("trait_prefix".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("closure is `{$trait_prefix}FnOnce` because it moves the variable `{$place}` out of its environment")),
&sub_args);
diag.span_label(__binding_0, __message);
}
}
}
}
};Subdiagnostic)]
154#[label(
155 "closure is `{$trait_prefix}FnOnce` because it moves the variable `{$place}` out of its environment"
156)]
157pub struct ClosureFnOnceLabel {
158 #[primary_span]
159 pub span: Span,
160 pub place: String,
161 pub trait_prefix: &'static str,
162}
163
164#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for ClosureFnMutLabel {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
ClosureFnMutLabel {
span: __binding_0,
place: __binding_1,
trait_prefix: __binding_2 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("place".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("trait_prefix".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("closure is `{$trait_prefix}FnMut` because it mutates the variable `{$place}` here")),
&sub_args);
diag.span_label(__binding_0, __message);
}
}
}
}
};Subdiagnostic)]
165#[label("closure is `{$trait_prefix}FnMut` because it mutates the variable `{$place}` here")]
166pub struct ClosureFnMutLabel {
167 #[primary_span]
168 pub span: Span,
169 pub place: String,
170 pub trait_prefix: &'static str,
171}
172
173#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
CoroClosureNotFn 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 {
CoroClosureNotFn {
span: __binding_0, kind: __binding_1, coro_kind: __binding_2
} => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$coro_kind}closure does not implement `{$kind}` because it captures state from its environment")));
;
diag.arg("kind", __binding_1);
diag.arg("coro_kind", __binding_2);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
174#[diag(
175 "{$coro_kind}closure does not implement `{$kind}` because it captures state from its environment"
176)]
177pub(crate) struct CoroClosureNotFn {
178 #[primary_span]
179 pub span: Span,
180 pub kind: &'static str,
181 pub coro_kind: String,
182}
183
184#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
AnnotationRequired<'a> 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 {
AnnotationRequired {
span: __binding_0,
source_kind: __binding_1,
source_name: __binding_2,
failure_span: __binding_3,
bad_label: __binding_4,
infer_subdiags: __binding_5,
multi_suggestions: __binding_6 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$source_kind ->\n[closure] type annotations needed for the closure `{$source_name}`\n[normal] type annotations needed for `{$source_name}`\n*[other] type annotations needed\n}")));
diag.code(E0282);
;
diag.arg("source_kind", __binding_1);
diag.arg("source_name", __binding_2);
diag.span(__binding_0);
if let Some(__binding_3) = __binding_3 {
diag.span_label(__binding_3,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("type must be known at this point")));
}
if let Some(__binding_4) = __binding_4 {
diag.subdiagnostic(__binding_4);
}
for __binding_5 in __binding_5 {
diag.subdiagnostic(__binding_5);
}
for __binding_6 in __binding_6 {
diag.subdiagnostic(__binding_6);
}
diag
}
}
}
}
};Diagnostic)]
185#[diag("{$source_kind ->
186[closure] type annotations needed for the closure `{$source_name}`
187[normal] type annotations needed for `{$source_name}`
188*[other] type annotations needed
189}", code = E0282)]
190pub struct AnnotationRequired<'a> {
191 #[primary_span]
192 pub span: Span,
193 pub source_kind: &'static str,
194 pub source_name: &'a str,
195 #[label("type must be known at this point")]
196 pub failure_span: Option<Span>,
197 #[subdiagnostic]
198 pub bad_label: Option<InferenceBadError<'a>>,
199 #[subdiagnostic]
200 pub infer_subdiags: Vec<SourceKindSubdiag<'a>>,
201 #[subdiagnostic]
202 pub multi_suggestions: Vec<SourceKindMultiSuggestion<'a>>,
203}
204
205#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
AmbiguousImpl<'a> 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 {
AmbiguousImpl {
span: __binding_0,
source_kind: __binding_1,
source_name: __binding_2,
failure_span: __binding_3,
bad_label: __binding_4,
infer_subdiags: __binding_5,
multi_suggestions: __binding_6 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$source_kind ->\n[closure] type annotations needed for the closure `{$source_name}`\n[normal] type annotations needed for `{$source_name}`\n*[other] type annotations needed\n}")));
diag.code(E0283);
;
diag.arg("source_kind", __binding_1);
diag.arg("source_name", __binding_2);
diag.span(__binding_0);
if let Some(__binding_3) = __binding_3 {
diag.span_label(__binding_3,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("type must be known at this point")));
}
if let Some(__binding_4) = __binding_4 {
diag.subdiagnostic(__binding_4);
}
for __binding_5 in __binding_5 {
diag.subdiagnostic(__binding_5);
}
for __binding_6 in __binding_6 {
diag.subdiagnostic(__binding_6);
}
diag
}
}
}
}
};Diagnostic)]
207#[diag("{$source_kind ->
208[closure] type annotations needed for the closure `{$source_name}`
209[normal] type annotations needed for `{$source_name}`
210*[other] type annotations needed
211}", code = E0283)]
212pub struct AmbiguousImpl<'a> {
213 #[primary_span]
214 pub span: Span,
215 pub source_kind: &'static str,
216 pub source_name: &'a str,
217 #[label("type must be known at this point")]
218 pub failure_span: Option<Span>,
219 #[subdiagnostic]
220 pub bad_label: Option<InferenceBadError<'a>>,
221 #[subdiagnostic]
222 pub infer_subdiags: Vec<SourceKindSubdiag<'a>>,
223 #[subdiagnostic]
224 pub multi_suggestions: Vec<SourceKindMultiSuggestion<'a>>,
225}
226
227#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
AmbiguousReturn<'a> 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 {
AmbiguousReturn {
span: __binding_0,
source_kind: __binding_1,
source_name: __binding_2,
failure_span: __binding_3,
bad_label: __binding_4,
infer_subdiags: __binding_5,
multi_suggestions: __binding_6 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$source_kind ->\n[closure] type annotations needed for the closure `{$source_name}`\n[normal] type annotations needed for `{$source_name}`\n*[other] type annotations needed\n}")));
diag.code(E0284);
;
diag.arg("source_kind", __binding_1);
diag.arg("source_name", __binding_2);
diag.span(__binding_0);
if let Some(__binding_3) = __binding_3 {
diag.span_label(__binding_3,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("type must be known at this point")));
}
if let Some(__binding_4) = __binding_4 {
diag.subdiagnostic(__binding_4);
}
for __binding_5 in __binding_5 {
diag.subdiagnostic(__binding_5);
}
for __binding_6 in __binding_6 {
diag.subdiagnostic(__binding_6);
}
diag
}
}
}
}
};Diagnostic)]
229#[diag("{$source_kind ->
230[closure] type annotations needed for the closure `{$source_name}`
231[normal] type annotations needed for `{$source_name}`
232*[other] type annotations needed
233}", code = E0284)]
234pub struct AmbiguousReturn<'a> {
235 #[primary_span]
236 pub span: Span,
237 pub source_kind: &'static str,
238 pub source_name: &'a str,
239 #[label("type must be known at this point")]
240 pub failure_span: Option<Span>,
241 #[subdiagnostic]
242 pub bad_label: Option<InferenceBadError<'a>>,
243 #[subdiagnostic]
244 pub infer_subdiags: Vec<SourceKindSubdiag<'a>>,
245 #[subdiagnostic]
246 pub multi_suggestions: Vec<SourceKindMultiSuggestion<'a>>,
247}
248
249#[derive(const _: () =
{
impl<'a> rustc_errors::Subdiagnostic for InferenceBadError<'a> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
InferenceBadError {
span: __binding_0,
bad_kind: __binding_1,
prefix_kind: __binding_2,
has_parent: __binding_3,
prefix: __binding_4,
parent_prefix: __binding_5,
parent_name: __binding_6,
name: __binding_7 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("bad_kind".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("prefix_kind".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
sub_args.insert("has_parent".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
&mut diag.long_ty_path));
sub_args.insert("prefix".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_4,
&mut diag.long_ty_path));
sub_args.insert("parent_prefix".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_5,
&mut diag.long_ty_path));
sub_args.insert("parent_name".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_6,
&mut diag.long_ty_path));
sub_args.insert("name".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_7,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$bad_kind ->\n*[other] cannot infer type\n[more_info] cannot infer {$prefix_kind ->\n*[type] type for {$prefix}\n[const_with_param] the value of const parameter\n[const] the value of the constant\n} `{$name}`{$has_parent ->\n[true] {\" \"}declared on the {$parent_prefix} `{$parent_name}`\n*[false] {\"\"}\n}\n}")),
&sub_args);
diag.span_label(__binding_0, __message);
}
}
}
}
};Subdiagnostic)]
251#[label(
252 "{$bad_kind ->
253*[other] cannot infer type
254[more_info] cannot infer {$prefix_kind ->
255*[type] type for {$prefix}
256[const_with_param] the value of const parameter
257[const] the value of the constant
258} `{$name}`{$has_parent ->
259[true] {\" \"}declared on the {$parent_prefix} `{$parent_name}`
260*[false] {\"\"}
261}
262}"
263)]
264pub struct InferenceBadError<'a> {
265 #[primary_span]
266 pub span: Span,
267 pub bad_kind: &'static str,
268 pub prefix_kind: UnderspecifiedArgKind,
269 pub has_parent: bool,
270 pub prefix: &'a str,
271 pub parent_prefix: &'a str,
272 pub parent_name: String,
273 pub name: String,
274}
275
276#[derive(const _: () =
{
impl<'a> rustc_errors::Subdiagnostic for SourceKindSubdiag<'a> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
SourceKindSubdiag::LetLike {
span: __binding_0,
name: __binding_1,
type_name: __binding_2,
kind: __binding_3,
x_kind: __binding_4,
prefix_kind: __binding_5,
prefix: __binding_6,
arg_name: __binding_7 } => {
let __code_0 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(": {0}", __binding_2))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("name".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("type_name".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
sub_args.insert("kind".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
&mut diag.long_ty_path));
sub_args.insert("x_kind".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_4,
&mut diag.long_ty_path));
sub_args.insert("prefix_kind".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_5,
&mut diag.long_ty_path));
sub_args.insert("prefix".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_6,
&mut diag.long_ty_path));
sub_args.insert("arg_name".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_7,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$kind ->\n [with_pattern] consider giving `{$name}` an explicit type\n [closure] consider giving this closure parameter an explicit type\n *[other] consider giving this pattern a type\n }{$x_kind ->\n [has_name] , where the {$prefix_kind ->\n *[type] type for {$prefix}\n [const_with_param] value of const parameter\n [const] value of the constant\n } `{$arg_name}` is specified\n [underscore] , where the placeholders `_` are specified\n *[empty] {\"\"}\n }")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_0, rustc_errors::Applicability::HasPlaceholders,
rustc_errors::SuggestionStyle::ShowAlways);
}
SourceKindSubdiag::GenericLabel {
span: __binding_0,
is_type: __binding_1,
param_name: __binding_2,
parent_exists: __binding_3,
parent_prefix: __binding_4,
parent_name: __binding_5 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("is_type".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("param_name".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
sub_args.insert("parent_exists".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
&mut diag.long_ty_path));
sub_args.insert("parent_prefix".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_4,
&mut diag.long_ty_path));
sub_args.insert("parent_name".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_5,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot infer {$is_type ->\n [true] type\n *[false] the value\n } of the {$is_type ->\n [true] type\n *[false] const\n } {$parent_exists ->\n [true] parameter `{$param_name}` declared on the {$parent_prefix} `{$parent_name}`\n *[false] parameter {$param_name}\n }")),
&sub_args);
diag.span_label(__binding_0, __message);
}
SourceKindSubdiag::GenericSuggestion {
span: __binding_0, arg_count: __binding_1, args: __binding_2
} => {
let __code_1 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("::<{0}>", __binding_2))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("arg_count".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("args".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider specifying the generic {$arg_count ->\n [one] argument\n *[other] arguments\n }")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_1, rustc_errors::Applicability::HasPlaceholders,
rustc_errors::SuggestionStyle::ShowAlways);
}
}
}
}
};Subdiagnostic)]
277pub enum SourceKindSubdiag<'a> {
278 #[suggestion(
279 "{$kind ->
280 [with_pattern] consider giving `{$name}` an explicit type
281 [closure] consider giving this closure parameter an explicit type
282 *[other] consider giving this pattern a type
283 }{$x_kind ->
284 [has_name] , where the {$prefix_kind ->
285 *[type] type for {$prefix}
286 [const_with_param] value of const parameter
287 [const] value of the constant
288 } `{$arg_name}` is specified
289 [underscore] , where the placeholders `_` are specified
290 *[empty] {\"\"}
291 }",
292 style = "verbose",
293 code = ": {type_name}",
294 applicability = "has-placeholders"
295 )]
296 LetLike {
297 #[primary_span]
298 span: Span,
299 name: String,
300 type_name: String,
301 kind: &'static str,
302 x_kind: &'static str,
303 prefix_kind: UnderspecifiedArgKind,
304 prefix: &'a str,
305 arg_name: String,
306 },
307 #[label(
308 "cannot infer {$is_type ->
309 [true] type
310 *[false] the value
311 } of the {$is_type ->
312 [true] type
313 *[false] const
314 } {$parent_exists ->
315 [true] parameter `{$param_name}` declared on the {$parent_prefix} `{$parent_name}`
316 *[false] parameter {$param_name}
317 }"
318 )]
319 GenericLabel {
320 #[primary_span]
321 span: Span,
322 is_type: bool,
323 param_name: String,
324 parent_exists: bool,
325 parent_prefix: String,
326 parent_name: String,
327 },
328 #[suggestion(
329 "consider specifying the generic {$arg_count ->
330 [one] argument
331 *[other] arguments
332 }",
333 style = "verbose",
334 code = "::<{args}>",
335 applicability = "has-placeholders"
336 )]
337 GenericSuggestion {
338 #[primary_span]
339 span: Span,
340 arg_count: usize,
341 args: String,
342 },
343}
344
345#[derive(const _: () =
{
impl<'a> rustc_errors::Subdiagnostic for SourceKindMultiSuggestion<'a>
{
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
SourceKindMultiSuggestion::FullyQualified {
span_lo: __binding_0,
span_hi: __binding_1,
def_path: __binding_2,
adjustment: __binding_3,
successor_pos: __binding_4 } => {
let mut suggestions = Vec::new();
let __code_2 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{1}({0}", __binding_3,
__binding_2))
});
let __code_3 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_4))
});
suggestions.push((__binding_0, __code_2));
suggestions.push((__binding_1, __code_3));
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("def_path".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
sub_args.insert("adjustment".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
&mut diag.long_ty_path));
sub_args.insert("successor_pos".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_4,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("try using a fully qualified path to specify the expected types")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::HasPlaceholders,
rustc_errors::SuggestionStyle::ShowAlways);
}
SourceKindMultiSuggestion::ClosureReturn {
start_span: __binding_0,
start_span_code: __binding_1,
end_span: __binding_2 } => {
let mut suggestions = Vec::new();
let __code_4 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_1))
});
let __code_5 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(" }}"))
});
suggestions.push((__binding_0, __code_4));
if let Some(__binding_2) = __binding_2 {
suggestions.push((__binding_2, __code_5));
}
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("start_span_code".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("try giving this closure an explicit return type")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::HasPlaceholders,
rustc_errors::SuggestionStyle::ShowAlways);
}
}
}
}
};Subdiagnostic)]
346pub enum SourceKindMultiSuggestion<'a> {
347 #[multipart_suggestion(
348 "try using a fully qualified path to specify the expected types",
349 style = "verbose",
350 applicability = "has-placeholders"
351 )]
352 FullyQualified {
353 #[suggestion_part(code = "{def_path}({adjustment}")]
354 span_lo: Span,
355 #[suggestion_part(code = "{successor_pos}")]
356 span_hi: Span,
357 def_path: String,
358 adjustment: &'a str,
359 successor_pos: &'a str,
360 },
361 #[multipart_suggestion(
362 "try giving this closure an explicit return type",
363 style = "verbose",
364 applicability = "has-placeholders"
365 )]
366 ClosureReturn {
367 #[suggestion_part(code = "{start_span_code}")]
368 start_span: Span,
369 start_span_code: String,
370 #[suggestion_part(code = " }}")]
371 end_span: Option<Span>,
372 },
373}
374
375impl<'a> SourceKindMultiSuggestion<'a> {
376 pub fn new_fully_qualified(
377 span: Span,
378 def_path: String,
379 adjustment: &'a str,
380 successor: (&'a str, BytePos),
381 ) -> Self {
382 Self::FullyQualified {
383 span_lo: span.shrink_to_lo(),
384 span_hi: span.shrink_to_hi().with_hi(successor.1),
385 def_path,
386 adjustment,
387 successor_pos: successor.0,
388 }
389 }
390
391 pub fn new_closure_return(
392 ty_info: String,
393 data: &'a FnRetTy<'a>,
394 should_wrap_expr: Option<Span>,
395 ) -> Self {
396 let arrow = match data {
397 FnRetTy::DefaultReturn(_) => " -> ",
398 _ => "",
399 };
400 let (start_span, start_span_code, end_span) = match should_wrap_expr {
401 Some(end_span) => (data.span(), ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}{1} {{", arrow, ty_info))
})format!("{arrow}{ty_info} {{"), Some(end_span)),
402 None => (data.span(), ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}{1}", arrow, ty_info))
})format!("{arrow}{ty_info}"), None),
403 };
404 Self::ClosureReturn { start_span, start_span_code, end_span }
405 }
406}
407
408pub enum RegionOriginNote<'a> {
409 Plain {
410 span: Span,
411 msg: DiagMessage,
412 },
413 WithName {
414 span: Span,
415 msg: DiagMessage,
416 name: &'a str,
417 continues: bool,
418 },
419 WithRequirement {
420 span: Span,
421 requirement: ObligationCauseAsDiagArg<'a>,
422 expected_found: Option<(DiagStyledString, DiagStyledString)>,
423 },
424}
425
426impl Subdiagnostic for RegionOriginNote<'_> {
427 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
428 let label_or_note = |diag: &mut Diag<'_, G>, span, msg: DiagMessage| {
429 let sub_count = diag.children.iter().filter(|d| d.span.is_dummy()).count();
430 let expanded_sub_count = diag.children.iter().filter(|d| !d.span.is_dummy()).count();
431 let span_is_primary = diag.span.primary_spans().iter().all(|&sp| sp == span);
432 if span_is_primary && sub_count == 0 && expanded_sub_count == 0 {
433 diag.span_label(span, msg);
434 } else if span_is_primary && expanded_sub_count == 0 {
435 diag.note(msg);
436 } else {
437 diag.span_note(span, msg);
438 }
439 };
440 match self {
441 RegionOriginNote::Plain { span, msg } => {
442 label_or_note(diag, span, msg);
443 }
444 RegionOriginNote::WithName { span, msg, name, continues } => {
445 label_or_note(
446 diag,
447 span,
448 msg.arg("name", name).arg("continues", continues).format(),
449 );
450 }
451 RegionOriginNote::WithRequirement {
452 span,
453 requirement,
454 expected_found: Some((expected, found)),
455 } => {
456 let msg = rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...so that the {$requirement ->\n [method_compat] method type is compatible with trait\n [type_compat] associated type is compatible with trait\n [const_compat] const is compatible with trait\n [expr_assignable] expression is assignable\n [if_else_different] `if` and `else` have incompatible types\n [no_else] `if` missing an `else` returns `()`\n [fn_main_correct_type] `main` function has the correct type\n [fn_lang_correct_type] lang item function has the correct type\n [intrinsic_correct_type] intrinsic has the correct type\n [method_correct_type] method receiver has the correct type\n *[other] types are compatible\n }"))msg!(
457 "...so that the {$requirement ->
458 [method_compat] method type is compatible with trait
459 [type_compat] associated type is compatible with trait
460 [const_compat] const is compatible with trait
461 [expr_assignable] expression is assignable
462 [if_else_different] `if` and `else` have incompatible types
463 [no_else] `if` missing an `else` returns `()`
464 [fn_main_correct_type] `main` function has the correct type
465 [fn_lang_correct_type] lang item function has the correct type
466 [intrinsic_correct_type] intrinsic has the correct type
467 [method_correct_type] method receiver has the correct type
468 *[other] types are compatible
469 }"
470 )
471 .arg("requirement", requirement)
472 .format();
473 label_or_note(diag, span, msg);
474
475 diag.note_expected_found("", expected, "", found);
476 }
477 RegionOriginNote::WithRequirement { span, requirement, expected_found: None } => {
478 let msg = rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...so that {$requirement ->\n [method_compat] method type is compatible with trait\n [type_compat] associated type is compatible with trait\n [const_compat] const is compatible with trait\n [expr_assignable] expression is assignable\n [if_else_different] `if` and `else` have incompatible types\n [no_else] `if` missing an `else` returns `()`\n [fn_main_correct_type] `main` function has the correct type\n [fn_lang_correct_type] lang item function has the correct type\n [intrinsic_correct_type] intrinsic has the correct type\n [method_correct_type] method receiver has the correct type\n *[other] types are compatible\n }"))msg!(
482 "...so that {$requirement ->
483 [method_compat] method type is compatible with trait
484 [type_compat] associated type is compatible with trait
485 [const_compat] const is compatible with trait
486 [expr_assignable] expression is assignable
487 [if_else_different] `if` and `else` have incompatible types
488 [no_else] `if` missing an `else` returns `()`
489 [fn_main_correct_type] `main` function has the correct type
490 [fn_lang_correct_type] lang item function has the correct type
491 [intrinsic_correct_type] intrinsic has the correct type
492 [method_correct_type] method receiver has the correct type
493 *[other] types are compatible
494 }"
495 )
496 .arg("requirement", requirement)
497 .format();
498 label_or_note(diag, span, msg);
499 }
500 };
501 }
502}
503
504pub enum LifetimeMismatchLabels {
505 InRet {
506 param_span: Span,
507 ret_span: Span,
508 span: Span,
509 label_var1: Option<Ident>,
510 },
511 Normal {
512 hir_equal: bool,
513 ty_sup: Span,
514 ty_sub: Span,
515 span: Span,
516 sup: Option<Ident>,
517 sub: Option<Ident>,
518 },
519}
520
521impl Subdiagnostic for LifetimeMismatchLabels {
522 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
523 match self {
524 LifetimeMismatchLabels::InRet { param_span, ret_span, span, label_var1 } => {
525 diag.span_label(param_span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this parameter and the return type are declared with different lifetimes..."))msg!("this parameter and the return type are declared with different lifetimes..."));
526 diag.span_label(ret_span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{\"\"}"))msg!("{\"\"}"));
527 diag.span_label(
528 span,
529 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...but data{$label_var1_exists ->\n [true] {\" \"}from `{$label_var1}`\n *[false] {\"\"}\n } is returned here"))msg!(
530 "...but data{$label_var1_exists ->
531 [true] {\" \"}from `{$label_var1}`
532 *[false] {\"\"}
533 } is returned here"
534 ),
535 );
536 diag.arg("label_var1_exists", label_var1.is_some());
537 diag.arg("label_var1", label_var1.map(|x| x.to_string()).unwrap_or_default());
538 }
539 LifetimeMismatchLabels::Normal {
540 hir_equal,
541 ty_sup,
542 ty_sub,
543 span,
544 sup: label_var1,
545 sub: label_var2,
546 } => {
547 if hir_equal {
548 diag.span_label(
549 ty_sup,
550 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this type is declared with multiple lifetimes..."))msg!("this type is declared with multiple lifetimes..."),
551 );
552 diag.span_label(ty_sub, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{\"\"}"))msg!("{\"\"}"));
553 diag.span_label(
554 span,
555 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...but data with one lifetime flows into the other here"))msg!("...but data with one lifetime flows into the other here"),
556 );
557 } else {
558 diag.span_label(
559 ty_sup,
560 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("these two types are declared with different lifetimes..."))msg!("these two types are declared with different lifetimes..."),
561 );
562 diag.span_label(ty_sub, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{\"\"}"))msg!("{\"\"}"));
563 diag.span_label(
564 span,
565 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...but data{$label_var1_exists ->\n [true] {\" \"}from `{$label_var1}`\n *[false] {\"\"}\n } flows{$label_var2_exists ->\n [true] {\" \"}into `{$label_var2}`\n *[false] {\"\"}\n } here"))msg!(
566 "...but data{$label_var1_exists ->
567 [true] {\" \"}from `{$label_var1}`
568 *[false] {\"\"}
569 } flows{$label_var2_exists ->
570 [true] {\" \"}into `{$label_var2}`
571 *[false] {\"\"}
572 } here"
573 ),
574 );
575 diag.arg("label_var1_exists", label_var1.is_some());
576 diag.arg("label_var1", label_var1.map(|x| x.to_string()).unwrap_or_default());
577 diag.arg("label_var2_exists", label_var2.is_some());
578 diag.arg("label_var2", label_var2.map(|x| x.to_string()).unwrap_or_default());
579 }
580 }
581 }
582 }
583}
584
585pub struct AddLifetimeParamsSuggestion<'a> {
586 pub tcx: TyCtxt<'a>,
587 pub generic_param_scope: LocalDefId,
588 pub sub: Region<'a>,
589 pub ty_sup: &'a hir::Ty<'a>,
590 pub ty_sub: &'a hir::Ty<'a>,
591 pub add_note: bool,
592}
593
594impl Subdiagnostic for AddLifetimeParamsSuggestion<'_> {
595 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
596 let mut mk_suggestion = || {
597 let Some(anon_reg) = self.tcx.is_suitable_region(self.generic_param_scope, self.sub)
598 else {
599 return false;
600 };
601
602 let node = self.tcx.hir_node_by_def_id(anon_reg.scope);
603 let is_impl = #[allow(non_exhaustive_omitted_patterns)] match &node {
hir::Node::ImplItem(_) => true,
_ => false,
}matches!(&node, hir::Node::ImplItem(_));
604 let (generics, parent_generics) = match node {
605 hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn { generics, .. }, .. })
606 | hir::Node::TraitItem(hir::TraitItem { generics, .. })
607 | hir::Node::ImplItem(hir::ImplItem { generics, .. }) => (
608 generics,
609 match self.tcx.parent_hir_node(self.tcx.local_def_id_to_hir_id(anon_reg.scope))
610 {
611 hir::Node::Item(hir::Item {
612 kind: hir::ItemKind::Trait(_, _, _, _, generics, ..),
613 ..
614 })
615 | hir::Node::Item(hir::Item {
616 kind: hir::ItemKind::Impl(hir::Impl { generics, .. }),
617 ..
618 }) => Some(generics),
619 _ => None,
620 },
621 ),
622 _ => return false,
623 };
624
625 let suggestion_param_name = generics
626 .params
627 .iter()
628 .filter(|p| #[allow(non_exhaustive_omitted_patterns)] match p.kind {
GenericParamKind::Lifetime { .. } => true,
_ => false,
}matches!(p.kind, GenericParamKind::Lifetime { .. }))
629 .map(|p| p.name.ident().name)
630 .find(|i| *i != kw::UnderscoreLifetime);
631 let introduce_new = suggestion_param_name.is_none();
632
633 let mut default = "'a".to_string();
634 if let Some(parent_generics) = parent_generics {
635 let used: FxHashSet<_> = parent_generics
636 .params
637 .iter()
638 .filter(|p| #[allow(non_exhaustive_omitted_patterns)] match p.kind {
GenericParamKind::Lifetime { .. } => true,
_ => false,
}matches!(p.kind, GenericParamKind::Lifetime { .. }))
639 .map(|p| p.name.ident().name)
640 .filter(|i| *i != kw::UnderscoreLifetime)
641 .map(|l| l.to_string())
642 .collect();
643 if let Some(lt) =
644 ('a'..='z').map(|it| ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("\'{0}", it))
})format!("'{it}")).find(|it| !used.contains(it))
645 {
646 default = lt;
651 }
652 }
653 let suggestion_param_name =
654 suggestion_param_name.map(|n| n.to_string()).unwrap_or_else(|| default);
655
656 struct ImplicitLifetimeFinder {
657 suggestions: Vec<(Span, String)>,
658 suggestion_param_name: String,
659 }
660
661 impl<'v> Visitor<'v> for ImplicitLifetimeFinder {
662 fn visit_ty(&mut self, ty: &'v hir::Ty<'v, AmbigArg>) {
663 match ty.kind {
664 hir::TyKind::Path(hir::QPath::Resolved(_, path)) => {
665 for segment in path.segments {
666 if let Some(args) = segment.args {
667 if args.args.iter().all(|arg| {
668 #[allow(non_exhaustive_omitted_patterns)] match arg {
hir::GenericArg::Lifetime(lifetime) if lifetime.is_implicit() => true,
_ => false,
}matches!(
669 arg,
670 hir::GenericArg::Lifetime(lifetime)
671 if lifetime.is_implicit()
672 )
673 }) {
674 self.suggestions.push((
675 segment.ident.span.shrink_to_hi(),
676 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("<{0}>",
args.args.iter().map(|_|
self.suggestion_param_name.clone()).collect::<Vec<_>>().join(", ")))
})format!(
677 "<{}>",
678 args.args
679 .iter()
680 .map(|_| self.suggestion_param_name.clone())
681 .collect::<Vec<_>>()
682 .join(", ")
683 ),
684 ));
685 } else {
686 for arg in args.args {
687 if let hir::GenericArg::Lifetime(lifetime) = arg
688 && lifetime.is_anonymous()
689 {
690 self.suggestions.push(
691 lifetime
692 .suggestion(&self.suggestion_param_name),
693 );
694 }
695 }
696 }
697 }
698 }
699 }
700 hir::TyKind::Ref(lifetime, ..) if lifetime.is_anonymous() => {
701 self.suggestions.push(lifetime.suggestion(&self.suggestion_param_name));
702 }
703 _ => {}
704 }
705 walk_ty(self, ty);
706 }
707 }
708 let mut visitor = ImplicitLifetimeFinder {
709 suggestions: ::alloc::vec::Vec::new()vec![],
710 suggestion_param_name: suggestion_param_name.clone(),
711 };
712 if let Some(fn_decl) = node.fn_decl()
713 && let hir::FnRetTy::Return(ty) = fn_decl.output
714 {
715 visitor.visit_ty_unambig(ty);
716 }
717 if visitor.suggestions.is_empty() {
718 visitor.visit_ty_unambig(self.ty_sup);
723 }
724 visitor.visit_ty_unambig(self.ty_sub);
725 if visitor.suggestions.is_empty() {
726 return false;
727 }
728 if introduce_new {
729 let new_param_suggestion = if let Some(first) =
730 generics.params.iter().find(|p| !p.name.ident().span.is_empty())
731 {
732 (first.span.shrink_to_lo(), ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}, ", suggestion_param_name))
})format!("{suggestion_param_name}, "))
733 } else {
734 (generics.span, ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("<{0}>", suggestion_param_name))
})format!("<{suggestion_param_name}>"))
735 };
736
737 visitor.suggestions.push(new_param_suggestion);
738 }
739 diag.multipart_suggestion(
740 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider {$is_reuse ->\n [true] reusing\n *[false] introducing\n } a named lifetime parameter{$is_impl ->\n [true] {\" \"}and update trait if needed\n *[false] {\"\"}\n }"))msg!(
741 "consider {$is_reuse ->
742 [true] reusing
743 *[false] introducing
744 } a named lifetime parameter{$is_impl ->
745 [true] {\" \"}and update trait if needed
746 *[false] {\"\"}
747 }"
748 ),
749 visitor.suggestions,
750 Applicability::MaybeIncorrect,
751 );
752 diag.arg("is_impl", is_impl);
753 diag.arg("is_reuse", !introduce_new);
754
755 true
756 };
757 if mk_suggestion() && self.add_note {
758 diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("each elided lifetime in input position becomes a distinct lifetime"))msg!("each elided lifetime in input position becomes a distinct lifetime"));
759 }
760 }
761}
762
763#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
LifetimeMismatch<'a> 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 {
LifetimeMismatch {
span: __binding_0,
labels: __binding_1,
suggestion: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime mismatch")));
diag.code(E0623);
;
diag.span(__binding_0);
diag.subdiagnostic(__binding_1);
diag.subdiagnostic(__binding_2);
diag
}
}
}
}
};Diagnostic)]
764#[diag("lifetime mismatch", code = E0623)]
765pub struct LifetimeMismatch<'a> {
766 #[primary_span]
767 pub span: Span,
768 #[subdiagnostic]
769 pub labels: LifetimeMismatchLabels,
770 #[subdiagnostic]
771 pub suggestion: AddLifetimeParamsSuggestion<'a>,
772}
773
774pub struct IntroducesStaticBecauseUnmetLifetimeReq {
775 pub unmet_requirements: MultiSpan,
776 pub binding_span: Span,
777}
778
779impl Subdiagnostic for IntroducesStaticBecauseUnmetLifetimeReq {
780 fn add_to_diag<G: EmissionGuarantee>(mut self, diag: &mut Diag<'_, G>) {
781 self.unmet_requirements.push_span_label(
782 self.binding_span,
783 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("introduces a `'static` lifetime requirement"))msg!("introduces a `'static` lifetime requirement"),
784 );
785 diag.span_note(
786 self.unmet_requirements,
787 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("because this has an unmet lifetime requirement"))msg!("because this has an unmet lifetime requirement"),
788 );
789 }
790}
791
792#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for DoesNotOutliveStaticFromImpl {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
DoesNotOutliveStaticFromImpl::Spanned { span: __binding_0 }
=> {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...does not necessarily outlive the static lifetime introduced by the compatible `impl`")),
&sub_args);
diag.span_note(__binding_0, __message);
}
DoesNotOutliveStaticFromImpl::Unspanned => {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...does not necessarily outlive the static lifetime introduced by the compatible `impl`")),
&sub_args);
diag.note(__message);
}
}
}
}
};Subdiagnostic)]
794pub enum DoesNotOutliveStaticFromImpl {
795 #[note(
796 "...does not necessarily outlive the static lifetime introduced by the compatible `impl`"
797 )]
798 Spanned {
799 #[primary_span]
800 span: Span,
801 },
802 #[note(
803 "...does not necessarily outlive the static lifetime introduced by the compatible `impl`"
804 )]
805 Unspanned,
806}
807
808#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for ImplicitStaticLifetimeSubdiag {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
ImplicitStaticLifetimeSubdiag::Note { span: __binding_0 } =>
{
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this has an implicit `'static` lifetime requirement")),
&sub_args);
diag.span_note(__binding_0, __message);
}
ImplicitStaticLifetimeSubdiag::Sugg { span: __binding_0 } =>
{
let __code_6 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(" + \'_"))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider relaxing the implicit `'static` requirement")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_6, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
}
}
}
}
};Subdiagnostic)]
809pub enum ImplicitStaticLifetimeSubdiag {
810 #[note("this has an implicit `'static` lifetime requirement")]
811 Note {
812 #[primary_span]
813 span: Span,
814 },
815 #[suggestion(
816 "consider relaxing the implicit `'static` requirement",
817 style = "verbose",
818 code = " + '_",
819 applicability = "maybe-incorrect"
820 )]
821 Sugg {
822 #[primary_span]
823 span: Span,
824 },
825}
826
827#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
MismatchedStaticLifetime<'a> 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 {
MismatchedStaticLifetime {
cause_span: __binding_0,
unmet_lifetime_reqs: __binding_1,
expl: __binding_2,
does_not_outlive_static_from_impl: __binding_3,
implicit_static_lifetimes: __binding_4 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("incompatible lifetime on type")));
;
diag.span(__binding_0);
diag.subdiagnostic(__binding_1);
if let Some(__binding_2) = __binding_2 {
diag.subdiagnostic(__binding_2);
}
diag.subdiagnostic(__binding_3);
for __binding_4 in __binding_4 {
diag.subdiagnostic(__binding_4);
}
diag
}
}
}
}
};Diagnostic)]
828#[diag("incompatible lifetime on type")]
829pub struct MismatchedStaticLifetime<'a> {
830 #[primary_span]
831 pub cause_span: Span,
832 #[subdiagnostic]
833 pub unmet_lifetime_reqs: IntroducesStaticBecauseUnmetLifetimeReq,
834 #[subdiagnostic]
835 pub expl: Option<note_and_explain::RegionExplanation<'a>>,
836 #[subdiagnostic]
837 pub does_not_outlive_static_from_impl: DoesNotOutliveStaticFromImpl,
838 #[subdiagnostic]
839 pub implicit_static_lifetimes: Vec<ImplicitStaticLifetimeSubdiag>,
840}
841
842#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
ExplicitLifetimeRequired<'a> 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 {
ExplicitLifetimeRequired::WithIdent {
span: __binding_0,
simple_ident: __binding_1,
named: __binding_2,
new_ty_span: __binding_3,
new_ty: __binding_4 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("explicit lifetime required in the type of `{$simple_ident}`")));
let __code_7 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_4))
})].into_iter();
diag.code(E0621);
;
diag.arg("simple_ident", __binding_1);
diag.arg("named", __binding_2);
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime `{$named}` required")));
diag.span_suggestions_with_style(__binding_3,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("add explicit lifetime `{$named}` to the type of `{$simple_ident}`")),
__code_7, rustc_errors::Applicability::Unspecified,
rustc_errors::SuggestionStyle::ShowAlways);
diag
}
ExplicitLifetimeRequired::WithParamType {
span: __binding_0,
named: __binding_1,
new_ty_span: __binding_2,
new_ty: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("explicit lifetime required in parameter type")));
let __code_8 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_3))
})].into_iter();
diag.code(E0621);
;
diag.arg("named", __binding_1);
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime `{$named}` required")));
diag.span_suggestions_with_style(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("add explicit lifetime `{$named}` to type")),
__code_8, rustc_errors::Applicability::Unspecified,
rustc_errors::SuggestionStyle::ShowAlways);
diag
}
}
}
}
};Diagnostic)]
843pub enum ExplicitLifetimeRequired<'a> {
844 #[diag("explicit lifetime required in the type of `{$simple_ident}`", code = E0621)]
845 WithIdent {
846 #[primary_span]
847 #[label("lifetime `{$named}` required")]
848 span: Span,
849 simple_ident: Ident,
850 named: String,
851 #[suggestion(
852 "add explicit lifetime `{$named}` to the type of `{$simple_ident}`",
853 code = "{new_ty}",
854 applicability = "unspecified",
855 style = "verbose"
856 )]
857 new_ty_span: Span,
858 #[skip_arg]
859 new_ty: Ty<'a>,
860 },
861 #[diag("explicit lifetime required in parameter type", code = E0621)]
862 WithParamType {
863 #[primary_span]
864 #[label("lifetime `{$named}` required")]
865 span: Span,
866 named: String,
867 #[suggestion(
868 "add explicit lifetime `{$named}` to type",
869 code = "{new_ty}",
870 applicability = "unspecified",
871 style = "verbose"
872 )]
873 new_ty_span: Span,
874 #[skip_arg]
875 new_ty: Ty<'a>,
876 },
877}
878
879pub enum TyOrSig<'tcx> {
880 Ty(Highlighted<'tcx, Ty<'tcx>>),
881 ClosureSig(Highlighted<'tcx, Binder<'tcx, FnSig<'tcx>>>),
882}
883
884impl IntoDiagArg for TyOrSig<'_> {
885 fn into_diag_arg(self, path: &mut Option<std::path::PathBuf>) -> rustc_errors::DiagArgValue {
886 match self {
887 TyOrSig::Ty(ty) => ty.into_diag_arg(path),
888 TyOrSig::ClosureSig(sig) => sig.into_diag_arg(path),
889 }
890 }
891}
892
893#[derive(const _: () =
{
impl<'tcx> rustc_errors::Subdiagnostic for ActualImplExplNotes<'tcx> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
ActualImplExplNotes::ExpectedSignatureTwo {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2,
lifetime_1: __binding_3,
lifetime_2: __binding_4 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("leading_ellipsis".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
sub_args.insert("ty_or_sig".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("trait_path".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
sub_args.insert("lifetime_1".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
&mut diag.long_ty_path));
sub_args.insert("lifetime_2".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_4,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }closure with signature `{$ty_or_sig}` must implement `{$trait_path}`, for any two lifetimes `'{$lifetime_1}` and `'{$lifetime_2}`...")),
&sub_args);
diag.note(__message);
}
ActualImplExplNotes::ExpectedSignatureAny {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2,
lifetime_1: __binding_3 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("leading_ellipsis".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
sub_args.insert("ty_or_sig".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("trait_path".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
sub_args.insert("lifetime_1".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }closure with signature `{$ty_or_sig}` must implement `{$trait_path}`, for any lifetime `'{$lifetime_1}`...")),
&sub_args);
diag.note(__message);
}
ActualImplExplNotes::ExpectedSignatureSome {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2,
lifetime_1: __binding_3 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("leading_ellipsis".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
sub_args.insert("ty_or_sig".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("trait_path".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
sub_args.insert("lifetime_1".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }closure with signature `{$ty_or_sig}` must implement `{$trait_path}`, for some specific lifetime `'{$lifetime_1}`...")),
&sub_args);
diag.note(__message);
}
ActualImplExplNotes::ExpectedSignatureNothing {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("leading_ellipsis".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
sub_args.insert("ty_or_sig".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("trait_path".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }closure with signature `{$ty_or_sig}` must implement `{$trait_path}`")),
&sub_args);
diag.note(__message);
}
ActualImplExplNotes::ExpectedPassiveTwo {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2,
lifetime_1: __binding_3,
lifetime_2: __binding_4 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("leading_ellipsis".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
sub_args.insert("ty_or_sig".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("trait_path".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
sub_args.insert("lifetime_1".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
&mut diag.long_ty_path));
sub_args.insert("lifetime_2".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_4,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`, for any two lifetimes `'{$lifetime_1}` and `'{$lifetime_2}`...")),
&sub_args);
diag.note(__message);
}
ActualImplExplNotes::ExpectedPassiveAny {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2,
lifetime_1: __binding_3 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("leading_ellipsis".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
sub_args.insert("ty_or_sig".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("trait_path".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
sub_args.insert("lifetime_1".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`, for any lifetime `'{$lifetime_1}`...")),
&sub_args);
diag.note(__message);
}
ActualImplExplNotes::ExpectedPassiveSome {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2,
lifetime_1: __binding_3 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("leading_ellipsis".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
sub_args.insert("ty_or_sig".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("trait_path".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
sub_args.insert("lifetime_1".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`, for some specific lifetime `'{$lifetime_1}`...")),
&sub_args);
diag.note(__message);
}
ActualImplExplNotes::ExpectedPassiveNothing {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("leading_ellipsis".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
sub_args.insert("ty_or_sig".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("trait_path".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`")),
&sub_args);
diag.note(__message);
}
ActualImplExplNotes::ExpectedOtherTwo {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2,
lifetime_1: __binding_3,
lifetime_2: __binding_4 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("leading_ellipsis".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
sub_args.insert("ty_or_sig".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("trait_path".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
sub_args.insert("lifetime_1".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
&mut diag.long_ty_path));
sub_args.insert("lifetime_2".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_4,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }`{$ty_or_sig}` must implement `{$trait_path}`, for any two lifetimes `'{$lifetime_1}` and `'{$lifetime_2}`...")),
&sub_args);
diag.note(__message);
}
ActualImplExplNotes::ExpectedOtherAny {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2,
lifetime_1: __binding_3 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("leading_ellipsis".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
sub_args.insert("ty_or_sig".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("trait_path".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
sub_args.insert("lifetime_1".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }`{$ty_or_sig}` must implement `{$trait_path}`, for any lifetime `'{$lifetime_1}`...")),
&sub_args);
diag.note(__message);
}
ActualImplExplNotes::ExpectedOtherSome {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2,
lifetime_1: __binding_3 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("leading_ellipsis".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
sub_args.insert("ty_or_sig".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("trait_path".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
sub_args.insert("lifetime_1".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }`{$ty_or_sig}` must implement `{$trait_path}`, for some specific lifetime `'{$lifetime_1}`...")),
&sub_args);
diag.note(__message);
}
ActualImplExplNotes::ExpectedOtherNothing {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("leading_ellipsis".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
sub_args.insert("ty_or_sig".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("trait_path".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }`{$ty_or_sig}` must implement `{$trait_path}`")),
&sub_args);
diag.note(__message);
}
ActualImplExplNotes::ButActuallyImplementsTrait {
trait_path: __binding_0,
has_lifetime: __binding_1,
lifetime: __binding_2 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("trait_path".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
sub_args.insert("has_lifetime".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("lifetime".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...but it actually implements `{$trait_path}`{$has_lifetime ->\n [true] , for some specific lifetime `'{$lifetime}`\n *[false] {\"\"}\n }")),
&sub_args);
diag.note(__message);
}
ActualImplExplNotes::ButActuallyImplementedForTy {
trait_path: __binding_0,
has_lifetime: __binding_1,
lifetime: __binding_2,
ty: __binding_3 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("trait_path".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
sub_args.insert("has_lifetime".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("lifetime".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
sub_args.insert("ty".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...but `{$trait_path}` is actually implemented for the type `{$ty}`{$has_lifetime ->\n [true] , for some specific lifetime `'{$lifetime}`\n *[false] {\"\"}\n }")),
&sub_args);
diag.note(__message);
}
ActualImplExplNotes::ButActuallyTyImplements {
trait_path: __binding_0,
has_lifetime: __binding_1,
lifetime: __binding_2,
ty: __binding_3 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("trait_path".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
sub_args.insert("has_lifetime".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("lifetime".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
sub_args.insert("ty".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...but `{$ty}` actually implements `{$trait_path}`{$has_lifetime ->\n [true] , for some specific lifetime `'{$lifetime}`\n *[false] {\"\"}\n }")),
&sub_args);
diag.note(__message);
}
}
}
}
};Subdiagnostic)]
894pub enum ActualImplExplNotes<'tcx> {
895 #[note("{$leading_ellipsis ->
896 [true] ...
897 *[false] {\"\"}
898 }closure with signature `{$ty_or_sig}` must implement `{$trait_path}`, for any two lifetimes `'{$lifetime_1}` and `'{$lifetime_2}`...")]
899 ExpectedSignatureTwo {
900 leading_ellipsis: bool,
901 ty_or_sig: TyOrSig<'tcx>,
902 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
903 lifetime_1: usize,
904 lifetime_2: usize,
905 },
906 #[note("{$leading_ellipsis ->
907 [true] ...
908 *[false] {\"\"}
909 }closure with signature `{$ty_or_sig}` must implement `{$trait_path}`, for any lifetime `'{$lifetime_1}`...")]
910 ExpectedSignatureAny {
911 leading_ellipsis: bool,
912 ty_or_sig: TyOrSig<'tcx>,
913 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
914 lifetime_1: usize,
915 },
916 #[note("{$leading_ellipsis ->
917 [true] ...
918 *[false] {\"\"}
919 }closure with signature `{$ty_or_sig}` must implement `{$trait_path}`, for some specific lifetime `'{$lifetime_1}`...")]
920 ExpectedSignatureSome {
921 leading_ellipsis: bool,
922 ty_or_sig: TyOrSig<'tcx>,
923 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
924 lifetime_1: usize,
925 },
926 #[note(
927 "{$leading_ellipsis ->
928 [true] ...
929 *[false] {\"\"}
930 }closure with signature `{$ty_or_sig}` must implement `{$trait_path}`"
931 )]
932 ExpectedSignatureNothing {
933 leading_ellipsis: bool,
934 ty_or_sig: TyOrSig<'tcx>,
935 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
936 },
937 #[note("{$leading_ellipsis ->
938 [true] ...
939 *[false] {\"\"}
940 }`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`, for any two lifetimes `'{$lifetime_1}` and `'{$lifetime_2}`...")]
941 ExpectedPassiveTwo {
942 leading_ellipsis: bool,
943 ty_or_sig: TyOrSig<'tcx>,
944 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
945 lifetime_1: usize,
946 lifetime_2: usize,
947 },
948 #[note("{$leading_ellipsis ->
949 [true] ...
950 *[false] {\"\"}
951 }`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`, for any lifetime `'{$lifetime_1}`...")]
952 ExpectedPassiveAny {
953 leading_ellipsis: bool,
954 ty_or_sig: TyOrSig<'tcx>,
955 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
956 lifetime_1: usize,
957 },
958 #[note("{$leading_ellipsis ->
959 [true] ...
960 *[false] {\"\"}
961 }`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`, for some specific lifetime `'{$lifetime_1}`...")]
962 ExpectedPassiveSome {
963 leading_ellipsis: bool,
964 ty_or_sig: TyOrSig<'tcx>,
965 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
966 lifetime_1: usize,
967 },
968 #[note(
969 "{$leading_ellipsis ->
970 [true] ...
971 *[false] {\"\"}
972 }`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`"
973 )]
974 ExpectedPassiveNothing {
975 leading_ellipsis: bool,
976 ty_or_sig: TyOrSig<'tcx>,
977 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
978 },
979 #[note("{$leading_ellipsis ->
980 [true] ...
981 *[false] {\"\"}
982 }`{$ty_or_sig}` must implement `{$trait_path}`, for any two lifetimes `'{$lifetime_1}` and `'{$lifetime_2}`...")]
983 ExpectedOtherTwo {
984 leading_ellipsis: bool,
985 ty_or_sig: TyOrSig<'tcx>,
986 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
987 lifetime_1: usize,
988 lifetime_2: usize,
989 },
990 #[note(
991 "{$leading_ellipsis ->
992 [true] ...
993 *[false] {\"\"}
994 }`{$ty_or_sig}` must implement `{$trait_path}`, for any lifetime `'{$lifetime_1}`..."
995 )]
996 ExpectedOtherAny {
997 leading_ellipsis: bool,
998 ty_or_sig: TyOrSig<'tcx>,
999 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
1000 lifetime_1: usize,
1001 },
1002 #[note(
1003 "{$leading_ellipsis ->
1004 [true] ...
1005 *[false] {\"\"}
1006 }`{$ty_or_sig}` must implement `{$trait_path}`, for some specific lifetime `'{$lifetime_1}`..."
1007 )]
1008 ExpectedOtherSome {
1009 leading_ellipsis: bool,
1010 ty_or_sig: TyOrSig<'tcx>,
1011 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
1012 lifetime_1: usize,
1013 },
1014 #[note(
1015 "{$leading_ellipsis ->
1016 [true] ...
1017 *[false] {\"\"}
1018 }`{$ty_or_sig}` must implement `{$trait_path}`"
1019 )]
1020 ExpectedOtherNothing {
1021 leading_ellipsis: bool,
1022 ty_or_sig: TyOrSig<'tcx>,
1023 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
1024 },
1025 #[note(
1026 "...but it actually implements `{$trait_path}`{$has_lifetime ->
1027 [true] , for some specific lifetime `'{$lifetime}`
1028 *[false] {\"\"}
1029 }"
1030 )]
1031 ButActuallyImplementsTrait {
1032 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
1033 has_lifetime: bool,
1034 lifetime: usize,
1035 },
1036 #[note(
1037 "...but `{$trait_path}` is actually implemented for the type `{$ty}`{$has_lifetime ->
1038 [true] , for some specific lifetime `'{$lifetime}`
1039 *[false] {\"\"}
1040 }"
1041 )]
1042 ButActuallyImplementedForTy {
1043 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
1044 has_lifetime: bool,
1045 lifetime: usize,
1046 ty: String,
1047 },
1048 #[note(
1049 "...but `{$ty}` actually implements `{$trait_path}`{$has_lifetime ->
1050 [true] , for some specific lifetime `'{$lifetime}`
1051 *[false] {\"\"}
1052 }"
1053 )]
1054 ButActuallyTyImplements {
1055 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
1056 has_lifetime: bool,
1057 lifetime: usize,
1058 ty: String,
1059 },
1060}
1061
1062pub enum ActualImplExpectedKind {
1063 Signature,
1064 Passive,
1065 Other,
1066}
1067
1068pub enum ActualImplExpectedLifetimeKind {
1069 Two,
1070 Any,
1071 Some,
1072 Nothing,
1073}
1074
1075impl<'tcx> ActualImplExplNotes<'tcx> {
1076 pub fn new_expected(
1077 kind: ActualImplExpectedKind,
1078 lt_kind: ActualImplExpectedLifetimeKind,
1079 leading_ellipsis: bool,
1080 ty_or_sig: TyOrSig<'tcx>,
1081 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
1082 lifetime_1: usize,
1083 lifetime_2: usize,
1084 ) -> Self {
1085 match (kind, lt_kind) {
1086 (ActualImplExpectedKind::Signature, ActualImplExpectedLifetimeKind::Two) => {
1087 Self::ExpectedSignatureTwo {
1088 leading_ellipsis,
1089 ty_or_sig,
1090 trait_path,
1091 lifetime_1,
1092 lifetime_2,
1093 }
1094 }
1095 (ActualImplExpectedKind::Signature, ActualImplExpectedLifetimeKind::Any) => {
1096 Self::ExpectedSignatureAny { leading_ellipsis, ty_or_sig, trait_path, lifetime_1 }
1097 }
1098 (ActualImplExpectedKind::Signature, ActualImplExpectedLifetimeKind::Some) => {
1099 Self::ExpectedSignatureSome { leading_ellipsis, ty_or_sig, trait_path, lifetime_1 }
1100 }
1101 (ActualImplExpectedKind::Signature, ActualImplExpectedLifetimeKind::Nothing) => {
1102 Self::ExpectedSignatureNothing { leading_ellipsis, ty_or_sig, trait_path }
1103 }
1104 (ActualImplExpectedKind::Passive, ActualImplExpectedLifetimeKind::Two) => {
1105 Self::ExpectedPassiveTwo {
1106 leading_ellipsis,
1107 ty_or_sig,
1108 trait_path,
1109 lifetime_1,
1110 lifetime_2,
1111 }
1112 }
1113 (ActualImplExpectedKind::Passive, ActualImplExpectedLifetimeKind::Any) => {
1114 Self::ExpectedPassiveAny { leading_ellipsis, ty_or_sig, trait_path, lifetime_1 }
1115 }
1116 (ActualImplExpectedKind::Passive, ActualImplExpectedLifetimeKind::Some) => {
1117 Self::ExpectedPassiveSome { leading_ellipsis, ty_or_sig, trait_path, lifetime_1 }
1118 }
1119 (ActualImplExpectedKind::Passive, ActualImplExpectedLifetimeKind::Nothing) => {
1120 Self::ExpectedPassiveNothing { leading_ellipsis, ty_or_sig, trait_path }
1121 }
1122 (ActualImplExpectedKind::Other, ActualImplExpectedLifetimeKind::Two) => {
1123 Self::ExpectedOtherTwo {
1124 leading_ellipsis,
1125 ty_or_sig,
1126 trait_path,
1127 lifetime_1,
1128 lifetime_2,
1129 }
1130 }
1131 (ActualImplExpectedKind::Other, ActualImplExpectedLifetimeKind::Any) => {
1132 Self::ExpectedOtherAny { leading_ellipsis, ty_or_sig, trait_path, lifetime_1 }
1133 }
1134 (ActualImplExpectedKind::Other, ActualImplExpectedLifetimeKind::Some) => {
1135 Self::ExpectedOtherSome { leading_ellipsis, ty_or_sig, trait_path, lifetime_1 }
1136 }
1137 (ActualImplExpectedKind::Other, ActualImplExpectedLifetimeKind::Nothing) => {
1138 Self::ExpectedOtherNothing { leading_ellipsis, ty_or_sig, trait_path }
1139 }
1140 }
1141 }
1142}
1143
1144#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
TraitPlaceholderMismatch<'tcx> 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 {
TraitPlaceholderMismatch {
span: __binding_0,
satisfy_span: __binding_1,
where_span: __binding_2,
dup_span: __binding_3,
def_id: __binding_4,
trait_def_id: __binding_5,
actual_impl_expl_notes: __binding_6 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("implementation of `{$trait_def_id}` is not general enough")));
;
diag.arg("def_id", __binding_4);
diag.arg("trait_def_id", __binding_5);
diag.span(__binding_0);
if let Some(__binding_1) = __binding_1 {
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("doesn't satisfy where-clause")));
}
if let Some(__binding_2) = __binding_2 {
diag.span_label(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("due to a where-clause on `{$def_id}`...")));
}
if let Some(__binding_3) = __binding_3 {
diag.span_label(__binding_3,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("implementation of `{$trait_def_id}` is not general enough")));
}
for __binding_6 in __binding_6 {
diag.subdiagnostic(__binding_6);
}
diag
}
}
}
}
};Diagnostic)]
1145#[diag("implementation of `{$trait_def_id}` is not general enough")]
1146pub struct TraitPlaceholderMismatch<'tcx> {
1147 #[primary_span]
1148 pub span: Span,
1149 #[label("doesn't satisfy where-clause")]
1150 pub satisfy_span: Option<Span>,
1151 #[label("due to a where-clause on `{$def_id}`...")]
1152 pub where_span: Option<Span>,
1153 #[label("implementation of `{$trait_def_id}` is not general enough")]
1154 pub dup_span: Option<Span>,
1155 pub def_id: String,
1156 pub trait_def_id: String,
1157
1158 #[subdiagnostic]
1159 pub actual_impl_expl_notes: Vec<ActualImplExplNotes<'tcx>>,
1160}
1161
1162pub struct ConsiderBorrowingParamHelp {
1163 pub spans: Vec<Span>,
1164}
1165
1166impl Subdiagnostic for ConsiderBorrowingParamHelp {
1167 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1168 let mut type_param_span: MultiSpan = self.spans.clone().into();
1169 for &span in &self.spans {
1170 type_param_span
1172 .push_span_label(span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider borrowing this type parameter in the trait"))msg!("consider borrowing this type parameter in the trait"));
1173 }
1174 let msg = rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`"))msg!(
1175 "the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`"
1176 );
1177 diag.span_help(type_param_span, msg);
1178 }
1179}
1180
1181#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for TraitImplDiff
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 {
TraitImplDiff {
sp: __binding_0,
trait_sp: __binding_1,
note: __binding_2,
param_help: __binding_3,
rel_help: __binding_4,
expected: __binding_5,
found: __binding_6 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`impl` item signature doesn't match `trait` item signature")));
;
diag.arg("expected", __binding_5);
diag.arg("found", __binding_6);
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("found `{$found}`")));
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected `{$expected}`")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected signature `{$expected}`\n {\" \"}found signature `{$found}`")));
diag.subdiagnostic(__binding_3);
if __binding_4 {
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("verify the lifetime relationships in the `trait` and `impl` between the `self` argument, the other inputs and its output")));
}
diag
}
}
}
}
};Diagnostic)]
1182#[diag("`impl` item signature doesn't match `trait` item signature")]
1183pub struct TraitImplDiff {
1184 #[primary_span]
1185 #[label("found `{$found}`")]
1186 pub sp: Span,
1187 #[label("expected `{$expected}`")]
1188 pub trait_sp: Span,
1189 #[note(
1190 "expected signature `{$expected}`
1191 {\" \"}found signature `{$found}`"
1192 )]
1193 pub note: (),
1194 #[subdiagnostic]
1195 pub param_help: ConsiderBorrowingParamHelp,
1196 #[help(
1197 "verify the lifetime relationships in the `trait` and `impl` between the `self` argument, the other inputs and its output"
1198 )]
1199 pub rel_help: bool,
1200 pub expected: String,
1201 pub found: String,
1202}
1203
1204pub struct DynTraitConstraintSuggestion {
1205 pub span: Span,
1206 pub ident: Ident,
1207}
1208
1209impl Subdiagnostic for DynTraitConstraintSuggestion {
1210 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1211 let mut multi_span: MultiSpan = ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[self.span]))vec![self.span].into();
1212 multi_span.push_span_label(
1213 self.span,
1214 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this has an implicit `'static` lifetime requirement"))msg!("this has an implicit `'static` lifetime requirement"),
1215 );
1216 multi_span.push_span_label(
1217 self.ident.span,
1218 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("calling this method introduces the `impl`'s `'static` requirement"))msg!("calling this method introduces the `impl`'s `'static` requirement"),
1219 );
1220 let msg = rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the used `impl` has a `'static` requirement"))msg!("the used `impl` has a `'static` requirement");
1221 diag.span_note(multi_span, msg);
1222 let msg = rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider relaxing the implicit `'static` requirement"))msg!("consider relaxing the implicit `'static` requirement");
1223 diag.span_suggestion_verbose(
1224 self.span.shrink_to_hi(),
1225 msg,
1226 " + '_",
1227 Applicability::MaybeIncorrect,
1228 );
1229 }
1230}
1231
1232pub struct ReqIntroducedLocations {
1233 pub span: MultiSpan,
1234 pub spans: Vec<Span>,
1235 pub fn_decl_span: Span,
1236 pub cause_span: Span,
1237 pub add_label: bool,
1238}
1239
1240impl Subdiagnostic for ReqIntroducedLocations {
1241 fn add_to_diag<G: EmissionGuarantee>(mut self, diag: &mut Diag<'_, G>) {
1242 for sp in self.spans {
1243 self.span.push_span_label(sp, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`'static` requirement introduced here"))msg!("`'static` requirement introduced here"));
1244 }
1245
1246 if self.add_label {
1247 self.span.push_span_label(
1248 self.fn_decl_span,
1249 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("requirement introduced by this return type"))msg!("requirement introduced by this return type"),
1250 );
1251 }
1252 self.span.push_span_label(self.cause_span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("because of this returned expression"))msg!("because of this returned expression"));
1253 let msg = rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("\"`'static` lifetime requirement introduced by the return type"))msg!("\"`'static` lifetime requirement introduced by the return type");
1254 diag.span_note(self.span, msg);
1255 }
1256}
1257
1258#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
ButNeedsToSatisfy 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 {
ButNeedsToSatisfy {
sp: __binding_0,
influencer_point: __binding_1,
spans: __binding_2,
require_span_as_label: __binding_3,
require_span_as_note: __binding_4,
bound: __binding_5,
has_param_name: __binding_6,
param_name: __binding_7,
spans_empty: __binding_8,
has_lifetime: __binding_9,
lifetime: __binding_10 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$has_param_name ->\n [true] `{$param_name}`\n *[false] `fn` parameter\n} has {$has_lifetime ->\n [true] lifetime `{$lifetime}`\n *[false] an anonymous lifetime `'_`\n} but it needs to satisfy a `'static` lifetime requirement")));
diag.code(E0759);
;
diag.arg("has_param_name", __binding_6);
diag.arg("param_name", __binding_7);
diag.arg("spans_empty", __binding_8);
diag.arg("has_lifetime", __binding_9);
diag.arg("lifetime", __binding_10);
diag.span(__binding_0);
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this data with {$has_lifetime ->\n [true] lifetime `{$lifetime}`\n *[false] an anonymous lifetime `'_`\n }...")));
for __binding_2 in __binding_2 {
diag.span_label(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...is used here...")));
}
if let Some(__binding_3) = __binding_3 {
diag.span_label(__binding_3,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$spans_empty ->\n *[true] ...is used and required to live as long as `'static` here\n [false] ...and is required to live as long as `'static` here\n }")));
}
if let Some(__binding_4) = __binding_4 {
diag.span_note(__binding_4,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$spans_empty ->\n *[true] ...is used and required to live as long as `'static` here\n [false] ...and is required to live as long as `'static` here\n }")));
}
if let Some(__binding_5) = __binding_5 {
diag.span_note(__binding_5,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`'static` lifetime requirement introduced by this bound")));
}
diag
}
}
}
}
};Diagnostic)]
1259#[diag("{$has_param_name ->
1260 [true] `{$param_name}`
1261 *[false] `fn` parameter
1262} has {$has_lifetime ->
1263 [true] lifetime `{$lifetime}`
1264 *[false] an anonymous lifetime `'_`
1265} but it needs to satisfy a `'static` lifetime requirement", code = E0759)]
1266pub struct ButNeedsToSatisfy {
1267 #[primary_span]
1268 pub sp: Span,
1269 #[label(
1270 "this data with {$has_lifetime ->
1271 [true] lifetime `{$lifetime}`
1272 *[false] an anonymous lifetime `'_`
1273 }..."
1274 )]
1275 pub influencer_point: Span,
1276 #[label("...is used here...")]
1277 pub spans: Vec<Span>,
1278 #[label(
1279 "{$spans_empty ->
1280 *[true] ...is used and required to live as long as `'static` here
1281 [false] ...and is required to live as long as `'static` here
1282 }"
1283 )]
1284 pub require_span_as_label: Option<Span>,
1285 #[note(
1286 "{$spans_empty ->
1287 *[true] ...is used and required to live as long as `'static` here
1288 [false] ...and is required to live as long as `'static` here
1289 }"
1290 )]
1291 pub require_span_as_note: Option<Span>,
1292 #[note("`'static` lifetime requirement introduced by this bound")]
1293 pub bound: Option<Span>,
1294
1295 pub has_param_name: bool,
1296 pub param_name: String,
1297 pub spans_empty: bool,
1298 pub has_lifetime: bool,
1299 pub lifetime: String,
1300}
1301
1302#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
OutlivesContent<'a> 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 {
OutlivesContent { span: __binding_0, notes: __binding_1 } =>
{
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime of reference outlives lifetime of borrowed content...")));
diag.code(E0312);
;
diag.span(__binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
}
}
}
};Diagnostic)]
1303#[diag("lifetime of reference outlives lifetime of borrowed content...", code = E0312)]
1304pub struct OutlivesContent<'a> {
1305 #[primary_span]
1306 pub span: Span,
1307 #[subdiagnostic]
1308 pub notes: Vec<note_and_explain::RegionExplanation<'a>>,
1309}
1310
1311#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
OutlivesBound<'a> 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 {
OutlivesBound { span: __binding_0, notes: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime of the source pointer does not outlive lifetime bound of the object type")));
diag.code(E0476);
;
diag.span(__binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
}
}
}
};Diagnostic)]
1312#[diag("lifetime of the source pointer does not outlive lifetime bound of the object type", code = E0476)]
1313pub struct OutlivesBound<'a> {
1314 #[primary_span]
1315 pub span: Span,
1316 #[subdiagnostic]
1317 pub notes: Vec<note_and_explain::RegionExplanation<'a>>,
1318}
1319
1320#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
FulfillReqLifetime<'a> 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 {
FulfillReqLifetime {
span: __binding_0, ty: __binding_1, note: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the type `{$ty}` does not fulfill the required lifetime")));
diag.code(E0477);
;
diag.arg("ty", __binding_1);
diag.span(__binding_0);
if let Some(__binding_2) = __binding_2 {
diag.subdiagnostic(__binding_2);
}
diag
}
}
}
}
};Diagnostic)]
1321#[diag("the type `{$ty}` does not fulfill the required lifetime", code = E0477)]
1322pub struct FulfillReqLifetime<'a> {
1323 #[primary_span]
1324 pub span: Span,
1325 pub ty: Ty<'a>,
1326 #[subdiagnostic]
1327 pub note: Option<note_and_explain::RegionExplanation<'a>>,
1328}
1329
1330#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
LfBoundNotSatisfied<'a> 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 {
LfBoundNotSatisfied { span: __binding_0, notes: __binding_1
} => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime bound not satisfied")));
diag.code(E0478);
;
diag.span(__binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
}
}
}
};Diagnostic)]
1331#[diag("lifetime bound not satisfied", code = E0478)]
1332pub struct LfBoundNotSatisfied<'a> {
1333 #[primary_span]
1334 pub span: Span,
1335 #[subdiagnostic]
1336 pub notes: Vec<note_and_explain::RegionExplanation<'a>>,
1337}
1338
1339#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
RefLongerThanData<'a> 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 {
RefLongerThanData {
span: __binding_0, ty: __binding_1, notes: __binding_2 } =>
{
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("in type `{$ty}`, reference has a longer lifetime than the data it references")));
diag.code(E0491);
;
diag.arg("ty", __binding_1);
diag.span(__binding_0);
for __binding_2 in __binding_2 {
diag.subdiagnostic(__binding_2);
}
diag
}
}
}
}
};Diagnostic)]
1340#[diag("in type `{$ty}`, reference has a longer lifetime than the data it references", code = E0491)]
1341pub struct RefLongerThanData<'a> {
1342 #[primary_span]
1343 pub span: Span,
1344 pub ty: Ty<'a>,
1345 #[subdiagnostic]
1346 pub notes: Vec<note_and_explain::RegionExplanation<'a>>,
1347}
1348
1349#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for WhereClauseSuggestions {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
WhereClauseSuggestions::Remove { span: __binding_0 } => {
let __code_9 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(""))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("remove the `where` clause")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_9, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowAlways);
}
WhereClauseSuggestions::CopyPredicates {
span: __binding_0,
space: __binding_1,
trait_predicates: __binding_2 } => {
let __code_10 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}where {1}",
__binding_1, __binding_2))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("space".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("trait_predicates".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("copy the `where` clause predicates from the trait")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_10, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowAlways);
}
}
}
}
};Subdiagnostic)]
1350pub enum WhereClauseSuggestions {
1351 #[suggestion(
1352 "remove the `where` clause",
1353 code = "",
1354 applicability = "machine-applicable",
1355 style = "verbose"
1356 )]
1357 Remove {
1358 #[primary_span]
1359 span: Span,
1360 },
1361 #[suggestion(
1362 "copy the `where` clause predicates from the trait",
1363 code = "{space}where {trait_predicates}",
1364 applicability = "machine-applicable",
1365 style = "verbose"
1366 )]
1367 CopyPredicates {
1368 #[primary_span]
1369 span: Span,
1370 space: &'static str,
1371 trait_predicates: String,
1372 },
1373}
1374
1375#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for SuggestRemoveSemiOrReturnBinding
{
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
SuggestRemoveSemiOrReturnBinding::RemoveAndBox {
first_lo: __binding_0,
first_hi: __binding_1,
second_lo: __binding_2,
second_hi: __binding_3,
sp: __binding_4 } => {
let mut suggestions = Vec::new();
let __code_11 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("Box::new("))
});
let __code_12 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(")"))
});
let __code_13 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("Box::new("))
});
let __code_14 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(")"))
});
let __code_15 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(""))
});
suggestions.push((__binding_0, __code_11));
suggestions.push((__binding_1, __code_12));
suggestions.push((__binding_2, __code_13));
suggestions.push((__binding_3, __code_14));
suggestions.push((__binding_4, __code_15));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider removing this semicolon and boxing the expressions")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
}
SuggestRemoveSemiOrReturnBinding::Remove { sp: __binding_0 }
=> {
let __code_16 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(""))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider removing this semicolon")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_16, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::HideCodeInline);
}
SuggestRemoveSemiOrReturnBinding::Add {
sp: __binding_0, code: __binding_1, ident: __binding_2 } =>
{
let __code_17 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_1))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("code".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("ident".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider returning the local binding `{$ident}`")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_17, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
}
SuggestRemoveSemiOrReturnBinding::AddOne {
spans: __binding_0 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider returning one of these bindings")),
&sub_args);
diag.span_note(__binding_0, __message);
}
}
}
}
};Subdiagnostic)]
1376pub enum SuggestRemoveSemiOrReturnBinding {
1377 #[multipart_suggestion(
1378 "consider removing this semicolon and boxing the expressions",
1379 applicability = "machine-applicable"
1380 )]
1381 RemoveAndBox {
1382 #[suggestion_part(code = "Box::new(")]
1383 first_lo: Span,
1384 #[suggestion_part(code = ")")]
1385 first_hi: Span,
1386 #[suggestion_part(code = "Box::new(")]
1387 second_lo: Span,
1388 #[suggestion_part(code = ")")]
1389 second_hi: Span,
1390 #[suggestion_part(code = "")]
1391 sp: Span,
1392 },
1393 #[suggestion(
1394 "consider removing this semicolon",
1395 style = "short",
1396 code = "",
1397 applicability = "machine-applicable"
1398 )]
1399 Remove {
1400 #[primary_span]
1401 sp: Span,
1402 },
1403 #[suggestion(
1404 "consider returning the local binding `{$ident}`",
1405 style = "verbose",
1406 code = "{code}",
1407 applicability = "maybe-incorrect"
1408 )]
1409 Add {
1410 #[primary_span]
1411 sp: Span,
1412 code: String,
1413 ident: Ident,
1414 },
1415 #[note("consider returning one of these bindings")]
1416 AddOne {
1417 #[primary_span]
1418 spans: MultiSpan,
1419 },
1420}
1421
1422#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for ConsiderAddingAwait {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
ConsiderAddingAwait::BothFuturesHelp => {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider `await`ing on both `Future`s")),
&sub_args);
diag.help(__message);
}
ConsiderAddingAwait::BothFuturesSugg {
first: __binding_0, second: __binding_1 } => {
let mut suggestions = Vec::new();
let __code_18 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(".await"))
});
let __code_19 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(".await"))
});
suggestions.push((__binding_0, __code_18));
suggestions.push((__binding_1, __code_19));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider `await`ing on both `Future`s")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
}
ConsiderAddingAwait::FutureSugg { span: __binding_0 } => {
let __code_20 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(".await"))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider `await`ing on the `Future`")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_20, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
}
ConsiderAddingAwait::FutureSuggNote { span: __binding_0 } =>
{
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("calling an async function returns a future")),
&sub_args);
diag.span_note(__binding_0, __message);
}
ConsiderAddingAwait::FutureSuggMultiple { spans: __binding_0
} => {
let mut suggestions = Vec::new();
let __code_21 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(".await"))
});
for __binding_0 in __binding_0 {
suggestions.push((__binding_0, __code_21.clone()));
}
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider `await`ing on the `Future`")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
}
}
}
}
};Subdiagnostic)]
1423pub enum ConsiderAddingAwait {
1424 #[help("consider `await`ing on both `Future`s")]
1425 BothFuturesHelp,
1426 #[multipart_suggestion(
1427 "consider `await`ing on both `Future`s",
1428 applicability = "maybe-incorrect"
1429 )]
1430 BothFuturesSugg {
1431 #[suggestion_part(code = ".await")]
1432 first: Span,
1433 #[suggestion_part(code = ".await")]
1434 second: Span,
1435 },
1436 #[suggestion(
1437 "consider `await`ing on the `Future`",
1438 code = ".await",
1439 style = "verbose",
1440 applicability = "maybe-incorrect"
1441 )]
1442 FutureSugg {
1443 #[primary_span]
1444 span: Span,
1445 },
1446 #[note("calling an async function returns a future")]
1447 FutureSuggNote {
1448 #[primary_span]
1449 span: Span,
1450 },
1451 #[multipart_suggestion(
1452 "consider `await`ing on the `Future`",
1453 style = "verbose",
1454 applicability = "maybe-incorrect"
1455 )]
1456 FutureSuggMultiple {
1457 #[suggestion_part(code = ".await")]
1458 spans: Vec<Span>,
1459 },
1460}
1461
1462#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
PlaceholderRelationLfNotSatisfied 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 {
PlaceholderRelationLfNotSatisfied::HasBoth {
span: __binding_0,
sub_span: __binding_1,
sup_span: __binding_2,
sub_symbol: __binding_3,
sup_symbol: __binding_4,
note: __binding_5 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime bound not satisfied")));
;
diag.arg("sub_symbol", __binding_3);
diag.arg("sup_symbol", __binding_4);
diag.span(__binding_0);
diag.span_note(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the lifetime `{$sub_symbol}` defined here...")));
diag.span_note(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...must outlive the lifetime `{$sup_symbol}` defined here")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)")));
diag
}
PlaceholderRelationLfNotSatisfied::HasSub {
span: __binding_0,
sub_span: __binding_1,
sup_span: __binding_2,
sub_symbol: __binding_3,
note: __binding_4 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime bound not satisfied")));
;
diag.arg("sub_symbol", __binding_3);
diag.span(__binding_0);
diag.span_note(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the lifetime `{$sub_symbol}` defined here...")));
diag.span_note(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...must outlive the lifetime defined here")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)")));
diag
}
PlaceholderRelationLfNotSatisfied::HasSup {
span: __binding_0,
sub_span: __binding_1,
sup_span: __binding_2,
sup_symbol: __binding_3,
note: __binding_4 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime bound not satisfied")));
;
diag.arg("sup_symbol", __binding_3);
diag.span(__binding_0);
diag.span_note(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the lifetime defined here...")));
diag.span_note(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...must outlive the lifetime `{$sup_symbol}` defined here")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)")));
diag
}
PlaceholderRelationLfNotSatisfied::HasNone {
span: __binding_0,
sub_span: __binding_1,
sup_span: __binding_2,
note: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime bound not satisfied")));
;
diag.span(__binding_0);
diag.span_note(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the lifetime defined here...")));
diag.span_note(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...must outlive the lifetime defined here")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)")));
diag
}
PlaceholderRelationLfNotSatisfied::OnlyPrimarySpan {
span: __binding_0, note: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime bound not satisfied")));
;
diag.span(__binding_0);
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)")));
diag
}
}
}
}
};Diagnostic)]
1463pub enum PlaceholderRelationLfNotSatisfied {
1464 #[diag("lifetime bound not satisfied")]
1465 HasBoth {
1466 #[primary_span]
1467 span: Span,
1468 #[note("the lifetime `{$sub_symbol}` defined here...")]
1469 sub_span: Span,
1470 #[note("...must outlive the lifetime `{$sup_symbol}` defined here")]
1471 sup_span: Span,
1472 sub_symbol: Symbol,
1473 sup_symbol: Symbol,
1474 #[note(
1475 "this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)"
1476 )]
1477 note: (),
1478 },
1479 #[diag("lifetime bound not satisfied")]
1480 HasSub {
1481 #[primary_span]
1482 span: Span,
1483 #[note("the lifetime `{$sub_symbol}` defined here...")]
1484 sub_span: Span,
1485 #[note("...must outlive the lifetime defined here")]
1486 sup_span: Span,
1487 sub_symbol: Symbol,
1488 #[note(
1489 "this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)"
1490 )]
1491 note: (),
1492 },
1493 #[diag("lifetime bound not satisfied")]
1494 HasSup {
1495 #[primary_span]
1496 span: Span,
1497 #[note("the lifetime defined here...")]
1498 sub_span: Span,
1499 #[note("...must outlive the lifetime `{$sup_symbol}` defined here")]
1500 sup_span: Span,
1501 sup_symbol: Symbol,
1502 #[note(
1503 "this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)"
1504 )]
1505 note: (),
1506 },
1507 #[diag("lifetime bound not satisfied")]
1508 HasNone {
1509 #[primary_span]
1510 span: Span,
1511 #[note("the lifetime defined here...")]
1512 sub_span: Span,
1513 #[note("...must outlive the lifetime defined here")]
1514 sup_span: Span,
1515 #[note(
1516 "this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)"
1517 )]
1518 note: (),
1519 },
1520 #[diag("lifetime bound not satisfied")]
1521 OnlyPrimarySpan {
1522 #[primary_span]
1523 span: Span,
1524 #[note(
1525 "this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)"
1526 )]
1527 note: (),
1528 },
1529}
1530
1531#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
OpaqueCapturesLifetime<'tcx> 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 {
OpaqueCapturesLifetime {
span: __binding_0,
opaque_ty_span: __binding_1,
opaque_ty: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("hidden type for `{$opaque_ty}` captures lifetime that does not appear in bounds")));
diag.code(E0700);
;
diag.arg("opaque_ty", __binding_2);
diag.span(__binding_0);
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("opaque type defined here")));
diag
}
}
}
}
};Diagnostic)]
1532#[diag("hidden type for `{$opaque_ty}` captures lifetime that does not appear in bounds", code = E0700)]
1533pub struct OpaqueCapturesLifetime<'tcx> {
1534 #[primary_span]
1535 pub span: Span,
1536 #[label("opaque type defined here")]
1537 pub opaque_ty_span: Span,
1538 pub opaque_ty: Ty<'tcx>,
1539}
1540
1541#[derive(const _: () =
{
impl<'a> rustc_errors::Subdiagnostic for FunctionPointerSuggestion<'a>
{
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
FunctionPointerSuggestion::UseRef { span: __binding_0 } => {
let __code_22 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("&"))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider using a reference")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_22, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
}
FunctionPointerSuggestion::RemoveRef {
span: __binding_0, fn_name: __binding_1 } => {
let __code_23 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_1))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider removing the reference")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_23, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
}
FunctionPointerSuggestion::CastRef {
span: __binding_0, fn_name: __binding_1, sig: __binding_2 }
=> {
let __code_24 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("&({0} as {1})",
__binding_1, __binding_2))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider casting to a fn pointer")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_24, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
}
FunctionPointerSuggestion::Cast {
span: __binding_0, sig: __binding_1 } => {
let __code_25 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(" as {0}", __binding_1))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider casting to a fn pointer")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_25, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
}
FunctionPointerSuggestion::CastBoth {
span: __binding_0,
found_sig: __binding_1,
expected_sig: __binding_2 } => {
let __code_26 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(" as {0}", __binding_1))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("expected_sig".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider casting both fn items to fn pointers using `as {$expected_sig}`")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_26, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::HideCodeAlways);
}
FunctionPointerSuggestion::CastBothRef {
span: __binding_0,
fn_name: __binding_1,
found_sig: __binding_2,
expected_sig: __binding_3 } => {
let __code_27 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("&({0} as {1})",
__binding_1, __binding_2))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("expected_sig".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider casting both fn items to fn pointers using `as {$expected_sig}`")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_27, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::HideCodeAlways);
}
}
}
}
};Subdiagnostic)]
1542pub enum FunctionPointerSuggestion<'a> {
1543 #[suggestion(
1544 "consider using a reference",
1545 code = "&",
1546 style = "verbose",
1547 applicability = "maybe-incorrect"
1548 )]
1549 UseRef {
1550 #[primary_span]
1551 span: Span,
1552 },
1553 #[suggestion(
1554 "consider removing the reference",
1555 code = "{fn_name}",
1556 style = "verbose",
1557 applicability = "maybe-incorrect"
1558 )]
1559 RemoveRef {
1560 #[primary_span]
1561 span: Span,
1562 #[skip_arg]
1563 fn_name: String,
1564 },
1565 #[suggestion(
1566 "consider casting to a fn pointer",
1567 code = "&({fn_name} as {sig})",
1568 style = "verbose",
1569 applicability = "maybe-incorrect"
1570 )]
1571 CastRef {
1572 #[primary_span]
1573 span: Span,
1574 #[skip_arg]
1575 fn_name: String,
1576 #[skip_arg]
1577 sig: Binder<'a, FnSig<'a>>,
1578 },
1579 #[suggestion(
1580 "consider casting to a fn pointer",
1581 code = " as {sig}",
1582 style = "verbose",
1583 applicability = "maybe-incorrect"
1584 )]
1585 Cast {
1586 #[primary_span]
1587 span: Span,
1588 #[skip_arg]
1589 sig: Binder<'a, FnSig<'a>>,
1590 },
1591 #[suggestion(
1592 "consider casting both fn items to fn pointers using `as {$expected_sig}`",
1593 code = " as {found_sig}",
1594 style = "hidden",
1595 applicability = "maybe-incorrect"
1596 )]
1597 CastBoth {
1598 #[primary_span]
1599 span: Span,
1600 #[skip_arg]
1601 found_sig: Binder<'a, FnSig<'a>>,
1602 expected_sig: Binder<'a, FnSig<'a>>,
1603 },
1604 #[suggestion(
1605 "consider casting both fn items to fn pointers using `as {$expected_sig}`",
1606 code = "&({fn_name} as {found_sig})",
1607 style = "hidden",
1608 applicability = "maybe-incorrect"
1609 )]
1610 CastBothRef {
1611 #[primary_span]
1612 span: Span,
1613 #[skip_arg]
1614 fn_name: String,
1615 #[skip_arg]
1616 found_sig: Binder<'a, FnSig<'a>>,
1617 expected_sig: Binder<'a, FnSig<'a>>,
1618 },
1619}
1620
1621#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for FnItemsAreDistinct {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
FnItemsAreDistinct => {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("fn items are distinct from fn pointers")),
&sub_args);
diag.note(__message);
}
}
}
}
};Subdiagnostic)]
1622#[note("fn items are distinct from fn pointers")]
1623pub struct FnItemsAreDistinct;
1624
1625#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for FnUniqTypes {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
FnUniqTypes => {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("different fn items have unique types, even if their signatures are the same")),
&sub_args);
diag.note(__message);
}
}
}
}
};Subdiagnostic)]
1626#[note("different fn items have unique types, even if their signatures are the same")]
1627pub struct FnUniqTypes;
1628
1629#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for FnConsiderCasting {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
FnConsiderCasting { casting: __binding_0 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("casting".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider casting the fn item to a fn pointer: `{$casting}`")),
&sub_args);
diag.help(__message);
}
}
}
}
};Subdiagnostic)]
1630#[help("consider casting the fn item to a fn pointer: `{$casting}`")]
1631pub struct FnConsiderCasting {
1632 pub casting: String,
1633}
1634
1635#[derive(const _: () =
{
impl<'a> rustc_errors::Subdiagnostic for FnConsiderCastingBoth<'a> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
FnConsiderCastingBoth { sig: __binding_0 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("sig".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider casting both fn items to fn pointers using `as {$sig}`")),
&sub_args);
diag.help(__message);
}
}
}
}
};Subdiagnostic)]
1636#[help("consider casting both fn items to fn pointers using `as {$sig}`")]
1637pub struct FnConsiderCastingBoth<'a> {
1638 pub sig: Binder<'a, FnSig<'a>>,
1639}
1640
1641#[derive(const _: () =
{
impl<'a> rustc_errors::Subdiagnostic for SuggestAccessingField<'a> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
SuggestAccessingField::Safe {
span: __binding_0,
snippet: __binding_1,
name: __binding_2,
ty: __binding_3 } => {
let __code_28 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{1}.{0}", __binding_2,
__binding_1))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("snippet".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("name".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
sub_args.insert("ty".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("you might have meant to use field `{$name}` whose type is `{$ty}`")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_28, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
}
SuggestAccessingField::Unsafe {
span: __binding_0,
snippet: __binding_1,
name: __binding_2,
ty: __binding_3 } => {
let __code_29 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("unsafe {{ {1}.{0} }}",
__binding_2, __binding_1))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("snippet".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("name".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
sub_args.insert("ty".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("you might have meant to use field `{$name}` whose type is `{$ty}`")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_29, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
}
}
}
}
};Subdiagnostic)]
1642pub enum SuggestAccessingField<'a> {
1643 #[suggestion(
1644 "you might have meant to use field `{$name}` whose type is `{$ty}`",
1645 code = "{snippet}.{name}",
1646 applicability = "maybe-incorrect",
1647 style = "verbose"
1648 )]
1649 Safe {
1650 #[primary_span]
1651 span: Span,
1652 snippet: String,
1653 name: Symbol,
1654 ty: Ty<'a>,
1655 },
1656 #[suggestion(
1657 "you might have meant to use field `{$name}` whose type is `{$ty}`",
1658 code = "unsafe {{ {snippet}.{name} }}",
1659 applicability = "maybe-incorrect",
1660 style = "verbose"
1661 )]
1662 Unsafe {
1663 #[primary_span]
1664 span: Span,
1665 snippet: String,
1666 name: Symbol,
1667 ty: Ty<'a>,
1668 },
1669}
1670
1671#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for SuggestTuplePatternOne {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
SuggestTuplePatternOne {
variant: __binding_0,
span_low: __binding_1,
span_high: __binding_2 } => {
let mut suggestions = Vec::new();
let __code_30 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}(", __binding_0))
});
let __code_31 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(")"))
});
suggestions.push((__binding_1, __code_30));
suggestions.push((__binding_2, __code_31));
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("variant".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("try wrapping the pattern in `{$variant}`")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
}
}
}
}
};Subdiagnostic)]
1672#[multipart_suggestion(
1673 "try wrapping the pattern in `{$variant}`",
1674 applicability = "maybe-incorrect"
1675)]
1676pub struct SuggestTuplePatternOne {
1677 pub variant: String,
1678 #[suggestion_part(code = "{variant}(")]
1679 pub span_low: Span,
1680 #[suggestion_part(code = ")")]
1681 pub span_high: Span,
1682}
1683
1684pub struct SuggestTuplePatternMany {
1685 pub path: String,
1686 pub cause_span: Span,
1687 pub compatible_variants: Vec<String>,
1688}
1689
1690impl Subdiagnostic for SuggestTuplePatternMany {
1691 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1692 diag.arg("path", self.path);
1693 let message = rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("try wrapping the pattern in a variant of `{$path}`"))msg!("try wrapping the pattern in a variant of `{$path}`");
1694 diag.multipart_suggestions(
1695 message,
1696 self.compatible_variants.into_iter().map(|variant| {
1697 ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[(self.cause_span.shrink_to_lo(),
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}(", variant))
})), (self.cause_span.shrink_to_hi(), ")".to_string())]))vec![
1698 (self.cause_span.shrink_to_lo(), format!("{variant}(")),
1699 (self.cause_span.shrink_to_hi(), ")".to_string()),
1700 ]
1701 }),
1702 rustc_errors::Applicability::MaybeIncorrect,
1703 );
1704 }
1705}
1706
1707#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for TypeErrorAdditionalDiags {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
TypeErrorAdditionalDiags::MeantByteLiteral {
span: __binding_0, code: __binding_1 } => {
let __code_32 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("b\'{0}\'", __binding_1))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("code".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("if you meant to write a byte literal, prefix with `b`")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_32, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowAlways);
}
TypeErrorAdditionalDiags::MeantCharLiteral {
span: __binding_0, code: __binding_1 } => {
let __code_33 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("\'{0}\'", __binding_1))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("code".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("if you meant to write a `char` literal, use single quotes")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_33, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowAlways);
}
TypeErrorAdditionalDiags::MeantStrLiteral {
start: __binding_0, end: __binding_1 } => {
let mut suggestions = Vec::new();
let __code_34 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("\""))
});
let __code_35 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("\""))
});
suggestions.push((__binding_0, __code_34));
suggestions.push((__binding_1, __code_35));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("if you meant to write a string literal, use double quotes")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
}
TypeErrorAdditionalDiags::ConsiderSpecifyingLength {
span: __binding_0, length: __binding_1 } => {
let __code_36 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_1))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("length".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider specifying the actual array length")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_36, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
}
TypeErrorAdditionalDiags::TryCannotConvert {
found: __binding_0, expected: __binding_1 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("found".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
sub_args.insert("expected".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`?` operator cannot convert from `{$found}` to `{$expected}`")),
&sub_args);
diag.note(__message);
}
TypeErrorAdditionalDiags::TupleOnlyComma { span: __binding_0
} => {
let __code_37 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(","))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use a trailing comma to create a tuple with one element")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_37, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
}
TypeErrorAdditionalDiags::TupleAlsoParentheses {
span_low: __binding_0, span_high: __binding_1 } => {
let mut suggestions = Vec::new();
let __code_38 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("("))
});
let __code_39 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(",)"))
});
suggestions.push((__binding_0, __code_38));
suggestions.push((__binding_1, __code_39));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use a trailing comma to create a tuple with one element")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
}
TypeErrorAdditionalDiags::AddLetForLetChains {
span: __binding_0 } => {
let __code_40 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("let "))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider adding `let`")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_40, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowAlways);
}
}
}
}
};Subdiagnostic)]
1708pub enum TypeErrorAdditionalDiags {
1709 #[suggestion(
1710 "if you meant to write a byte literal, prefix with `b`",
1711 code = "b'{code}'",
1712 applicability = "machine-applicable",
1713 style = "verbose"
1714 )]
1715 MeantByteLiteral {
1716 #[primary_span]
1717 span: Span,
1718 code: String,
1719 },
1720 #[suggestion(
1721 "if you meant to write a `char` literal, use single quotes",
1722 code = "'{code}'",
1723 applicability = "machine-applicable",
1724 style = "verbose"
1725 )]
1726 MeantCharLiteral {
1727 #[primary_span]
1728 span: Span,
1729 code: String,
1730 },
1731 #[multipart_suggestion(
1732 "if you meant to write a string literal, use double quotes",
1733 applicability = "machine-applicable"
1734 )]
1735 MeantStrLiteral {
1736 #[suggestion_part(code = "\"")]
1737 start: Span,
1738 #[suggestion_part(code = "\"")]
1739 end: Span,
1740 },
1741 #[suggestion(
1742 "consider specifying the actual array length",
1743 code = "{length}",
1744 applicability = "maybe-incorrect",
1745 style = "verbose"
1746 )]
1747 ConsiderSpecifyingLength {
1748 #[primary_span]
1749 span: Span,
1750 length: u64,
1751 },
1752 #[note("`?` operator cannot convert from `{$found}` to `{$expected}`")]
1753 TryCannotConvert { found: String, expected: String },
1754 #[suggestion(
1755 "use a trailing comma to create a tuple with one element",
1756 code = ",",
1757 applicability = "machine-applicable"
1758 )]
1759 TupleOnlyComma {
1760 #[primary_span]
1761 span: Span,
1762 },
1763 #[multipart_suggestion(
1764 "use a trailing comma to create a tuple with one element",
1765 applicability = "machine-applicable"
1766 )]
1767 TupleAlsoParentheses {
1768 #[suggestion_part(code = "(")]
1769 span_low: Span,
1770 #[suggestion_part(code = ",)")]
1771 span_high: Span,
1772 },
1773 #[suggestion(
1774 "consider adding `let`",
1775 style = "verbose",
1776 applicability = "machine-applicable",
1777 code = "let "
1778 )]
1779 AddLetForLetChains {
1780 #[primary_span]
1781 span: Span,
1782 },
1783}
1784
1785#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
ObligationCauseFailureCode 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 {
ObligationCauseFailureCode::MethodCompat {
span: __binding_0, subdiags: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("method not compatible with trait")));
diag.code(E0308);
;
diag.span(__binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
ObligationCauseFailureCode::TypeCompat {
span: __binding_0, subdiags: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("type not compatible with trait")));
diag.code(E0308);
;
diag.span(__binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
ObligationCauseFailureCode::ConstCompat {
span: __binding_0, subdiags: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("const not compatible with trait")));
diag.code(E0308);
;
diag.span(__binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
ObligationCauseFailureCode::TryCompat {
span: __binding_0, subdiags: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`?` operator has incompatible types")));
diag.code(E0308);
;
diag.span(__binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
ObligationCauseFailureCode::MatchCompat {
span: __binding_0, subdiags: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`match` arms have incompatible types")));
diag.code(E0308);
;
diag.span(__binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
ObligationCauseFailureCode::IfElseDifferent {
span: __binding_0, subdiags: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`if` and `else` have incompatible types")));
diag.code(E0308);
;
diag.span(__binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
ObligationCauseFailureCode::NoElse { span: __binding_0 } =>
{
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`if` may be missing an `else` clause")));
diag.code(E0317);
;
diag.span(__binding_0);
diag
}
ObligationCauseFailureCode::NoDiverge {
span: __binding_0, subdiags: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`else` clause of `let...else` does not diverge")));
diag.code(E0308);
;
diag.span(__binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
ObligationCauseFailureCode::FnMainCorrectType {
span: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`main` function has wrong type")));
diag.code(E0580);
;
diag.span(__binding_0);
diag
}
ObligationCauseFailureCode::FnLangCorrectType {
span: __binding_0,
subdiags: __binding_1,
lang_item_name: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$lang_item_name ->\n [panic_impl] `#[panic_handler]`\n *[lang_item_name] lang item `{$lang_item_name}`\n } function has wrong type")));
diag.code(E0308);
;
diag.arg("lang_item_name", __binding_2);
diag.span(__binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
ObligationCauseFailureCode::IntrinsicCorrectType {
span: __binding_0, subdiags: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("intrinsic has wrong type")));
diag.code(E0308);
;
diag.span(__binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
ObligationCauseFailureCode::MethodCorrectType {
span: __binding_0, subdiags: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("mismatched `self` parameter type")));
diag.code(E0308);
;
diag.span(__binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
ObligationCauseFailureCode::ClosureSelfref {
span: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("closure/coroutine type that references itself")));
diag.code(E0644);
;
diag.span(__binding_0);
diag
}
ObligationCauseFailureCode::CantCoerceForceInline {
span: __binding_0, subdiags: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot coerce functions which must be inlined to function pointers")));
diag.code(E0308);
;
diag.span(__binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
ObligationCauseFailureCode::CantCoerceIntrinsic {
span: __binding_0, subdiags: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot coerce intrinsics to function pointers")));
diag.code(E0308);
;
diag.span(__binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
ObligationCauseFailureCode::Generic {
span: __binding_0, subdiags: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("mismatched types")));
diag.code(E0308);
;
diag.span(__binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
}
}
}
};Diagnostic)]
1786pub enum ObligationCauseFailureCode {
1787 #[diag("method not compatible with trait", code = E0308)]
1788 MethodCompat {
1789 #[primary_span]
1790 span: Span,
1791 #[subdiagnostic]
1792 subdiags: Vec<TypeErrorAdditionalDiags>,
1793 },
1794 #[diag("type not compatible with trait", code = E0308)]
1795 TypeCompat {
1796 #[primary_span]
1797 span: Span,
1798 #[subdiagnostic]
1799 subdiags: Vec<TypeErrorAdditionalDiags>,
1800 },
1801 #[diag("const not compatible with trait", code = E0308)]
1802 ConstCompat {
1803 #[primary_span]
1804 span: Span,
1805 #[subdiagnostic]
1806 subdiags: Vec<TypeErrorAdditionalDiags>,
1807 },
1808 #[diag("`?` operator has incompatible types", code = E0308)]
1809 TryCompat {
1810 #[primary_span]
1811 span: Span,
1812 #[subdiagnostic]
1813 subdiags: Vec<TypeErrorAdditionalDiags>,
1814 },
1815 #[diag("`match` arms have incompatible types", code = E0308)]
1816 MatchCompat {
1817 #[primary_span]
1818 span: Span,
1819 #[subdiagnostic]
1820 subdiags: Vec<TypeErrorAdditionalDiags>,
1821 },
1822 #[diag("`if` and `else` have incompatible types", code = E0308)]
1823 IfElseDifferent {
1824 #[primary_span]
1825 span: Span,
1826 #[subdiagnostic]
1827 subdiags: Vec<TypeErrorAdditionalDiags>,
1828 },
1829 #[diag("`if` may be missing an `else` clause", code = E0317)]
1830 NoElse {
1831 #[primary_span]
1832 span: Span,
1833 },
1834 #[diag("`else` clause of `let...else` does not diverge", code = E0308)]
1835 NoDiverge {
1836 #[primary_span]
1837 span: Span,
1838 #[subdiagnostic]
1839 subdiags: Vec<TypeErrorAdditionalDiags>,
1840 },
1841 #[diag("`main` function has wrong type", code = E0580)]
1842 FnMainCorrectType {
1843 #[primary_span]
1844 span: Span,
1845 },
1846 #[diag(
1847 "{$lang_item_name ->
1848 [panic_impl] `#[panic_handler]`
1849 *[lang_item_name] lang item `{$lang_item_name}`
1850 } function has wrong type"
1851 , code = E0308)]
1852 FnLangCorrectType {
1853 #[primary_span]
1854 span: Span,
1855 #[subdiagnostic]
1856 subdiags: Vec<TypeErrorAdditionalDiags>,
1857 lang_item_name: Symbol,
1858 },
1859 #[diag("intrinsic has wrong type", code = E0308)]
1860 IntrinsicCorrectType {
1861 #[primary_span]
1862 span: Span,
1863 #[subdiagnostic]
1864 subdiags: Vec<TypeErrorAdditionalDiags>,
1865 },
1866 #[diag("mismatched `self` parameter type", code = E0308)]
1867 MethodCorrectType {
1868 #[primary_span]
1869 span: Span,
1870 #[subdiagnostic]
1871 subdiags: Vec<TypeErrorAdditionalDiags>,
1872 },
1873 #[diag("closure/coroutine type that references itself", code = E0644)]
1874 ClosureSelfref {
1875 #[primary_span]
1876 span: Span,
1877 },
1878 #[diag("cannot coerce functions which must be inlined to function pointers", code = E0308)]
1879 CantCoerceForceInline {
1880 #[primary_span]
1881 span: Span,
1882 #[subdiagnostic]
1883 subdiags: Vec<TypeErrorAdditionalDiags>,
1884 },
1885 #[diag("cannot coerce intrinsics to function pointers", code = E0308)]
1886 CantCoerceIntrinsic {
1887 #[primary_span]
1888 span: Span,
1889 #[subdiagnostic]
1890 subdiags: Vec<TypeErrorAdditionalDiags>,
1891 },
1892 #[diag("mismatched types", code = E0308)]
1893 Generic {
1894 #[primary_span]
1895 span: Span,
1896 #[subdiagnostic]
1897 subdiags: Vec<TypeErrorAdditionalDiags>,
1898 },
1899}
1900
1901#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for AddPreciseCapturing {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
AddPreciseCapturing::New {
span: __binding_0,
new_lifetime: __binding_1,
concatenated_bounds: __binding_2 } => {
let __code_41 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(" + use<{0}>",
__binding_2))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("new_lifetime".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("concatenated_bounds".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("add a `use<...>` bound to explicitly capture `{$new_lifetime}`")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_41, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowAlways);
}
AddPreciseCapturing::Existing {
span: __binding_0,
new_lifetime: __binding_1,
pre: __binding_2,
post: __binding_3 } => {
let __code_42 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{2}{0}{1}", __binding_1,
__binding_3, __binding_2))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("new_lifetime".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("pre".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
sub_args.insert("post".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("add `{$new_lifetime}` to the `use<...>` bound to explicitly capture it")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_42, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowAlways);
}
}
}
}
};Subdiagnostic)]
1902pub enum AddPreciseCapturing {
1903 #[suggestion(
1904 "add a `use<...>` bound to explicitly capture `{$new_lifetime}`",
1905 style = "verbose",
1906 code = " + use<{concatenated_bounds}>",
1907 applicability = "machine-applicable"
1908 )]
1909 New {
1910 #[primary_span]
1911 span: Span,
1912 new_lifetime: Symbol,
1913 concatenated_bounds: String,
1914 },
1915 #[suggestion(
1916 "add `{$new_lifetime}` to the `use<...>` bound to explicitly capture it",
1917 style = "verbose",
1918 code = "{pre}{new_lifetime}{post}",
1919 applicability = "machine-applicable"
1920 )]
1921 Existing {
1922 #[primary_span]
1923 span: Span,
1924 new_lifetime: Symbol,
1925 pre: &'static str,
1926 post: &'static str,
1927 },
1928}
1929
1930pub struct AddPreciseCapturingAndParams {
1931 pub suggs: Vec<(Span, String)>,
1932 pub new_lifetime: Symbol,
1933 pub apit_spans: Vec<Span>,
1934}
1935
1936impl Subdiagnostic for AddPreciseCapturingAndParams {
1937 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1938 diag.arg("new_lifetime", self.new_lifetime);
1939 diag.multipart_suggestion(
1940 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("add a `use<...>` bound to explicitly capture `{$new_lifetime}` after turning all argument-position `impl Trait` into type parameters, noting that this possibly affects the API of this crate"))msg!("add a `use<...>` bound to explicitly capture `{$new_lifetime}` after turning all argument-position `impl Trait` into type parameters, noting that this possibly affects the API of this crate"),
1941 self.suggs,
1942 Applicability::MaybeIncorrect,
1943 );
1944 diag.span_note(
1945 self.apit_spans,
1946 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("you could use a `use<...>` bound to explicitly capture `{$new_lifetime}`, but argument-position `impl Trait`s are not nameable"))msg!("you could use a `use<...>` bound to explicitly capture `{$new_lifetime}`, but argument-position `impl Trait`s are not nameable"),
1947 );
1948 }
1949}
1950
1951pub fn impl_trait_overcapture_suggestion<'tcx>(
1956 tcx: TyCtxt<'tcx>,
1957 opaque_def_id: LocalDefId,
1958 fn_def_id: LocalDefId,
1959 captured_args: FxIndexSet<DefId>,
1960) -> Option<AddPreciseCapturingForOvercapture> {
1961 let generics = tcx.generics_of(fn_def_id);
1962
1963 let mut captured_lifetimes = FxIndexSet::default();
1964 let mut captured_non_lifetimes = FxIndexSet::default();
1965 let mut synthetics = ::alloc::vec::Vec::new()vec![];
1966
1967 for arg in captured_args {
1968 if tcx.def_kind(arg) == DefKind::LifetimeParam {
1969 captured_lifetimes.insert(tcx.item_name(arg));
1970 } else {
1971 let idx = generics.param_def_id_to_index(tcx, arg).expect("expected arg in scope");
1972 let param = generics.param_at(idx as usize, tcx);
1973 if param.kind.is_synthetic() {
1974 synthetics.push((tcx.def_span(arg), param.name));
1975 } else {
1976 captured_non_lifetimes.insert(tcx.item_name(arg));
1977 }
1978 }
1979 }
1980
1981 let mut next_fresh_param = || {
1982 ['T', 'U', 'V', 'W', 'X', 'Y', 'A', 'B', 'C']
1983 .into_iter()
1984 .map(sym::character)
1985 .chain((0..).map(|i| Symbol::intern(&::alloc::__export::must_use({ ::alloc::fmt::format(format_args!("T{0}", i)) })format!("T{i}"))))
1986 .find(|s| captured_non_lifetimes.insert(*s))
1987 .unwrap()
1988 };
1989
1990 let mut suggs = ::alloc::vec::Vec::new()vec![];
1991 let mut apit_spans = ::alloc::vec::Vec::new()vec![];
1992
1993 if !synthetics.is_empty() {
1994 let mut new_params = String::new();
1995 for (i, (span, name)) in synthetics.into_iter().enumerate() {
1996 apit_spans.push(span);
1997
1998 let fresh_param = next_fresh_param();
1999
2000 suggs.push((span, fresh_param.to_string()));
2002
2003 if i > 0 {
2011 new_params += ", ";
2012 }
2013 let name_as_bounds = name.as_str().trim_start_matches("impl").trim_start();
2014 new_params += fresh_param.as_str();
2015 new_params += ": ";
2016 new_params += name_as_bounds;
2017 }
2018
2019 let Some(generics) = tcx.hir_get_generics(fn_def_id) else {
2020 return None;
2022 };
2023
2024 suggs.push(if let Some(params_span) = generics.span_for_param_suggestion() {
2026 (params_span, ::alloc::__export::must_use({
::alloc::fmt::format(format_args!(", {0}", new_params))
})format!(", {new_params}"))
2027 } else {
2028 (generics.span, ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("<{0}>", new_params))
})format!("<{new_params}>"))
2029 });
2030 }
2031
2032 let concatenated_bounds = captured_lifetimes
2033 .into_iter()
2034 .chain(captured_non_lifetimes)
2035 .map(|sym| sym.to_string())
2036 .collect::<Vec<_>>()
2037 .join(", ");
2038
2039 let opaque_hir_id = tcx.local_def_id_to_hir_id(opaque_def_id);
2040 let (lparen, rparen) = match tcx
2042 .hir_parent_iter(opaque_hir_id)
2043 .nth(1)
2044 .expect("expected ty to have a parent always")
2045 .1
2046 {
2047 Node::PathSegment(segment)
2048 if segment.args().paren_sugar_output().is_some_and(|ty| ty.hir_id == opaque_hir_id) =>
2049 {
2050 ("(", ")")
2051 }
2052 Node::Ty(ty) => match ty.kind {
2053 rustc_hir::TyKind::Ptr(_) | rustc_hir::TyKind::Ref(..) => ("(", ")"),
2054 _ => ("", ""),
2058 },
2059 _ => ("", ""),
2060 };
2061
2062 let rpit_span = tcx.def_span(opaque_def_id);
2063 if !lparen.is_empty() {
2064 suggs.push((rpit_span.shrink_to_lo(), lparen.to_string()));
2065 }
2066 suggs.push((rpit_span.shrink_to_hi(), ::alloc::__export::must_use({
::alloc::fmt::format(format_args!(" + use<{0}>{1}",
concatenated_bounds, rparen))
})format!(" + use<{concatenated_bounds}>{rparen}")));
2067
2068 Some(AddPreciseCapturingForOvercapture { suggs, apit_spans })
2069}
2070
2071pub struct AddPreciseCapturingForOvercapture {
2072 pub suggs: Vec<(Span, String)>,
2073 pub apit_spans: Vec<Span>,
2074}
2075
2076impl Subdiagnostic for AddPreciseCapturingForOvercapture {
2077 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
2078 let applicability = if self.apit_spans.is_empty() {
2079 Applicability::MachineApplicable
2080 } else {
2081 Applicability::MaybeIncorrect
2085 };
2086 diag.multipart_suggestion(
2087 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use the precise capturing `use<...>` syntax to make the captures explicit"))msg!("use the precise capturing `use<...>` syntax to make the captures explicit"),
2088 self.suggs,
2089 applicability,
2090 );
2091 if !self.apit_spans.is_empty() {
2092 diag.span_note(
2093 self.apit_spans,
2094 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("you could use a `use<...>` bound to explicitly specify captures, but argument-position `impl Trait`s are not nameable"))msg!("you could use a `use<...>` bound to explicitly specify captures, but argument-position `impl Trait`s are not nameable"),
2095 );
2096 }
2097 }
2098}
2099
2100#[derive(const _: () =
{
impl<'_sess, 'a, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
NonGenericOpaqueTypeParam<'a, 'tcx> 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 {
NonGenericOpaqueTypeParam {
arg: __binding_0,
kind: __binding_1,
span: __binding_2,
param_span: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected generic {$kind} parameter, found `{$arg}`")));
diag.code(E0792);
;
diag.arg("arg", __binding_0);
diag.arg("kind", __binding_1);
diag.span(__binding_2);
diag.span_label(__binding_3,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{STREQ($arg, \"'static\") ->\n [true] cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type\n *[other] this generic parameter must be used with a generic {$kind} parameter\n }")));
diag
}
}
}
}
};Diagnostic)]
2101#[diag("expected generic {$kind} parameter, found `{$arg}`", code = E0792)]
2102pub(crate) struct NonGenericOpaqueTypeParam<'a, 'tcx> {
2103 pub arg: GenericArg<'tcx>,
2104 pub kind: &'a str,
2105 #[primary_span]
2106 pub span: Span,
2107 #[label("{STREQ($arg, \"'static\") ->
2108 [true] cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type
2109 *[other] this generic parameter must be used with a generic {$kind} parameter
2110 }")]
2111 pub param_span: Span,
2112}