diff options
| author | Gary Guo <gary@garyguo.net> | 2020-06-16 22:48:35 +0100 |
|---|---|---|
| committer | Gary Guo <gary@garyguo.net> | 2020-06-16 22:50:21 +0100 |
| commit | 2b7d8588668bc79a1855a2c335572a1ac8ceaf34 (patch) | |
| tree | e99e944f435b0bb74bf8d497eb38aa6686f8b44a | |
| parent | 5cedf5dfba1c83f2fe3e2fcb7acbc20c6e34604a (diff) | |
| download | rust-2b7d8588668bc79a1855a2c335572a1ac8ceaf34.tar.gz rust-2b7d8588668bc79a1855a2c335572a1ac8ceaf34.zip | |
Add some comments related to place op typeck
| -rw-r--r-- | src/librustc_typeck/check/mod.rs | 7 | ||||
| -rw-r--r-- | src/librustc_typeck/check/place_op.rs | 6 |
2 files changed, 7 insertions, 6 deletions
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index b1d32213b72..fa7dd2156ed 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3219,10 +3219,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } - // When there is an auto mutable borrow, it is equivalent to `&mut expr`, - // thus `expr` is ought to be typechecked with needs = [`Needs::MutPlace`]. - // However in many cases it might not be checked this way originally, e.g. - // the receiver of a method call. We need to fix them up. + // If there is an mutable auto-borrow, it is equivalent to `&mut <expr>`. + // In this case implicit use of `Deref` and `Index` within `<expr>` should + // instead be `DerefMut` and `IndexMut`, so fix those up. if autoborrow_mut { self.convert_place_derefs_to_mutable(expr); } diff --git a/src/librustc_typeck/check/place_op.rs b/src/librustc_typeck/check/place_op.rs index ce4b6f8baf9..d1c22cd1ac0 100644 --- a/src/librustc_typeck/check/place_op.rs +++ b/src/librustc_typeck/check/place_op.rs @@ -11,10 +11,11 @@ use rustc_span::symbol::{sym, Ident}; use rustc_span::Span; impl<'a, 'tcx> FnCtxt<'a, 'tcx> { + /// Type-check `*oprnd_expr` with `oprnd_expr` type-checked already. pub(super) fn lookup_derefing( &self, expr: &hir::Expr<'_>, - oprnd: &'tcx hir::Expr<'tcx>, + oprnd_expr: &'tcx hir::Expr<'tcx>, oprnd_ty: Ty<'tcx>, ) -> Option<Ty<'tcx>> { if let Some(mt) = oprnd_ty.builtin_deref(true) { @@ -25,7 +26,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let method = self.register_infer_ok_obligations(ok); if let ty::Ref(region, _, hir::Mutability::Not) = method.sig.inputs()[0].kind { self.apply_adjustments( - oprnd, + oprnd_expr, vec![Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(region, AutoBorrowMutability::Not)), target: method.sig.inputs()[0], @@ -39,6 +40,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Some(ty) } + /// Type-check `*base_expr[index_expr]` with `base_expr` and `index_expr` type-checked already. pub(super) fn lookup_indexing( &self, expr: &hir::Expr<'_>, |
