@@ -1346,12 +1346,13 @@ impl AttributeExt for Attribute {
13461346 }
13471347 }
13481348
1349- #[ inline]
1350- fn style ( & self ) -> AttrStyle {
1351- match & self {
1352- Attribute :: Unparsed ( u) => u. style ,
1353- Attribute :: Parsed ( AttributeKind :: DocComment { style, .. } ) => * style,
1354- _ => panic ! ( ) ,
1349+ fn doc_resolution_scope ( & self ) -> Option < AttrStyle > {
1350+ match self {
1351+ Attribute :: Parsed ( AttributeKind :: DocComment { style, .. } ) => Some ( * style) ,
1352+ Attribute :: Unparsed ( attr) if self . has_name ( sym:: doc) && self . value_str ( ) . is_some ( ) => {
1353+ Some ( attr. style )
1354+ }
1355+ _ => None ,
13551356 }
13561357 }
13571358}
@@ -1442,11 +1443,6 @@ impl Attribute {
14421443 pub fn doc_str_and_comment_kind ( & self ) -> Option < ( Symbol , CommentKind ) > {
14431444 AttributeExt :: doc_str_and_comment_kind ( self )
14441445 }
1445-
1446- #[ inline]
1447- pub fn style ( & self ) -> AttrStyle {
1448- AttributeExt :: style ( self )
1449- }
14501446}
14511447
14521448/// Attributes owned by a HIR owner.
@@ -2286,16 +2282,9 @@ pub struct Expr<'hir> {
22862282}
22872283
22882284impl Expr < ' _ > {
2289- pub fn precedence (
2290- & self ,
2291- for_each_attr : & dyn Fn ( HirId , & mut dyn FnMut ( & Attribute ) ) ,
2292- ) -> ExprPrecedence {
2285+ pub fn precedence ( & self , has_attr : & dyn Fn ( HirId ) -> bool ) -> ExprPrecedence {
22932286 let prefix_attrs_precedence = || -> ExprPrecedence {
2294- let mut has_outer_attr = false ;
2295- for_each_attr ( self . hir_id , & mut |attr : & Attribute | {
2296- has_outer_attr |= matches ! ( attr. style( ) , AttrStyle :: Outer )
2297- } ) ;
2298- if has_outer_attr { ExprPrecedence :: Prefix } else { ExprPrecedence :: Unambiguous }
2287+ if has_attr ( self . hir_id ) { ExprPrecedence :: Prefix } else { ExprPrecedence :: Unambiguous }
22992288 } ;
23002289
23012290 match & self . kind {
@@ -2351,7 +2340,7 @@ impl Expr<'_> {
23512340 | ExprKind :: Use ( ..)
23522341 | ExprKind :: Err ( _) => prefix_attrs_precedence ( ) ,
23532342
2354- ExprKind :: DropTemps ( expr, ..) => expr. precedence ( for_each_attr ) ,
2343+ ExprKind :: DropTemps ( expr, ..) => expr. precedence ( has_attr ) ,
23552344 }
23562345 }
23572346
0 commit comments