@@ -7,7 +7,7 @@ use rustc_ast::walk_list;
7
7
use rustc_data_structures:: fx:: FxHashMap ;
8
8
use rustc_hir as hir;
9
9
use 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 } ;
11
11
use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
12
12
use rustc_middle:: hir:: map:: Map ;
13
13
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
@@ -132,6 +132,10 @@ impl<'tcx> LateLintPass<'tcx> for Author {
132
132
if !has_attr ( cx, stmt. hir_id ) {
133
133
return ;
134
134
}
135
+ match stmt. kind {
136
+ StmtKind :: Expr ( e) | StmtKind :: Semi ( e) if has_attr ( cx, e. hir_id ) => return ,
137
+ _ => { } ,
138
+ }
135
139
prelude ( ) ;
136
140
PrintVisitor :: new ( "stmt" ) . visit_stmt ( stmt) ;
137
141
done ( ) ;
@@ -316,11 +320,13 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
316
320
self . current = cast_pat;
317
321
self . visit_expr ( expr) ;
318
322
} ,
319
- ExprKind :: Loop ( body, _, desugaring , _) => {
323
+ ExprKind :: Loop ( body, _, des , _) => {
320
324
let body_pat = self . next ( "body" ) ;
321
- let des = loop_desugaring_name ( desugaring) ;
322
325
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
+ ) ;
324
330
self . current = body_pat;
325
331
self . visit_block ( body) ;
326
332
} ,
@@ -343,11 +349,13 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
343
349
self . current = then_pat;
344
350
self . visit_expr ( then) ;
345
351
} ,
346
- ExprKind :: Match ( expr, arms, desugaring) => {
347
- let des = desugaring_name ( desugaring) ;
352
+ ExprKind :: Match ( expr, arms, des) => {
348
353
let expr_pat = self . next ( "expr" ) ;
349
354
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
+ ) ;
351
359
self . current = expr_pat;
352
360
self . visit_expr ( expr) ;
353
361
println ! ( " if {}.len() == {};" , arms_pat, arms. len( ) ) ;
@@ -536,14 +544,19 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
536
544
}
537
545
538
546
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) ;
541
547
println ! ( " if {}.stmts.len() == {};" , self . current, block. stmts. len( ) ) ;
542
- let current = self . current . clone ( ) ;
548
+ let block_name = self . current . clone ( ) ;
543
549
for ( i, stmt) in block. stmts . iter ( ) . enumerate ( ) {
544
- self . current = format ! ( "{}.stmts[{}]" , current , i) ;
550
+ self . current = format ! ( "{}.stmts[{}]" , block_name , i) ;
545
551
self . visit_stmt ( stmt) ;
546
552
}
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
+ }
547
560
}
548
561
549
562
#[ allow( clippy:: too_many_lines) ]
@@ -553,12 +566,7 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
553
566
match pat. kind {
554
567
PatKind :: Wild => println ! ( "Wild = {};" , current) ,
555
568
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) ;
562
570
let name_pat = self . next ( "name" ) ;
563
571
if let Some ( sub) = * sub {
564
572
let sub_pat = self . next ( "sub" ) ;
@@ -723,33 +731,6 @@ fn has_attr(cx: &LateContext<'_>, hir_id: hir::HirId) -> bool {
723
731
get_attr ( cx. sess ( ) , attrs, "author" ) . count ( ) > 0
724
732
}
725
733
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
-
753
734
fn print_path ( path : & QPath < ' _ > , first : & mut bool ) {
754
735
match * path {
755
736
QPath :: Resolved ( _, path) => {
0 commit comments