1
Fork 0

Add some code comments

This commit is contained in:
Santiago Pastorino 2025-03-06 16:57:51 -03:00
parent a68db7e3a8
commit 42b8b13b22
No known key found for this signature in database
GPG key ID: 8131A24E0C79EFAF
2 changed files with 11 additions and 1 deletions

View file

@ -1760,9 +1760,13 @@ pub enum CaptureBy {
/// The span of the `move` keyword. /// The span of the `move` keyword.
move_kw: Span, move_kw: Span,
}, },
/// `move` keyword was not specified. /// `move` or `use` keywords were not specified.
Ref, Ref,
/// `use |x| y + x`. /// `use |x| y + x`.
///
/// Note that if you have a regular closure like `|| x.use`, this will *not* result
/// in a `Use` capture. Instead, the `ExprUseVisitor` will look at the type
/// of `x` and treat `x.use` as either a copy/clone/move as appropriate.
Use { Use {
/// The span of the `use` keyword. /// The span of the `use` keyword.
use_kw: Span, use_kw: Span,

View file

@ -327,6 +327,12 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
pub fn consume_clone_or_copy(&self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: HirId) { pub fn consume_clone_or_copy(&self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: HirId) {
debug!("delegate_consume_or_clone(place_with_id={:?})", place_with_id); debug!("delegate_consume_or_clone(place_with_id={:?})", place_with_id);
// `x.use` will do one of the following
// * if it implements `Copy`, it will be a copy
// * if it implements `UseCloned`, it will be a call to `clone`
// * otherwise, it is a move
//
// we do a conservative approximation of this, treating it as a move unless we know that it implements copy or `UseCloned`
if self.cx.type_is_copy_modulo_regions(place_with_id.place.ty()) { if self.cx.type_is_copy_modulo_regions(place_with_id.place.ty()) {
self.delegate.borrow_mut().copy(place_with_id, diag_expr_id); self.delegate.borrow_mut().copy(place_with_id, diag_expr_id);
} else if self.cx.type_is_use_cloned_modulo_regions(place_with_id.place.ty()) { } else if self.cx.type_is_use_cloned_modulo_regions(place_with_id.place.ty()) {