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