Skip to content

Commit 42b8b13

Browse files
committed
Add some code comments
1 parent a68db7e commit 42b8b13

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

compiler/rustc_ast/src/ast.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1760,9 +1760,13 @@ pub enum CaptureBy {
17601760
/// The span of the `move` keyword.
17611761
move_kw: Span,
17621762
},
1763-
/// `move` keyword was not specified.
1763+
/// `move` or `use` keywords were not specified.
17641764
Ref,
17651765
/// `use |x| y + x`.
1766+
///
1767+
/// Note that if you have a regular closure like `|| x.use`, this will *not* result
1768+
/// in a `Use` capture. Instead, the `ExprUseVisitor` will look at the type
1769+
/// of `x` and treat `x.use` as either a copy/clone/move as appropriate.
17661770
Use {
17671771
/// The span of the `use` keyword.
17681772
use_kw: Span,

compiler/rustc_hir_typeck/src/expr_use_visitor.rs

+6
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,12 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
327327
pub fn consume_clone_or_copy(&self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: HirId) {
328328
debug!("delegate_consume_or_clone(place_with_id={:?})", place_with_id);
329329

330+
// `x.use` will do one of the following
331+
// * if it implements `Copy`, it will be a copy
332+
// * if it implements `UseCloned`, it will be a call to `clone`
333+
// * otherwise, it is a move
334+
//
335+
// we do a conservative approximation of this, treating it as a move unless we know that it implements copy or `UseCloned`
330336
if self.cx.type_is_copy_modulo_regions(place_with_id.place.ty()) {
331337
self.delegate.borrow_mut().copy(place_with_id, diag_expr_id);
332338
} else if self.cx.type_is_use_cloned_modulo_regions(place_with_id.place.ty()) {

0 commit comments

Comments
 (0)