@@ -7,7 +7,7 @@ use rustc_ast::walk_list;
77use rustc_data_structures:: fx:: FxHashMap ;
88use rustc_hir as hir;
99use rustc_hir:: intravisit:: { NestedVisitorMap , Visitor } ;
10- use rustc_hir:: { BindingAnnotation , Block , Expr , ExprKind , Pat , PatKind , QPath , Stmt , StmtKind , TyKind } ;
10+ use rustc_hir:: { Block , Expr , ExprKind , Pat , PatKind , QPath , Stmt , StmtKind , TyKind } ;
1111use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
1212use rustc_middle:: hir:: map:: Map ;
1313use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
@@ -132,6 +132,10 @@ impl<'tcx> LateLintPass<'tcx> for Author {
132132 if !has_attr ( cx, stmt. hir_id ) {
133133 return ;
134134 }
135+ match stmt. kind {
136+ StmtKind :: Expr ( e) | StmtKind :: Semi ( e) if has_attr ( cx, e. hir_id ) => return ,
137+ _ => { } ,
138+ }
135139 prelude ( ) ;
136140 PrintVisitor :: new ( "stmt" ) . visit_stmt ( stmt) ;
137141 done ( ) ;
@@ -316,11 +320,13 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
316320 self . current = cast_pat;
317321 self . visit_expr ( expr) ;
318322 } ,
319- ExprKind :: Loop ( body, _, desugaring , _) => {
323+ ExprKind :: Loop ( body, _, des , _) => {
320324 let body_pat = self . next ( "body" ) ;
321- let des = loop_desugaring_name ( desugaring) ;
322325 let label_pat = self . next ( "label" ) ;
323- println ! ( "Loop(ref {}, ref {}, {}) = {};" , body_pat, label_pat, des, current) ;
326+ println ! (
327+ "Loop(ref {}, ref {}, LoopSource::{:?}) = {};" ,
328+ body_pat, label_pat, des, current
329+ ) ;
324330 self . current = body_pat;
325331 self . visit_block ( body) ;
326332 } ,
@@ -343,11 +349,13 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
343349 self . current = then_pat;
344350 self . visit_expr ( then) ;
345351 } ,
346- ExprKind :: Match ( expr, arms, desugaring) => {
347- let des = desugaring_name ( desugaring) ;
352+ ExprKind :: Match ( expr, arms, des) => {
348353 let expr_pat = self . next ( "expr" ) ;
349354 let arms_pat = self . next ( "arms" ) ;
350- println ! ( "Match(ref {}, ref {}, {}) = {};" , expr_pat, arms_pat, des, current) ;
355+ println ! (
356+ "Match(ref {}, ref {}, MatchSource::{:?}) = {};" ,
357+ expr_pat, arms_pat, des, current
358+ ) ;
351359 self . current = expr_pat;
352360 self . visit_expr ( expr) ;
353361 println ! ( " if {}.len() == {};" , arms_pat, arms. len( ) ) ;
@@ -536,14 +544,19 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
536544 }
537545
538546 fn visit_block ( & mut self , block : & Block < ' _ > ) {
539- let trailing_pat = self . next ( "trailing_expr" ) ;
540- println ! ( " if let Some({}) = &{}.expr;" , trailing_pat, self . current) ;
541547 println ! ( " if {}.stmts.len() == {};" , self . current, block. stmts. len( ) ) ;
542- let current = self . current . clone ( ) ;
548+ let block_name = self . current . clone ( ) ;
543549 for ( i, stmt) in block. stmts . iter ( ) . enumerate ( ) {
544- self . current = format ! ( "{}.stmts[{}]" , current , i) ;
550+ self . current = format ! ( "{}.stmts[{}]" , block_name , i) ;
545551 self . visit_stmt ( stmt) ;
546552 }
553+ if let Some ( expr) = block. expr {
554+ self . current = self . next ( "trailing_expr" ) ;
555+ println ! ( " if let Some({}) = &{}.expr;" , self . current, block_name) ;
556+ self . visit_expr ( expr) ;
557+ } else {
558+ println ! ( " if {}.expr.is_none();" , block_name) ;
559+ }
547560 }
548561
549562 #[ allow( clippy:: too_many_lines) ]
@@ -553,12 +566,7 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
553566 match pat. kind {
554567 PatKind :: Wild => println ! ( "Wild = {};" , current) ,
555568 PatKind :: Binding ( anno, .., ident, ref sub) => {
556- let anno_pat = match anno {
557- BindingAnnotation :: Unannotated => "BindingAnnotation::Unannotated" ,
558- BindingAnnotation :: Mutable => "BindingAnnotation::Mutable" ,
559- BindingAnnotation :: Ref => "BindingAnnotation::Ref" ,
560- BindingAnnotation :: RefMut => "BindingAnnotation::RefMut" ,
561- } ;
569+ let anno_pat = & format ! ( "BindingAnnotation::{:?}" , anno) ;
562570 let name_pat = self . next ( "name" ) ;
563571 if let Some ( sub) = * sub {
564572 let sub_pat = self . next ( "sub" ) ;
@@ -723,33 +731,6 @@ fn has_attr(cx: &LateContext<'_>, hir_id: hir::HirId) -> bool {
723731 get_attr ( cx. sess ( ) , attrs, "author" ) . count ( ) > 0
724732}
725733
726- #[ must_use]
727- fn desugaring_name ( des : hir:: MatchSource ) -> String {
728- match des {
729- hir:: MatchSource :: ForLoopDesugar => "MatchSource::ForLoopDesugar" . to_string ( ) ,
730- hir:: MatchSource :: TryDesugar => "MatchSource::TryDesugar" . to_string ( ) ,
731- hir:: MatchSource :: WhileDesugar => "MatchSource::WhileDesugar" . to_string ( ) ,
732- hir:: MatchSource :: WhileLetDesugar => "MatchSource::WhileLetDesugar" . to_string ( ) ,
733- hir:: MatchSource :: Normal => "MatchSource::Normal" . to_string ( ) ,
734- hir:: MatchSource :: IfLetDesugar { contains_else_clause } => format ! (
735- "MatchSource::IfLetDesugar {{ contains_else_clause: {} }}" ,
736- contains_else_clause
737- ) ,
738- hir:: MatchSource :: IfLetGuardDesugar => "MatchSource::IfLetGuardDesugar" . to_string ( ) ,
739- hir:: MatchSource :: AwaitDesugar => "MatchSource::AwaitDesugar" . to_string ( ) ,
740- }
741- }
742-
743- #[ must_use]
744- fn loop_desugaring_name ( des : hir:: LoopSource ) -> & ' static str {
745- match des {
746- hir:: LoopSource :: ForLoop => "LoopSource::ForLoop" ,
747- hir:: LoopSource :: Loop => "LoopSource::Loop" ,
748- hir:: LoopSource :: While => "LoopSource::While" ,
749- hir:: LoopSource :: WhileLet => "LoopSource::WhileLet" ,
750- }
751- }
752-
753734fn print_path ( path : & QPath < ' _ > , first : & mut bool ) {
754735 match * path {
755736 QPath :: Resolved ( _, path) => {
0 commit comments