Skip to content

Commit 2b7d858

Browse files
committed
Add some comments related to place op typeck
1 parent 5cedf5d commit 2b7d858

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/librustc_typeck/check/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -3219,10 +3219,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
32193219
}
32203220
}
32213221

3222-
// When there is an auto mutable borrow, it is equivalent to `&mut expr`,
3223-
// thus `expr` is ought to be typechecked with needs = [`Needs::MutPlace`].
3224-
// However in many cases it might not be checked this way originally, e.g.
3225-
// the receiver of a method call. We need to fix them up.
3222+
// If there is an mutable auto-borrow, it is equivalent to `&mut <expr>`.
3223+
// In this case implicit use of `Deref` and `Index` within `<expr>` should
3224+
// instead be `DerefMut` and `IndexMut`, so fix those up.
32263225
if autoborrow_mut {
32273226
self.convert_place_derefs_to_mutable(expr);
32283227
}

src/librustc_typeck/check/place_op.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ use rustc_span::symbol::{sym, Ident};
1111
use rustc_span::Span;
1212

1313
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14+
/// Type-check `*oprnd_expr` with `oprnd_expr` type-checked already.
1415
pub(super) fn lookup_derefing(
1516
&self,
1617
expr: &hir::Expr<'_>,
17-
oprnd: &'tcx hir::Expr<'tcx>,
18+
oprnd_expr: &'tcx hir::Expr<'tcx>,
1819
oprnd_ty: Ty<'tcx>,
1920
) -> Option<Ty<'tcx>> {
2021
if let Some(mt) = oprnd_ty.builtin_deref(true) {
@@ -25,7 +26,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2526
let method = self.register_infer_ok_obligations(ok);
2627
if let ty::Ref(region, _, hir::Mutability::Not) = method.sig.inputs()[0].kind {
2728
self.apply_adjustments(
28-
oprnd,
29+
oprnd_expr,
2930
vec![Adjustment {
3031
kind: Adjust::Borrow(AutoBorrow::Ref(region, AutoBorrowMutability::Not)),
3132
target: method.sig.inputs()[0],
@@ -39,6 +40,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3940
Some(ty)
4041
}
4142

43+
/// Type-check `*base_expr[index_expr]` with `base_expr` and `index_expr` type-checked already.
4244
pub(super) fn lookup_indexing(
4345
&self,
4446
expr: &hir::Expr<'_>,

0 commit comments

Comments
 (0)