mirror of https://github.com/rust-lang/rust.git
Rollup merge of #115862 - clubby789:migrate-callee-translatable, r=compiler-errors
Migrate `compiler/rustc_hir_typeck/src/callee.rs` to translatable diagnostics
This commit is contained in:
commit
f082f1dd30
|
@ -33,6 +33,10 @@ hir_typeck_expected_default_return_type = expected `()` because of default retur
|
||||||
|
|
||||||
hir_typeck_expected_return_type = expected `{$expected}` because of return type
|
hir_typeck_expected_return_type = expected `{$expected}` because of return type
|
||||||
|
|
||||||
|
hir_typeck_explicit_destructor = explicit use of destructor method
|
||||||
|
.label = explicit destructor calls not allowed
|
||||||
|
.suggestion = consider using `drop` function
|
||||||
|
|
||||||
hir_typeck_field_multiply_specified_in_initializer =
|
hir_typeck_field_multiply_specified_in_initializer =
|
||||||
field `{$ident}` specified more than once
|
field `{$ident}` specified more than once
|
||||||
.label = used more than once
|
.label = used more than once
|
||||||
|
@ -52,8 +56,10 @@ hir_typeck_functional_record_update_on_non_struct =
|
||||||
|
|
||||||
hir_typeck_help_set_edition_cargo = set `edition = "{$edition}"` in `Cargo.toml`
|
hir_typeck_help_set_edition_cargo = set `edition = "{$edition}"` in `Cargo.toml`
|
||||||
hir_typeck_help_set_edition_standalone = pass `--edition {$edition}` to `rustc`
|
hir_typeck_help_set_edition_standalone = pass `--edition {$edition}` to `rustc`
|
||||||
hir_typeck_lang_start_expected_sig_note = the `start` lang item should have the signature `fn(fn() -> T, isize, *const *const u8, u8) -> isize`
|
|
||||||
|
|
||||||
|
hir_typeck_invalid_callee = expected function, found {$ty}
|
||||||
|
|
||||||
|
hir_typeck_lang_start_expected_sig_note = the `start` lang item should have the signature `fn(fn() -> T, isize, *const *const u8, u8) -> isize`
|
||||||
hir_typeck_lang_start_incorrect_number_params = incorrect number of parameters for the `start` lang item
|
hir_typeck_lang_start_incorrect_number_params = incorrect number of parameters for the `start` lang item
|
||||||
hir_typeck_lang_start_incorrect_number_params_note_expected_count = the `start` lang item should have four parameters, but found {$found_param_count}
|
hir_typeck_lang_start_incorrect_number_params_note_expected_count = the `start` lang item should have four parameters, but found {$found_param_count}
|
||||||
|
|
||||||
|
@ -66,6 +72,9 @@ hir_typeck_lang_start_incorrect_ret_ty = the return type of the `start` lang ite
|
||||||
hir_typeck_method_call_on_unknown_raw_pointee =
|
hir_typeck_method_call_on_unknown_raw_pointee =
|
||||||
cannot call a method on a raw pointer with an unknown pointee type
|
cannot call a method on a raw pointer with an unknown pointee type
|
||||||
|
|
||||||
|
hir_typeck_missing_fn_lang_items = failed to find an overloaded call trait for closure call
|
||||||
|
.help = make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods
|
||||||
|
|
||||||
hir_typeck_missing_parentheses_in_range = can't call method `{$method_name}` on type `{$ty_str}`
|
hir_typeck_missing_parentheses_in_range = can't call method `{$method_name}` on type `{$ty_str}`
|
||||||
|
|
||||||
hir_typeck_no_associated_item = no {$item_kind} named `{$item_name}` found for {$ty_prefix} `{$ty_str}`{$trait_missing_method ->
|
hir_typeck_no_associated_item = no {$item_kind} named `{$item_name}` found for {$ty_prefix} `{$ty_str}`{$trait_missing_method ->
|
||||||
|
@ -92,6 +101,9 @@ hir_typeck_return_stmt_outside_of_fn_body =
|
||||||
.encl_body_label = the {$statement_kind} is part of this body...
|
.encl_body_label = the {$statement_kind} is part of this body...
|
||||||
.encl_fn_label = ...not the enclosing function body
|
.encl_fn_label = ...not the enclosing function body
|
||||||
|
|
||||||
|
hir_typeck_rustcall_incorrect_args =
|
||||||
|
functions with the "rust-call" ABI must take a single non-self tuple argument
|
||||||
|
|
||||||
hir_typeck_struct_expr_non_exhaustive =
|
hir_typeck_struct_expr_non_exhaustive =
|
||||||
cannot create non-exhaustive {$what} using struct expression
|
cannot create non-exhaustive {$what} using struct expression
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,9 @@ use super::method::probe::ProbeScope;
|
||||||
use super::method::MethodCallee;
|
use super::method::MethodCallee;
|
||||||
use super::{Expectation, FnCtxt, TupleArgumentsFlag};
|
use super::{Expectation, FnCtxt, TupleArgumentsFlag};
|
||||||
|
|
||||||
use crate::type_error_struct;
|
use crate::errors;
|
||||||
use rustc_ast::util::parser::PREC_POSTFIX;
|
use rustc_ast::util::parser::PREC_POSTFIX;
|
||||||
use rustc_errors::{struct_span_err, Applicability, Diagnostic, ErrorGuaranteed, StashKey};
|
use rustc_errors::{Applicability, Diagnostic, ErrorGuaranteed, StashKey};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{self, CtorKind, DefKind, Namespace, Res};
|
use rustc_hir::def::{self, CtorKind, DefKind, Namespace, Res};
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
|
@ -44,23 +44,15 @@ pub fn check_legal_trait_for_method_call(
|
||||||
trait_id: DefId,
|
trait_id: DefId,
|
||||||
) {
|
) {
|
||||||
if tcx.lang_items().drop_trait() == Some(trait_id) {
|
if tcx.lang_items().drop_trait() == Some(trait_id) {
|
||||||
let mut err = struct_span_err!(tcx.sess, span, E0040, "explicit use of destructor method");
|
let sugg = if let Some(receiver) = receiver.filter(|s| !s.is_empty()) {
|
||||||
err.span_label(span, "explicit destructor calls not allowed");
|
errors::ExplicitDestructorCallSugg::Snippet {
|
||||||
|
lo: expr_span.shrink_to_lo(),
|
||||||
let (sp, suggestion) = receiver
|
hi: receiver.shrink_to_hi().to(expr_span.shrink_to_hi()),
|
||||||
.and_then(|s| tcx.sess.source_map().span_to_snippet(s).ok())
|
}
|
||||||
.filter(|snippet| !snippet.is_empty())
|
} else {
|
||||||
.map(|snippet| (expr_span, format!("drop({snippet})")))
|
errors::ExplicitDestructorCallSugg::Empty(span)
|
||||||
.unwrap_or_else(|| (span, "drop".to_string()));
|
};
|
||||||
|
tcx.sess.emit_err(errors::ExplicitDestructorCall { span, sugg });
|
||||||
err.span_suggestion(
|
|
||||||
sp,
|
|
||||||
"consider using `drop` function",
|
|
||||||
suggestion,
|
|
||||||
Applicability::MaybeIncorrect,
|
|
||||||
);
|
|
||||||
|
|
||||||
err.emit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -387,6 +379,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
// Unit testing: function items annotated with
|
// Unit testing: function items annotated with
|
||||||
// `#[rustc_evaluate_where_clauses]` trigger special output
|
// `#[rustc_evaluate_where_clauses]` trigger special output
|
||||||
// to let us test the trait evaluation system.
|
// to let us test the trait evaluation system.
|
||||||
|
// Untranslatable diagnostics are okay for rustc internals
|
||||||
|
#[allow(rustc::untranslatable_diagnostic)]
|
||||||
|
#[allow(rustc::diagnostic_outside_of_impl)]
|
||||||
if self.tcx.has_attr(def_id, sym::rustc_evaluate_where_clauses) {
|
if self.tcx.has_attr(def_id, sym::rustc_evaluate_where_clauses) {
|
||||||
let predicates = self.tcx.predicates_of(def_id);
|
let predicates = self.tcx.predicates_of(def_id);
|
||||||
let predicates = predicates.instantiate(self.tcx, args);
|
let predicates = predicates.instantiate(self.tcx, args);
|
||||||
|
@ -478,10 +473,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
);
|
);
|
||||||
self.require_type_is_sized(ty, sp, traits::RustCall);
|
self.require_type_is_sized(ty, sp, traits::RustCall);
|
||||||
} else {
|
} else {
|
||||||
self.tcx.sess.span_err(
|
self.tcx.sess.emit_err(errors::RustCallIncorrectArgs { span: sp });
|
||||||
sp,
|
|
||||||
"functions with the \"rust-call\" ABI must take a single non-self tuple argument",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -610,17 +602,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let callee_ty = self.resolve_vars_if_possible(callee_ty);
|
let callee_ty = self.resolve_vars_if_possible(callee_ty);
|
||||||
let mut err = type_error_struct!(
|
let mut err = self.tcx.sess.create_err(errors::InvalidCallee {
|
||||||
self.tcx.sess,
|
span: callee_expr.span,
|
||||||
callee_expr.span,
|
ty: match &unit_variant {
|
||||||
callee_ty,
|
|
||||||
E0618,
|
|
||||||
"expected function, found {}",
|
|
||||||
match &unit_variant {
|
|
||||||
Some((_, kind, path)) => format!("{kind} `{path}`"),
|
Some((_, kind, path)) => format!("{kind} `{path}`"),
|
||||||
None => format!("`{callee_ty}`"),
|
None => format!("`{callee_ty}`"),
|
||||||
}
|
},
|
||||||
);
|
});
|
||||||
|
if callee_ty.references_error() {
|
||||||
|
err.downgrade_to_delayed_bug();
|
||||||
|
}
|
||||||
|
|
||||||
self.identify_bad_closure_def_and_call(
|
self.identify_bad_closure_def_and_call(
|
||||||
&mut err,
|
&mut err,
|
||||||
|
@ -891,15 +882,7 @@ impl<'a, 'tcx> DeferredCallResolution<'tcx> {
|
||||||
None => {
|
None => {
|
||||||
// This can happen if `#![no_core]` is used and the `fn/fn_mut/fn_once`
|
// This can happen if `#![no_core]` is used and the `fn/fn_mut/fn_once`
|
||||||
// lang items are not defined (issue #86238).
|
// lang items are not defined (issue #86238).
|
||||||
let mut err = fcx.inh.tcx.sess.struct_span_err(
|
fcx.inh.tcx.sess.emit_err(errors::MissingFnLangItems { span: self.call_expr.span });
|
||||||
self.call_expr.span,
|
|
||||||
"failed to find an overloaded call trait for closure call",
|
|
||||||
);
|
|
||||||
err.help(
|
|
||||||
"make sure the `fn`/`fn_mut`/`fn_once` lang items are defined \
|
|
||||||
and have correctly defined `call`/`call_mut`/`call_once` methods",
|
|
||||||
);
|
|
||||||
err.emit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,13 @@ impl IntoDiagnosticArg for ReturnLikeStatementKind {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(hir_typeck_rustcall_incorrect_args)]
|
||||||
|
pub struct RustCallIncorrectArgs {
|
||||||
|
#[primary_span]
|
||||||
|
pub span: Span,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(hir_typeck_yield_expr_outside_of_generator, code = "E0627")]
|
#[diag(hir_typeck_yield_expr_outside_of_generator, code = "E0627")]
|
||||||
pub struct YieldExprOutsideOfGenerator {
|
pub struct YieldExprOutsideOfGenerator {
|
||||||
|
@ -76,6 +83,14 @@ pub struct MethodCallOnUnknownRawPointee {
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(hir_typeck_missing_fn_lang_items)]
|
||||||
|
#[help]
|
||||||
|
pub struct MissingFnLangItems {
|
||||||
|
#[primary_span]
|
||||||
|
pub span: Span,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(hir_typeck_functional_record_update_on_non_struct, code = "E0436")]
|
#[diag(hir_typeck_functional_record_update_on_non_struct, code = "E0436")]
|
||||||
pub struct FunctionalRecordUpdateOnNonStruct {
|
pub struct FunctionalRecordUpdateOnNonStruct {
|
||||||
|
@ -129,6 +144,29 @@ pub enum ExpectedReturnTypeLabel<'tcx> {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(hir_typeck_explicit_destructor, code = "E0040")]
|
||||||
|
pub struct ExplicitDestructorCall {
|
||||||
|
#[primary_span]
|
||||||
|
#[label]
|
||||||
|
pub span: Span,
|
||||||
|
#[subdiagnostic]
|
||||||
|
pub sugg: ExplicitDestructorCallSugg,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Subdiagnostic)]
|
||||||
|
pub enum ExplicitDestructorCallSugg {
|
||||||
|
#[suggestion(hir_typeck_suggestion, code = "drop", applicability = "maybe-incorrect")]
|
||||||
|
Empty(#[primary_span] Span),
|
||||||
|
#[multipart_suggestion(hir_typeck_suggestion, style = "short")]
|
||||||
|
Snippet {
|
||||||
|
#[suggestion_part(code = "drop(")]
|
||||||
|
lo: Span,
|
||||||
|
#[suggestion_part(code = ")")]
|
||||||
|
hi: Span,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(hir_typeck_missing_parentheses_in_range, code = "E0689")]
|
#[diag(hir_typeck_missing_parentheses_in_range, code = "E0689")]
|
||||||
pub struct MissingParenthesesInRange {
|
pub struct MissingParenthesesInRange {
|
||||||
|
@ -252,6 +290,14 @@ impl HelpUseLatestEdition {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(hir_typeck_invalid_callee, code = "E0618")]
|
||||||
|
pub struct InvalidCallee {
|
||||||
|
#[primary_span]
|
||||||
|
pub span: Span,
|
||||||
|
pub ty: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
#[derive(Subdiagnostic)]
|
||||||
pub enum OptionResultRefMismatch {
|
pub enum OptionResultRefMismatch {
|
||||||
#[suggestion(
|
#[suggestion(
|
||||||
|
|
|
@ -2,10 +2,12 @@ error[E0040]: explicit use of destructor method
|
||||||
--> $DIR/E0040.rs:16:7
|
--> $DIR/E0040.rs:16:7
|
||||||
|
|
|
|
||||||
LL | x.drop();
|
LL | x.drop();
|
||||||
| --^^^^--
|
| ^^^^ explicit destructor calls not allowed
|
||||||
| | |
|
|
|
||||||
| | explicit destructor calls not allowed
|
help: consider using `drop` function
|
||||||
| help: consider using `drop` function: `drop(x)`
|
|
|
||||||
|
LL | drop(x);
|
||||||
|
| +++++ ~
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,12 @@ error[E0040]: explicit use of destructor method
|
||||||
--> $DIR/explicit-call-to-dtor.rs:15:7
|
--> $DIR/explicit-call-to-dtor.rs:15:7
|
||||||
|
|
|
|
||||||
LL | x.drop();
|
LL | x.drop();
|
||||||
| --^^^^--
|
| ^^^^ explicit destructor calls not allowed
|
||||||
| | |
|
|
|
||||||
| | explicit destructor calls not allowed
|
help: consider using `drop` function
|
||||||
| help: consider using `drop` function: `drop(x)`
|
|
|
||||||
|
LL | drop(x);
|
||||||
|
| +++++ ~
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,12 @@ error[E0040]: explicit use of destructor method
|
||||||
--> $DIR/explicit-call-to-supertrait-dtor.rs:22:14
|
--> $DIR/explicit-call-to-supertrait-dtor.rs:22:14
|
||||||
|
|
|
|
||||||
LL | self.drop();
|
LL | self.drop();
|
||||||
| -----^^^^--
|
| ^^^^ explicit destructor calls not allowed
|
||||||
| | |
|
|
|
||||||
| | explicit destructor calls not allowed
|
help: consider using `drop` function
|
||||||
| help: consider using `drop` function: `drop(self)`
|
|
|
||||||
|
LL | drop(self);
|
||||||
|
| +++++ ~
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue