@@ -2,9 +2,10 @@ use super::method::probe::ProbeScope;
2
2
use super :: method:: MethodCallee ;
3
3
use super :: { Expectation , FnCtxt , TupleArgumentsFlag } ;
4
4
5
+ use crate :: errors;
5
6
use crate :: type_error_struct;
6
7
use rustc_ast:: util:: parser:: PREC_POSTFIX ;
7
- use rustc_errors:: { struct_span_err , Applicability , Diagnostic , ErrorGuaranteed , StashKey } ;
8
+ use rustc_errors:: { Applicability , Diagnostic , ErrorGuaranteed , StashKey } ;
8
9
use rustc_hir as hir;
9
10
use rustc_hir:: def:: { self , CtorKind , DefKind , Namespace , Res } ;
10
11
use rustc_hir:: def_id:: DefId ;
@@ -44,23 +45,15 @@ pub fn check_legal_trait_for_method_call(
44
45
trait_id : DefId ,
45
46
) {
46
47
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 ( ) ;
48
+ let sugg = if let Some ( receiver) = receiver. filter ( |s| !s. is_empty ( ) ) {
49
+ errors:: ExplicitDestructorCallSugg :: Snippet {
50
+ lo : expr_span. shrink_to_lo ( ) ,
51
+ hi : receiver. shrink_to_hi ( ) . to ( expr_span. shrink_to_hi ( ) ) ,
52
+ }
53
+ } else {
54
+ errors:: ExplicitDestructorCallSugg :: Empty ( span)
55
+ } ;
56
+ tcx. sess . emit_err ( errors:: ExplicitDestructorCall { span, sugg } ) ;
64
57
}
65
58
}
66
59
0 commit comments