11use crate :: FxHashSet ;
22use clippy_utils:: diagnostics:: span_lint_and_then;
3- use clippy_utils:: get_attr;
3+ use clippy_utils:: { get_attr, is_lint_allowed } ;
44use clippy_utils:: source:: { indent_of, snippet} ;
55use rustc_errors:: { Applicability , Diagnostic } ;
66use rustc_hir:: intravisit:: { walk_expr, Visitor } ;
@@ -19,16 +19,18 @@ pub(super) fn check<'tcx>(
1919 arms : & ' tcx [ Arm < ' _ > ] ,
2020 source : MatchSource ,
2121) {
22+ if is_lint_allowed ( cx, SIGNIFICANT_DROP_IN_SCRUTINEE , expr. hir_id ) {
23+ return ;
24+ }
25+
2226 if let Some ( ( suggestions, message) ) = has_significant_drop_in_scrutinee ( cx, scrutinee, source) {
2327 for found in suggestions {
2428 span_lint_and_then ( cx, SIGNIFICANT_DROP_IN_SCRUTINEE , found. found_span , message, |diag| {
2529 set_diagnostic ( diag, cx, expr, found) ;
2630 let s = Span :: new ( expr. span . hi ( ) , expr. span . hi ( ) , expr. span . ctxt ( ) , None ) ;
27- diag. span_label ( s, "original temporary lives until here" ) ;
28- if let Some ( spans) = has_significant_drop_in_arms ( cx, arms) {
29- for span in spans {
30- diag. span_label ( span, "another temporary with significant `Drop` created here" ) ;
31- }
31+ diag. span_label ( s, "temporary lives until here" ) ;
32+ for span in has_significant_drop_in_arms ( cx, arms) {
33+ diag. span_label ( span, "another value with significant `Drop` created here" ) ;
3234 }
3335 diag. note ( "this might lead to deadlocks or other unexpected behavior" ) ;
3436 } ) ;
@@ -360,19 +362,19 @@ impl<'a, 'tcx> Visitor<'tcx> for SigDropHelper<'a, 'tcx> {
360362
361363struct ArmSigDropHelper < ' a , ' tcx > {
362364 sig_drop_checker : SigDropChecker < ' a , ' tcx > ,
363- found_sig_drop_spans : Option < FxHashSet < Span > > ,
365+ found_sig_drop_spans : FxHashSet < Span > ,
364366}
365367
366368impl < ' a , ' tcx > ArmSigDropHelper < ' a , ' tcx > {
367369 fn new ( cx : & ' a LateContext < ' tcx > ) -> ArmSigDropHelper < ' a , ' tcx > {
368370 ArmSigDropHelper {
369371 sig_drop_checker : SigDropChecker :: new ( cx) ,
370- found_sig_drop_spans : None ,
372+ found_sig_drop_spans : FxHashSet :: < Span > :: default ( ) ,
371373 }
372374 }
373375}
374376
375- fn has_significant_drop_in_arms < ' tcx , ' a > ( cx : & ' a LateContext < ' tcx > , arms : & ' tcx [ Arm < ' _ > ] ) -> Option < FxHashSet < Span > > {
377+ fn has_significant_drop_in_arms < ' tcx , ' a > ( cx : & ' a LateContext < ' tcx > , arms : & ' tcx [ Arm < ' _ > ] ) -> FxHashSet < Span > {
376378 let mut helper = ArmSigDropHelper :: new ( cx) ;
377379 for arm in arms {
378380 helper. visit_expr ( arm. body ) ;
@@ -386,9 +388,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ArmSigDropHelper<'a, 'tcx> {
386388 . sig_drop_checker
387389 . has_sig_drop_attr ( self . sig_drop_checker . cx , self . sig_drop_checker . get_type ( ex) )
388390 {
389- self . found_sig_drop_spans
390- . get_or_insert_with ( FxHashSet :: default)
391- . insert ( ex. span ) ;
391+ self . found_sig_drop_spans . insert ( ex. span ) ;
392392 return ;
393393 }
394394 walk_expr ( self , ex) ;
0 commit comments