1
1
use crate :: FxHashSet ;
2
2
use clippy_utils:: diagnostics:: span_lint_and_then;
3
- use clippy_utils:: get_attr;
3
+ use clippy_utils:: { get_attr, is_lint_allowed } ;
4
4
use clippy_utils:: source:: { indent_of, snippet} ;
5
5
use rustc_errors:: { Applicability , Diagnostic } ;
6
6
use rustc_hir:: intravisit:: { walk_expr, Visitor } ;
@@ -19,16 +19,18 @@ pub(super) fn check<'tcx>(
19
19
arms : & ' tcx [ Arm < ' _ > ] ,
20
20
source : MatchSource ,
21
21
) {
22
+ if is_lint_allowed ( cx, SIGNIFICANT_DROP_IN_SCRUTINEE , expr. hir_id ) {
23
+ return ;
24
+ }
25
+
22
26
if let Some ( ( suggestions, message) ) = has_significant_drop_in_scrutinee ( cx, scrutinee, source) {
23
27
for found in suggestions {
24
28
span_lint_and_then ( cx, SIGNIFICANT_DROP_IN_SCRUTINEE , found. found_span , message, |diag| {
25
29
set_diagnostic ( diag, cx, expr, found) ;
26
30
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" ) ;
32
34
}
33
35
diag. note ( "this might lead to deadlocks or other unexpected behavior" ) ;
34
36
} ) ;
@@ -360,19 +362,19 @@ impl<'a, 'tcx> Visitor<'tcx> for SigDropHelper<'a, 'tcx> {
360
362
361
363
struct ArmSigDropHelper < ' a , ' tcx > {
362
364
sig_drop_checker : SigDropChecker < ' a , ' tcx > ,
363
- found_sig_drop_spans : Option < FxHashSet < Span > > ,
365
+ found_sig_drop_spans : FxHashSet < Span > ,
364
366
}
365
367
366
368
impl < ' a , ' tcx > ArmSigDropHelper < ' a , ' tcx > {
367
369
fn new ( cx : & ' a LateContext < ' tcx > ) -> ArmSigDropHelper < ' a , ' tcx > {
368
370
ArmSigDropHelper {
369
371
sig_drop_checker : SigDropChecker :: new ( cx) ,
370
- found_sig_drop_spans : None ,
372
+ found_sig_drop_spans : FxHashSet :: < Span > :: default ( ) ,
371
373
}
372
374
}
373
375
}
374
376
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 > {
376
378
let mut helper = ArmSigDropHelper :: new ( cx) ;
377
379
for arm in arms {
378
380
helper. visit_expr ( arm. body ) ;
@@ -386,9 +388,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ArmSigDropHelper<'a, 'tcx> {
386
388
. sig_drop_checker
387
389
. has_sig_drop_attr ( self . sig_drop_checker . cx , self . sig_drop_checker . get_type ( ex) )
388
390
{
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 ) ;
392
392
return ;
393
393
}
394
394
walk_expr ( self , ex) ;
0 commit comments