rustc_typeck: rename LvalueOp to PlaceOp.
This commit is contained in:
parent
2c4a75bf09
commit
3f4a489f8f
3 changed files with 31 additions and 31 deletions
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
use astconv::AstConv;
|
||||
|
||||
use super::{FnCtxt, LvalueOp, Needs};
|
||||
use super::{FnCtxt, PlaceOp, Needs};
|
||||
use super::method::MethodCallee;
|
||||
|
||||
use rustc::infer::InferOk;
|
||||
|
|
@ -239,6 +239,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
base_ty: Ty<'tcx>,
|
||||
needs: Needs)
|
||||
-> Option<InferOk<'tcx, MethodCallee<'tcx>>> {
|
||||
self.try_overloaded_lvalue_op(span, base_ty, &[], needs, LvalueOp::Deref)
|
||||
self.try_overloaded_place_op(span, base_ty, &[], needs, PlaceOp::Deref)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
use super::{probe, MethodCallee};
|
||||
|
||||
use astconv::AstConv;
|
||||
use check::{FnCtxt, LvalueOp, callee, Needs};
|
||||
use check::{FnCtxt, PlaceOp, callee, Needs};
|
||||
use hir::def_id::DefId;
|
||||
use rustc::ty::subst::Substs;
|
||||
use rustc::traits;
|
||||
|
|
@ -438,7 +438,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
|
|||
debug!("convert_lvalue_derefs_to_mutable: i={} expr={:?}", i, expr);
|
||||
|
||||
// Fix up the autoderefs. Autorefs can only occur immediately preceding
|
||||
// overloaded lvalue ops, and will be fixed by them in order to get
|
||||
// overloaded place ops, and will be fixed by them in order to get
|
||||
// the correct region.
|
||||
let mut source = self.node_ty(expr.hir_id);
|
||||
// Do not mutate adjustments in place, but rather take them,
|
||||
|
|
@ -470,28 +470,28 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
|
|||
match expr.node {
|
||||
hir::ExprIndex(ref base_expr, ref index_expr) => {
|
||||
let index_expr_ty = self.node_ty(index_expr.hir_id);
|
||||
self.convert_lvalue_op_to_mutable(
|
||||
LvalueOp::Index, expr, base_expr, &[index_expr_ty]);
|
||||
self.convert_place_op_to_mutable(
|
||||
PlaceOp::Index, expr, base_expr, &[index_expr_ty]);
|
||||
}
|
||||
hir::ExprUnary(hir::UnDeref, ref base_expr) => {
|
||||
self.convert_lvalue_op_to_mutable(
|
||||
LvalueOp::Deref, expr, base_expr, &[]);
|
||||
self.convert_place_op_to_mutable(
|
||||
PlaceOp::Deref, expr, base_expr, &[]);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_lvalue_op_to_mutable(&self,
|
||||
op: LvalueOp,
|
||||
fn convert_place_op_to_mutable(&self,
|
||||
op: PlaceOp,
|
||||
expr: &hir::Expr,
|
||||
base_expr: &hir::Expr,
|
||||
arg_tys: &[Ty<'tcx>])
|
||||
{
|
||||
debug!("convert_lvalue_op_to_mutable({:?}, {:?}, {:?}, {:?})",
|
||||
debug!("convert_place_op_to_mutable({:?}, {:?}, {:?}, {:?})",
|
||||
op, expr, base_expr, arg_tys);
|
||||
if !self.tables.borrow().is_method_call(expr) {
|
||||
debug!("convert_lvalue_op_to_mutable - builtin, nothing to do");
|
||||
debug!("convert_place_op_to_mutable - builtin, nothing to do");
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -499,24 +499,24 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
|
|||
.map_or_else(|| self.node_ty(expr.hir_id), |adj| adj.target);
|
||||
let base_ty = self.resolve_type_vars_if_possible(&base_ty);
|
||||
|
||||
// Need to deref because overloaded lvalue ops take self by-reference.
|
||||
// Need to deref because overloaded place ops take self by-reference.
|
||||
let base_ty = base_ty.builtin_deref(false)
|
||||
.expect("lvalue op takes something that is not a ref")
|
||||
.expect("place op takes something that is not a ref")
|
||||
.ty;
|
||||
|
||||
let method = self.try_overloaded_lvalue_op(
|
||||
let method = self.try_overloaded_place_op(
|
||||
expr.span, base_ty, arg_tys, Needs::MutPlace, op);
|
||||
let method = match method {
|
||||
Some(ok) => self.register_infer_ok_obligations(ok),
|
||||
None => return self.tcx.sess.delay_span_bug(expr.span, "re-trying op failed")
|
||||
};
|
||||
debug!("convert_lvalue_op_to_mutable: method={:?}", method);
|
||||
debug!("convert_place_op_to_mutable: method={:?}", method);
|
||||
self.write_method_call(expr.hir_id, method);
|
||||
|
||||
let (region, mutbl) = if let ty::TyRef(r, mt) = method.sig.inputs()[0].sty {
|
||||
(r, mt.mutbl)
|
||||
} else {
|
||||
span_bug!(expr.span, "input to lvalue op is not a ref?");
|
||||
span_bug!(expr.span, "input to place op is not a ref?");
|
||||
};
|
||||
|
||||
// Convert the autoref in the base expr to mutable with the correct
|
||||
|
|
@ -529,7 +529,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
|
|||
let mut source = base_expr_ty;
|
||||
for adjustment in &mut adjustments[..] {
|
||||
if let Adjust::Borrow(AutoBorrow::Ref(..)) = adjustment.kind {
|
||||
debug!("convert_lvalue_op_to_mutable: converting autoref {:?}", adjustment);
|
||||
debug!("convert_place_op_to_mutable: converting autoref {:?}", adjustment);
|
||||
adjustment.kind = Adjust::Borrow(AutoBorrow::Ref(region, mutbl));
|
||||
adjustment.target = self.tcx.mk_ref(region, ty::TypeAndMut {
|
||||
ty: source,
|
||||
|
|
|
|||
|
|
@ -424,7 +424,7 @@ impl UnsafetyState {
|
|||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum LvalueOp {
|
||||
pub enum PlaceOp {
|
||||
Deref,
|
||||
Index
|
||||
}
|
||||
|
|
@ -2293,8 +2293,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
// type from the method signature.
|
||||
// If some lookup succeeded, install method in table
|
||||
let input_ty = self.next_ty_var(TypeVariableOrigin::AutoDeref(base_expr.span));
|
||||
let method = self.try_overloaded_lvalue_op(
|
||||
expr.span, self_ty, &[input_ty], needs, LvalueOp::Index);
|
||||
let method = self.try_overloaded_place_op(
|
||||
expr.span, self_ty, &[input_ty], needs, PlaceOp::Index);
|
||||
|
||||
let result = method.map(|ok| {
|
||||
debug!("try_index_step: success, using overloaded indexing");
|
||||
|
|
@ -2329,36 +2329,36 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
None
|
||||
}
|
||||
|
||||
fn resolve_lvalue_op(&self, op: LvalueOp, is_mut: bool) -> (Option<DefId>, Symbol) {
|
||||
fn resolve_place_op(&self, op: PlaceOp, is_mut: bool) -> (Option<DefId>, Symbol) {
|
||||
let (tr, name) = match (op, is_mut) {
|
||||
(LvalueOp::Deref, false) =>
|
||||
(PlaceOp::Deref, false) =>
|
||||
(self.tcx.lang_items().deref_trait(), "deref"),
|
||||
(LvalueOp::Deref, true) =>
|
||||
(PlaceOp::Deref, true) =>
|
||||
(self.tcx.lang_items().deref_mut_trait(), "deref_mut"),
|
||||
(LvalueOp::Index, false) =>
|
||||
(PlaceOp::Index, false) =>
|
||||
(self.tcx.lang_items().index_trait(), "index"),
|
||||
(LvalueOp::Index, true) =>
|
||||
(PlaceOp::Index, true) =>
|
||||
(self.tcx.lang_items().index_mut_trait(), "index_mut"),
|
||||
};
|
||||
(tr, Symbol::intern(name))
|
||||
}
|
||||
|
||||
fn try_overloaded_lvalue_op(&self,
|
||||
fn try_overloaded_place_op(&self,
|
||||
span: Span,
|
||||
base_ty: Ty<'tcx>,
|
||||
arg_tys: &[Ty<'tcx>],
|
||||
needs: Needs,
|
||||
op: LvalueOp)
|
||||
op: PlaceOp)
|
||||
-> Option<InferOk<'tcx, MethodCallee<'tcx>>>
|
||||
{
|
||||
debug!("try_overloaded_lvalue_op({:?},{:?},{:?},{:?})",
|
||||
debug!("try_overloaded_place_op({:?},{:?},{:?},{:?})",
|
||||
span,
|
||||
base_ty,
|
||||
needs,
|
||||
op);
|
||||
|
||||
// Try Mut first, if needed.
|
||||
let (mut_tr, mut_op) = self.resolve_lvalue_op(op, true);
|
||||
let (mut_tr, mut_op) = self.resolve_place_op(op, true);
|
||||
let method = match (needs, mut_tr) {
|
||||
(Needs::MutPlace, Some(trait_did)) => {
|
||||
self.lookup_method_in_trait(span, mut_op, trait_did, base_ty, Some(arg_tys))
|
||||
|
|
@ -2367,7 +2367,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
};
|
||||
|
||||
// Otherwise, fall back to the immutable version.
|
||||
let (imm_tr, imm_op) = self.resolve_lvalue_op(op, false);
|
||||
let (imm_tr, imm_op) = self.resolve_place_op(op, false);
|
||||
let method = match (method, imm_tr) {
|
||||
(None, Some(trait_did)) => {
|
||||
self.lookup_method_in_trait(span, imm_op, trait_did, base_ty, Some(arg_tys))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue