1 //! Errors emitted by `rustc_hir_typeck`.
4 use crate::fluent_generated
as fluent
;
5 use rustc_errors
::{AddToDiagnostic, Applicability, Diagnostic, MultiSpan, SubdiagnosticMessage}
;
6 use rustc_macros
::{Diagnostic, Subdiagnostic}
;
7 use rustc_middle
::ty
::Ty
;
9 edition
::{Edition, LATEST_STABLE_EDITION}
,
15 #[diag(hir_typeck_field_multiply_specified_in_initializer, code = "E0062")]
16 pub struct FieldMultiplySpecifiedInInitializer
{
20 #[label(hir_typeck_previous_use_label)]
26 #[diag(hir_typeck_return_stmt_outside_of_fn_body, code = "E0572")]
27 pub struct ReturnStmtOutsideOfFnBody
{
30 #[label(hir_typeck_encl_body_label)]
31 pub encl_body_span
: Option
<Span
>,
32 #[label(hir_typeck_encl_fn_label)]
33 pub encl_fn_span
: Option
<Span
>,
37 #[diag(hir_typeck_yield_expr_outside_of_generator, code = "E0627")]
38 pub struct YieldExprOutsideOfGenerator
{
44 #[diag(hir_typeck_struct_expr_non_exhaustive, code = "E0639")]
45 pub struct StructExprNonExhaustive
{
48 pub what
: &'
static str,
52 #[diag(hir_typeck_method_call_on_unknown_raw_pointee, code = "E0699")]
53 pub struct MethodCallOnUnknownRawPointee
{
59 #[diag(hir_typeck_functional_record_update_on_non_struct, code = "E0436")]
60 pub struct FunctionalRecordUpdateOnNonStruct
{
66 #[diag(hir_typeck_address_of_temporary_taken, code = "E0745")]
67 pub struct AddressOfTemporaryTaken
{
73 #[derive(Subdiagnostic)]
74 pub enum AddReturnTypeSuggestion
{
76 hir_typeck_add_return_type_add
,
78 applicability
= "machine-applicable"
86 hir_typeck_add_return_type_missing_here
,
88 applicability
= "has-placeholders"
96 #[derive(Subdiagnostic)]
97 pub enum ExpectedReturnTypeLabel
<'tcx
> {
98 #[label(hir_typeck_expected_default_return_type)]
103 #[label(hir_typeck_expected_return_type)]
111 #[derive(Diagnostic)]
112 #[diag(hir_typeck_missing_parentheses_in_range, code = "E0689")]
113 pub struct MissingParenthesesInRange
{
115 #[label(hir_typeck_missing_parentheses_in_range)]
118 pub method_name
: String
,
120 pub add_missing_parentheses
: Option
<AddMissingParenthesesInRange
>,
123 #[derive(Subdiagnostic)]
124 #[multipart_suggestion(
125 hir_typeck_add_missing_parentheses_in_range
,
127 applicability
= "maybe-incorrect"
129 pub struct AddMissingParenthesesInRange
{
130 pub func_name
: String
,
131 #[suggestion_part(code = "(")]
133 #[suggestion_part(code = ")")]
137 #[derive(Diagnostic)]
138 #[diag(hir_typeck_op_trait_generic_params)]
139 pub struct OpMethodGenericParams
{
142 pub method_name
: String
,
145 pub struct TypeMismatchFruTypo
{
146 /// Span of the LHS of the range
148 /// Span of the `..RHS` part of the range
150 /// Rendered expression of the RHS of the range
151 pub expr
: Option
<String
>,
154 impl AddToDiagnostic
for TypeMismatchFruTypo
{
155 fn add_to_diagnostic_with
<F
>(self, diag
: &mut Diagnostic
, _
: F
)
157 F
: Fn(&mut Diagnostic
, SubdiagnosticMessage
) -> SubdiagnosticMessage
,
159 diag
.set_arg("expr", self.expr
.as_deref().unwrap_or("NONE"));
161 // Only explain that `a ..b` is a range if it's split up
162 if self.expr_span
.between(self.fru_span
).is_empty() {
163 diag
.span_note(self.expr_span
.to(self.fru_span
), fluent
::hir_typeck_fru_note
);
165 let mut multispan
: MultiSpan
= vec
![self.expr_span
, self.fru_span
].into();
166 multispan
.push_span_label(self.expr_span
, fluent
::hir_typeck_fru_expr
);
167 multispan
.push_span_label(self.fru_span
, fluent
::hir_typeck_fru_expr2
);
168 diag
.span_note(multispan
, fluent
::hir_typeck_fru_note
);
171 diag
.span_suggestion(
172 self.expr_span
.shrink_to_hi(),
173 fluent
::hir_typeck_fru_suggestion
,
175 Applicability
::MaybeIncorrect
,
180 #[derive(Diagnostic)]
181 #[diag(hir_typeck_lang_start_incorrect_number_params)]
182 #[note(hir_typeck_lang_start_incorrect_number_params_note_expected_count)]
183 #[note(hir_typeck_lang_start_expected_sig_note)]
184 pub struct LangStartIncorrectNumberArgs
{
186 pub params_span
: Span
,
187 pub found_param_count
: usize,
190 #[derive(Diagnostic)]
191 #[diag(hir_typeck_lang_start_incorrect_param)]
192 pub struct LangStartIncorrectParam
<'tcx
> {
194 #[suggestion(style = "short", code = "{expected_ty}", applicability = "machine-applicable")]
195 pub param_span
: Span
,
197 pub param_num
: usize,
198 pub expected_ty
: Ty
<'tcx
>,
199 pub found_ty
: Ty
<'tcx
>,
202 #[derive(Diagnostic)]
203 #[diag(hir_typeck_lang_start_incorrect_ret_ty)]
204 pub struct LangStartIncorrectRetTy
<'tcx
> {
206 #[suggestion(style = "short", code = "{expected_ty}", applicability = "machine-applicable")]
209 pub expected_ty
: Ty
<'tcx
>,
210 pub found_ty
: Ty
<'tcx
>,
213 #[derive(Subdiagnostic)]
214 pub enum HelpUseLatestEdition
{
215 #[help(hir_typeck_help_set_edition_cargo)]
216 #[note(hir_typeck_note_edition_guide)]
217 Cargo { edition: Edition }
,
218 #[help(hir_typeck_help_set_edition_standalone)]
219 #[note(hir_typeck_note_edition_guide)]
220 Standalone { edition: Edition }
,
223 impl HelpUseLatestEdition
{
224 pub fn new() -> Self {
225 let edition
= LATEST_STABLE_EDITION
;
226 if std
::env
::var_os("CARGO").is_some() {
227 Self::Cargo { edition }
229 Self::Standalone { edition }
234 #[derive(Diagnostic)]
235 #[diag(hir_typeck_const_select_must_be_const)]
237 pub struct ConstSelectMustBeConst
{
242 #[derive(Diagnostic)]
243 #[diag(hir_typeck_const_select_must_be_fn)]
246 pub struct ConstSelectMustBeFn
<'a
> {
252 #[derive(Diagnostic)]
253 #[diag(hir_typeck_union_pat_multiple_fields)]
254 pub struct UnionPatMultipleFields
{
259 #[derive(Diagnostic)]
260 #[diag(hir_typeck_union_pat_dotdot)]
261 pub struct UnionPatDotDot
{
266 #[derive(Diagnostic)]
267 #[diag(hir_typeck_arg_mismatch_indeterminate)]
268 pub struct ArgMismatchIndeterminate
{
273 #[derive(Subdiagnostic)]
274 pub enum SuggestBoxing
{
275 #[note(hir_typeck_suggest_boxing_note)]
276 #[multipart_suggestion(
277 hir_typeck_suggest_boxing_when_appropriate
,
278 applicability
= "machine-applicable"
281 #[suggestion_part(code = "Box::new(())")]
283 #[suggestion_part(code = "")]
286 #[note(hir_typeck_suggest_boxing_note)]
288 #[note(hir_typeck_suggest_boxing_note)]
289 #[multipart_suggestion(
290 hir_typeck_suggest_boxing_when_appropriate
,
291 applicability
= "machine-applicable"
294 #[suggestion_part(code = "Box::new(")]
296 #[suggestion_part(code = ")")]
301 #[derive(Diagnostic)]
302 #[diag(hir_typeck_no_associated_item, code = "E0599")]
303 pub struct NoAssociatedItem
{
306 pub item_kind
: &'
static str,
307 pub item_name
: Ident
,
308 pub ty_prefix
: Cow
<'
static, str>,
310 pub trait_missing_method
: bool
,
313 #[derive(Subdiagnostic)]
314 #[note(hir_typeck_candidate_trait_note)]
315 pub struct CandidateTraitNote
{
318 pub trait_name
: String
,
319 pub item_name
: Ident
,
320 pub action_or_ty
: String
,
323 #[derive(Diagnostic)]
324 #[diag(hir_typeck_ctor_is_private, code = "E0603")]
325 pub struct CtorIsPrivate
{