@@ -21,74 +21,74 @@ use std::iter;
21
21
22
22
use crate :: mem_categorization as mc;
23
23
24
- ///////////////////////////////////////////////////////////////////////////
25
- // The Delegate trait
26
-
27
24
/// This trait defines the callbacks you can expect to receive when
28
25
/// employing the ExprUseVisitor.
29
26
pub trait Delegate < ' tcx > {
30
- // The value found at `place` is moved, depending
31
- // on `mode`. Where `diag_expr_id` is the id used for diagnostics for `place`.
32
- //
33
- // Use of a `Copy` type in a ByValue context is considered a use
34
- // by `ImmBorrow` and `borrow` is called instead. This is because
35
- // a shared borrow is the "minimum access" that would be needed
36
- // to perform a copy.
37
- //
38
- //
39
- // The parameter `diag_expr_id` indicates the HIR id that ought to be used for
40
- // diagnostics. Around pattern matching such as `let pat = expr`, the diagnostic
41
- // id will be the id of the expression `expr` but the place itself will have
42
- // the id of the binding in the pattern `pat`.
27
+ /// The value found at `place` is moved, depending
28
+ /// on `mode`. Where `diag_expr_id` is the id used for diagnostics for `place`.
29
+ ///
30
+ /// Use of a `Copy` type in a ByValue context is considered a use
31
+ /// by `ImmBorrow` and `borrow` is called instead. This is because
32
+ /// a shared borrow is the "minimum access" that would be needed
33
+ /// to perform a copy.
34
+ ///
35
+ ///
36
+ /// The parameter `diag_expr_id` indicates the HIR id that ought to be used for
37
+ /// diagnostics. Around pattern matching such as `let pat = expr`, the diagnostic
38
+ /// id will be the id of the expression `expr` but the place itself will have
39
+ /// the id of the binding in the pattern `pat`.
43
40
fn consume ( & mut self , place_with_id : & PlaceWithHirId < ' tcx > , diag_expr_id : hir:: HirId ) ;
44
41
45
- // The value found at `place` is being borrowed with kind `bk`.
46
- // `diag_expr_id` is the id used for diagnostics (see `consume` for more details).
42
+ /// The value found at `place` is being borrowed with kind `bk`.
43
+ /// `diag_expr_id` is the id used for diagnostics (see `consume` for more details).
47
44
fn borrow (
48
45
& mut self ,
49
46
place_with_id : & PlaceWithHirId < ' tcx > ,
50
47
diag_expr_id : hir:: HirId ,
51
48
bk : ty:: BorrowKind ,
52
49
) ;
53
50
54
- // The path at `assignee_place` is being assigned to.
55
- // `diag_expr_id` is the id used for diagnostics (see `consume` for more details).
51
+ /// The path at `assignee_place` is being assigned to.
52
+ /// `diag_expr_id` is the id used for diagnostics (see `consume` for more details).
56
53
fn mutate ( & mut self , assignee_place : & PlaceWithHirId < ' tcx > , diag_expr_id : hir:: HirId ) ;
57
54
58
- // The `place` should be a fake read because of specified `cause`.
55
+ /// The `place` should be a fake read because of specified `cause`.
59
56
fn fake_read ( & mut self , place : Place < ' tcx > , cause : FakeReadCause , diag_expr_id : hir:: HirId ) ;
60
57
}
61
58
62
59
#[ derive( Copy , Clone , PartialEq , Debug ) ]
63
60
enum ConsumeMode {
64
- Copy , // reference to x where x has a type that copies
65
- Move , // reference to x where x has a type that moves
61
+ /// reference to x where x has a type that copies
62
+ Copy ,
63
+ /// reference to x where x has a type that moves
64
+ Move ,
66
65
}
67
66
68
67
#[ derive( Copy , Clone , PartialEq , Debug ) ]
69
68
pub enum MutateMode {
70
69
Init ,
71
- JustWrite , // x = y
72
- WriteAndRead , // x += y
70
+ /// Example: `x = y`
71
+ JustWrite ,
72
+ /// Example: `x += y`
73
+ WriteAndRead ,
73
74
}
74
75
75
- ///////////////////////////////////////////////////////////////////////////
76
- // The ExprUseVisitor type
77
- //
78
- // This is the code that actually walks the tree.
76
+ /// The ExprUseVisitor type
77
+ ///
78
+ /// This is the code that actually walks the tree.
79
79
pub struct ExprUseVisitor < ' a , ' tcx > {
80
80
mc : mc:: MemCategorizationContext < ' a , ' tcx > ,
81
81
body_owner : LocalDefId ,
82
82
delegate : & ' a mut dyn Delegate < ' tcx > ,
83
83
}
84
84
85
- // If the MC results in an error, it's because the type check
86
- // failed (or will fail, when the error is uncovered and reported
87
- // during writeback). In this case, we just ignore this part of the
88
- // code.
89
- //
90
- // Note that this macro appears similar to try!(), but, unlike try!(),
91
- // it does not propagate the error.
85
+ /// If the MC results in an error, it's because the type check
86
+ /// failed (or will fail, when the error is uncovered and reported
87
+ /// during writeback). In this case, we just ignore this part of the
88
+ /// code.
89
+ ///
90
+ /// Note that this macro appears similar to try!(), but, unlike try!(),
91
+ /// it does not propagate the error.
92
92
macro_rules! return_if_err {
93
93
( $inp: expr) => {
94
94
match $inp {
@@ -537,9 +537,9 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
537
537
self . walk_expr ( with_expr) ;
538
538
}
539
539
540
- // Invoke the appropriate delegate calls for anything that gets
541
- // consumed or borrowed as part of the automatic adjustment
542
- // process.
540
+ /// Invoke the appropriate delegate calls for anything that gets
541
+ /// consumed or borrowed as part of the automatic adjustment
542
+ /// process.
543
543
fn walk_adjustment ( & mut self , expr : & hir:: Expr < ' _ > ) {
544
544
let adjustments = self . mc . typeck_results . expr_adjustments ( expr) ;
545
545
let mut place_with_id = return_if_err ! ( self . mc. cat_expr_unadjusted( expr) ) ;
0 commit comments