@@ -2,9 +2,9 @@ use super::method::probe::ProbeScope;
2
2
use super :: method:: MethodCallee ;
3
3
use super :: { Expectation , FnCtxt , TupleArgumentsFlag } ;
4
4
5
- use crate :: type_error_struct ;
5
+ use crate :: errors ;
6
6
use rustc_ast:: util:: parser:: PREC_POSTFIX ;
7
- use rustc_errors:: { struct_span_err , Applicability , Diagnostic , ErrorGuaranteed , StashKey } ;
7
+ use rustc_errors:: { Applicability , Diagnostic , ErrorGuaranteed , StashKey } ;
8
8
use rustc_hir as hir;
9
9
use rustc_hir:: def:: { self , CtorKind , DefKind , Namespace , Res } ;
10
10
use rustc_hir:: def_id:: DefId ;
@@ -44,23 +44,15 @@ pub fn check_legal_trait_for_method_call(
44
44
trait_id : DefId ,
45
45
) {
46
46
if tcx. lang_items ( ) . drop_trait ( ) == Some ( trait_id) {
47
- let mut err = struct_span_err ! ( tcx. sess, span, E0040 , "explicit use of destructor method" ) ;
48
- err. span_label ( span, "explicit destructor calls not allowed" ) ;
49
-
50
- let ( sp, suggestion) = receiver
51
- . and_then ( |s| tcx. sess . source_map ( ) . span_to_snippet ( s) . ok ( ) )
52
- . filter ( |snippet| !snippet. is_empty ( ) )
53
- . map ( |snippet| ( expr_span, format ! ( "drop({snippet})" ) ) )
54
- . unwrap_or_else ( || ( span, "drop" . to_string ( ) ) ) ;
55
-
56
- err. span_suggestion (
57
- sp,
58
- "consider using `drop` function" ,
59
- suggestion,
60
- Applicability :: MaybeIncorrect ,
61
- ) ;
62
-
63
- err. emit ( ) ;
47
+ let sugg = if let Some ( receiver) = receiver. filter ( |s| !s. is_empty ( ) ) {
48
+ errors:: ExplicitDestructorCallSugg :: Snippet {
49
+ lo : expr_span. shrink_to_lo ( ) ,
50
+ hi : receiver. shrink_to_hi ( ) . to ( expr_span. shrink_to_hi ( ) ) ,
51
+ }
52
+ } else {
53
+ errors:: ExplicitDestructorCallSugg :: Empty ( span)
54
+ } ;
55
+ tcx. sess . emit_err ( errors:: ExplicitDestructorCall { span, sugg } ) ;
64
56
}
65
57
}
66
58
@@ -387,6 +379,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
387
379
// Unit testing: function items annotated with
388
380
// `#[rustc_evaluate_where_clauses]` trigger special output
389
381
// to let us test the trait evaluation system.
382
+ // Untranslatable diagnostics are okay for rustc internals
383
+ #[ allow( rustc:: untranslatable_diagnostic) ]
384
+ #[ allow( rustc:: diagnostic_outside_of_impl) ]
390
385
if self . tcx . has_attr ( def_id, sym:: rustc_evaluate_where_clauses) {
391
386
let predicates = self . tcx . predicates_of ( def_id) ;
392
387
let predicates = predicates. instantiate ( self . tcx , args) ;
@@ -478,10 +473,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
478
473
) ;
479
474
self . require_type_is_sized ( ty, sp, traits:: RustCall ) ;
480
475
} else {
481
- self . tcx . sess . span_err (
482
- sp,
483
- "functions with the \" rust-call\" ABI must take a single non-self tuple argument" ,
484
- ) ;
476
+ self . tcx . sess . emit_err ( errors:: RustCallIncorrectArgs { span : sp } ) ;
485
477
}
486
478
}
487
479
@@ -610,17 +602,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
610
602
}
611
603
612
604
let callee_ty = self . resolve_vars_if_possible ( callee_ty) ;
613
- let mut err = type_error_struct ! (
614
- self . tcx. sess,
615
- callee_expr. span,
616
- callee_ty,
617
- E0618 ,
618
- "expected function, found {}" ,
619
- match & unit_variant {
605
+ let mut err = self . tcx . sess . create_err ( errors:: InvalidCallee {
606
+ span : callee_expr. span ,
607
+ ty : match & unit_variant {
620
608
Some ( ( _, kind, path) ) => format ! ( "{kind} `{path}`" ) ,
621
609
None => format ! ( "`{callee_ty}`" ) ,
622
- }
623
- ) ;
610
+ } ,
611
+ } ) ;
612
+ if callee_ty. references_error ( ) {
613
+ err. downgrade_to_delayed_bug ( ) ;
614
+ }
624
615
625
616
self . identify_bad_closure_def_and_call (
626
617
& mut err,
@@ -891,15 +882,7 @@ impl<'a, 'tcx> DeferredCallResolution<'tcx> {
891
882
None => {
892
883
// This can happen if `#![no_core]` is used and the `fn/fn_mut/fn_once`
893
884
// lang items are not defined (issue #86238).
894
- let mut err = fcx. inh . tcx . sess . struct_span_err (
895
- self . call_expr . span ,
896
- "failed to find an overloaded call trait for closure call" ,
897
- ) ;
898
- err. help (
899
- "make sure the `fn`/`fn_mut`/`fn_once` lang items are defined \
900
- and have correctly defined `call`/`call_mut`/`call_once` methods",
901
- ) ;
902
- err. emit ( ) ;
885
+ fcx. inh . tcx . sess . emit_err ( errors:: MissingFnLangItems { span : self . call_expr . span } ) ;
903
886
}
904
887
}
905
888
}
0 commit comments