@@ -1500,7 +1500,8 @@ impl InvalidAtomicOrdering {
1500
1500
fn check_atomic_load_store ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) {
1501
1501
use rustc_hir:: def:: { DefKind , Res } ;
1502
1502
use rustc_hir:: QPath ;
1503
- if let Some ( ( method, args) ) = Self :: inherent_atomic_method_call ( cx, expr, & [ sym:: load, sym:: store] )
1503
+ if let Some ( ( method, args) ) =
1504
+ Self :: inherent_atomic_method_call ( cx, expr, & [ sym:: load, sym:: store] )
1504
1505
&& let Some ( ( ordering_arg, invalid_ordering) ) = match method {
1505
1506
sym:: load => Some ( ( & args[ 1 ] , sym:: Release ) ) ,
1506
1507
sym:: store => Some ( ( & args[ 2 ] , sym:: Acquire ) ) ,
@@ -1536,56 +1537,58 @@ impl InvalidAtomicOrdering {
1536
1537
{
1537
1538
cx. struct_span_lint ( INVALID_ATOMIC_ORDERING , args[ 0 ] . span , |diag| {
1538
1539
diag. build ( "memory fences cannot have `Relaxed` ordering" )
1539
- . help ( "consider using ordering modes `Acquire`, `Release`, `AcqRel` or `SeqCst`" )
1540
+ . help (
1541
+ "consider using ordering modes `Acquire`, `Release`, `AcqRel` or `SeqCst`" ,
1542
+ )
1540
1543
. emit ( ) ;
1541
1544
} ) ;
1542
1545
}
1543
1546
}
1544
1547
1545
1548
fn check_atomic_compare_exchange ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) {
1546
- if let Some ( ( method, args) ) = Self :: inherent_atomic_method_call ( cx, expr, & [ sym:: fetch_update, sym:: compare_exchange, sym:: compare_exchange_weak] )
1547
- && let Some ( ( success_order_arg, failure_order_arg) ) = match method {
1548
- sym:: fetch_update => Some ( ( & args[ 1 ] , & args[ 2 ] ) ) ,
1549
- sym:: compare_exchange | sym:: compare_exchange_weak => Some ( ( & args[ 3 ] , & args[ 4 ] ) ) ,
1550
- _ => None ,
1551
- }
1552
- && let Some ( fail_ordering_def_id) = Self :: opt_ordering_defid ( cx, failure_order_arg)
1549
+ if let Some ( ( method, args) ) = Self :: inherent_atomic_method_call (
1550
+ cx,
1551
+ expr,
1552
+ & [ sym:: fetch_update, sym:: compare_exchange, sym:: compare_exchange_weak] ,
1553
+ ) && let Some ( ( success_order_arg, failure_order_arg) ) = match method {
1554
+ sym:: fetch_update => Some ( ( & args[ 1 ] , & args[ 2 ] ) ) ,
1555
+ sym:: compare_exchange | sym:: compare_exchange_weak => Some ( ( & args[ 3 ] , & args[ 4 ] ) ) ,
1556
+ _ => None ,
1557
+ } && let Some ( fail_ordering_def_id) = Self :: opt_ordering_defid ( cx, failure_order_arg)
1553
1558
{
1554
1559
// Helper type holding on to some checking and error reporting data. Has
1555
1560
// - (success ordering,
1556
1561
// - list of failure orderings forbidden by the success order,
1557
1562
// - suggestion message)
1558
1563
type OrdLintInfo = ( Symbol , & ' static [ Symbol ] , & ' static str ) ;
1559
- const RELAXED : OrdLintInfo = ( sym:: Relaxed , & [ sym:: SeqCst , sym:: Acquire ] , "ordering mode `Relaxed`" ) ;
1560
- const ACQUIRE : OrdLintInfo = ( sym:: Acquire , & [ sym:: SeqCst ] , "ordering modes `Acquire` or `Relaxed`" ) ;
1561
- const SEQ_CST : OrdLintInfo = ( sym:: SeqCst , & [ ] , "ordering modes `Acquire`, `SeqCst` or `Relaxed`" ) ;
1564
+ const RELAXED : OrdLintInfo =
1565
+ ( sym:: Relaxed , & [ sym:: SeqCst , sym:: Acquire ] , "ordering mode `Relaxed`" ) ;
1566
+ const ACQUIRE : OrdLintInfo =
1567
+ ( sym:: Acquire , & [ sym:: SeqCst ] , "ordering modes `Acquire` or `Relaxed`" ) ;
1568
+ const SEQ_CST : OrdLintInfo =
1569
+ ( sym:: SeqCst , & [ ] , "ordering modes `Acquire`, `SeqCst` or `Relaxed`" ) ;
1562
1570
const RELEASE : OrdLintInfo = ( sym:: Release , RELAXED . 1 , RELAXED . 2 ) ;
1563
1571
const ACQREL : OrdLintInfo = ( sym:: AcqRel , ACQUIRE . 1 , ACQUIRE . 2 ) ;
1564
1572
const SEARCH : [ OrdLintInfo ; 5 ] = [ RELAXED , ACQUIRE , SEQ_CST , RELEASE , ACQREL ] ;
1565
1573
1566
- let success_lint_info = Self :: opt_ordering_defid ( cx, success_order_arg)
1567
- . and_then ( |success_ord_def_id| -> Option < OrdLintInfo > {
1568
- SEARCH
1569
- . iter ( )
1570
- . copied ( )
1571
- . find ( |( ordering, ..) | {
1572
- Self :: matches_ordering ( cx, success_ord_def_id, & [ * ordering] )
1573
- } )
1574
- } ) ;
1574
+ let success_lint_info = Self :: opt_ordering_defid ( cx, success_order_arg) . and_then (
1575
+ |success_ord_def_id| -> Option < OrdLintInfo > {
1576
+ SEARCH . iter ( ) . copied ( ) . find ( |( ordering, ..) | {
1577
+ Self :: matches_ordering ( cx, success_ord_def_id, & [ * ordering] )
1578
+ } )
1579
+ } ,
1580
+ ) ;
1575
1581
if Self :: matches_ordering ( cx, fail_ordering_def_id, & [ sym:: Release , sym:: AcqRel ] ) {
1576
1582
// If we don't know the success order is, use what we'd suggest
1577
1583
// if it were maximally permissive.
1578
1584
let suggested = success_lint_info. unwrap_or ( SEQ_CST ) . 2 ;
1579
1585
cx. struct_span_lint ( INVALID_ATOMIC_ORDERING , failure_order_arg. span , |diag| {
1580
- let msg = format ! (
1581
- "{}'s failure ordering may not be `Release` or `AcqRel`" ,
1582
- method,
1583
- ) ;
1584
- diag. build ( & msg)
1585
- . help ( & format ! ( "consider using {} instead" , suggested) )
1586
- . emit ( ) ;
1586
+ let msg =
1587
+ format ! ( "{}'s failure ordering may not be `Release` or `AcqRel`" , method, ) ;
1588
+ diag. build ( & msg) . help ( & format ! ( "consider using {} instead" , suggested) ) . emit ( ) ;
1587
1589
} ) ;
1588
- } else if let Some ( ( success_ord, bad_ords_given_success, suggested) ) = success_lint_info {
1590
+ } else if let Some ( ( success_ord, bad_ords_given_success, suggested) ) = success_lint_info
1591
+ {
1589
1592
if Self :: matches_ordering ( cx, fail_ordering_def_id, bad_ords_given_success) {
1590
1593
cx. struct_span_lint ( INVALID_ATOMIC_ORDERING , failure_order_arg. span , |diag| {
1591
1594
let msg = format ! (
0 commit comments