);
// Build a tuple (U0..Un) of the final upvar types U0..Un
- // and unify the upvar tupe type in the closure with it:
+ // and unify the upvar tuple type in the closure with it:
let final_tupled_upvars_type = self.tcx.mk_tup(final_upvar_tys.iter());
self.demand_suptype(span, substs.tupled_upvars_ty(), final_tupled_upvars_type);
// Returns a list of `Ty`s for each upvar.
fn final_upvar_tys(&self, closure_id: DefId) -> Vec<Ty<'tcx>> {
- // Presently an unboxed closure type cannot "escape" out of a
- // function, so we will only encounter ones that originated in the
- // local crate or were inlined into it along with some function.
- // This may change if abstract return types of some sort are
- // implemented.
self.typeck_results
.borrow()
.closure_min_captures_flattened(closure_id)
/// let s: String; // hir_id_s
/// let mut p: Point; // his_id_p
/// let c = || {
- /// println!("{}", s); // L1
+ /// println!("{s}"); // L1
/// p.x += 10; // L2
- /// println!("{}" , p.y) // L3
- /// println!("{}", p) // L4
+ /// println!("{}" , p.y); // L3
+ /// println!("{p}"); // L4
/// drop(s); // L5
/// };
/// ```
base => bug!("Expected upvar, found={:?}", base),
};
- let min_cap_list = match root_var_min_capture_list.get_mut(&var_hir_id) {
- None => {
- let mutability = self.determine_capture_mutability(&typeck_results, &place);
- let min_cap_list = vec![ty::CapturedPlace {
- place,
- info: capture_info,
- mutability,
- region: None,
- }];
- root_var_min_capture_list.insert(var_hir_id, min_cap_list);
- continue;
- }
- Some(min_cap_list) => min_cap_list,
+ let Some(min_cap_list) = root_var_min_capture_list.get_mut(&var_hir_id) else {
+ let mutability = self.determine_capture_mutability(&typeck_results, &place);
+ let min_cap_list = vec![ty::CapturedPlace {
+ place,
+ info: capture_info,
+ mutability,
+ region: None,
+ }];
+ root_var_min_capture_list.insert(var_hir_id, min_cap_list);
+ continue;
};
// Go through each entry in the current list of min_captures
// capture information.
//
// - if descendant is found, remove it from the list, and update the current place's
- // capture information to account for the descendants's capture kind.
+ // capture information to account for the descendant's capture kind.
//
// We can never be in a case where the list contains both an ancestor and a descendant
// Also there can only be ancestor but in case of descendants there might be
// Now that we have the minimized list of captures, sort the captures by field id.
// This causes the closure to capture the upvars in the same order as the fields are
// declared which is also the drop order. Thus, in situations where we capture all the
- // fields of some type, the obserable drop order will remain the same as it previously
+ // fields of some type, the observable drop order will remain the same as it previously
// was even though we're dropping each capture individually.
// See https://github.com/rust-lang/project-rfc-2229/issues/42 and
// `src/test/ui/closures/2229_closure_analysis/preserve_field_drop_order.rs`.
// Add a label pointing to where a captured variable affected by drop order
// is dropped
if lint_note.reason.drop_order {
- let drop_location_span = drop_location_span(self.tcx, &closure_hir_id);
+ let drop_location_span = drop_location_span(self.tcx, closure_hir_id);
match &lint_note.captures_info {
UpvarMigrationInfo::CapturingPrecise { var_name: captured_name, .. } => {
// represents the case of the path being completely captured by the variable.
//
// eg. If `a.b` is captured and we are processing `a.b`, then we can't have the closure also
- // capture `a.b.c`, because that voilates min capture.
+ // capture `a.b.c`, because that violates min capture.
let is_completely_captured = captured_by_move_projs.iter().any(|projs| projs.is_empty());
assert!(!is_completely_captured || (captured_by_move_projs.len() == 1));
// Observations:
// - `captured_by_move_projs` is not empty. Therefore we can call
// `captured_by_move_projs.first().unwrap()` safely.
- // - All entries in `captured_by_move_projs` have atleast one projection.
+ // - All entries in `captured_by_move_projs` have at least one projection.
// Therefore we can call `captured_by_move_projs.first().unwrap().first().unwrap()` safely.
// We don't capture derefs in case of move captures, which would have be applied to
ty::RawPtr(..) => unreachable!(),
ty::Adt(def, substs) => {
- // Multi-varaint enums are captured in entirety,
+ // Multi-variant enums are captured in entirety,
// which would've been handled in the case of single empty slice in `captured_by_move_projs`.
- assert_eq!(def.variants.len(), 1);
+ assert_eq!(def.variants().len(), 1);
// Only Field projections can be applied to a non-box Adt.
assert!(
ProjectionKind::Field(..)
))
);
- def.variants.get(VariantIdx::new(0)).unwrap().fields.iter().enumerate().any(
+ def.variants().get(VariantIdx::new(0)).unwrap().fields.iter().enumerate().any(
|(i, field)| {
let paths_using_field = captured_by_move_projs
.iter()
)
}
- ty::Tuple(..) => {
+ ty::Tuple(fields) => {
// Only Field projections can be applied to a tuple.
assert!(
captured_by_move_projs.iter().all(|projs| matches!(
))
);
- base_path_ty.tuple_fields().enumerate().any(|(i, element_ty)| {
+ fields.iter().enumerate().any(|(i, element_ty)| {
let paths_using_field = captured_by_move_projs
.iter()
.filter_map(|projs| {
// We don't capture derefs of raw ptrs
ty::RawPtr(_) => unreachable!(),
- // Derefencing a mut-ref allows us to mut the Place if we don't deref
+ // Dereferencing a mut-ref allows us to mut the Place if we don't deref
// an immut-ref after on top of this.
ty::Ref(.., hir::Mutability::Mut) => is_mutbl = hir::Mutability::Mut,
// Return true for fields of packed structs, unless those fields have alignment 1.
match p.kind {
ProjectionKind::Field(..) => match ty.kind() {
- ty::Adt(def, _) if def.repr.packed() => {
+ ty::Adt(def, _) if def.repr().packed() => {
// We erase regions here because they cannot be hashed
match tcx.layout_of(param_env.and(tcx.erase_regions(p.ty))) {
Ok(layout) if layout.align.abi.bytes() == 1 => {
}
/// Returns the Span of where the value with the provided HirId would be dropped
-fn drop_location_span<'tcx>(tcx: TyCtxt<'tcx>, hir_id: &hir::HirId) -> Span {
- let owner_id = tcx.hir().get_enclosing_scope(*hir_id).unwrap();
+fn drop_location_span<'tcx>(tcx: TyCtxt<'tcx>, hir_id: hir::HirId) -> Span {
+ let owner_id = tcx.hir().get_enclosing_scope(hir_id).unwrap();
let owner_node = tcx.hir().get(owner_id);
let owner_span = match owner_node {
}
if proj.ty.is_union() {
- // Don't capture preicse fields of a union.
+ // Don't capture precise fields of a union.
truncate_place_to_len_and_update_capture_kind(&mut place, &mut curr_mode, i + 1);
break;
}
/// Truncate projections so that following rules are obeyed by the captured `place`:
/// - No Index projections are captured, since arrays are captured completely.
/// - No unsafe block is required to capture `place`
-/// Returns the truncated place and updated cature mode.
+/// Returns the truncated place and updated capture mode.
fn restrict_capture_precision<'tcx>(
place: Place<'tcx>,
curr_mode: ty::UpvarCapture,
/// It is the caller's duty to figure out which path_expr_id to use.
///
/// If both the CaptureKind and Expression are considered to be equivalent,
-/// then `CaptureInfo` A is preferred. This can be useful in cases where we want to priortize
+/// then `CaptureInfo` A is preferred. This can be useful in cases where we want to prioritize
/// expressions reported back to the user as part of diagnostics based on which appears earlier
/// in the closure. This can be achieved simply by calling
/// `determine_capture_info(existing_info, current_info)`. This works out because the
}
}
-/// Reduces the precision of the captured place when the precision doesn't yeild any benefit from
-/// borrow checking prespective, allowing us to save us on the size of the capture.
+/// Reduces the precision of the captured place when the precision doesn't yield any benefit from
+/// borrow checking perspective, allowing us to save us on the size of the capture.
///
///
/// Fields that are read through a shared reference will always be read via a shared ref or a copy,