Skip to content

Commit

Permalink
rustc_typeck: rename LvaluePreference::PreferMutLvalue to `Needs::M…
Browse files Browse the repository at this point in the history
…utPlace`.
  • Loading branch information
eddyb committed Jan 28, 2018
1 parent 800166c commit 2c4a75b
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 82 deletions.
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/_match.rs
Expand Up @@ -15,7 +15,7 @@ use rustc::infer;
use rustc::infer::type_variable::TypeVariableOrigin;
use rustc::traits::ObligationCauseCode;
use rustc::ty::{self, Ty, TypeFoldable};
use check::{FnCtxt, Expectation, Diverges, LvaluePreference};
use check::{FnCtxt, Expectation, Diverges, Needs};
use check::coercion::CoerceMany;
use util::nodemap::FxHashMap;

Expand Down Expand Up @@ -584,7 +584,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
});
let discrim_ty;
if let Some(m) = contains_ref_bindings {
discrim_ty = self.check_expr_with_lvalue_pref(discrim, LvaluePreference::from_mutbl(m));
discrim_ty = self.check_expr_with_needs(discrim, Needs::maybe_mut_place(m));
} else {
// ...but otherwise we want to use any supertype of the
// discriminant. This is sort of a workaround, see note (*) in
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_typeck/check/autoderef.rs
Expand Up @@ -10,7 +10,7 @@

use astconv::AstConv;

use super::{FnCtxt, LvalueOp, LvaluePreference};
use super::{FnCtxt, LvalueOp, Needs};
use super::method::MethodCallee;

use rustc::infer::InferOk;
Expand Down Expand Up @@ -162,19 +162,19 @@ impl<'a, 'gcx, 'tcx> Autoderef<'a, 'gcx, 'tcx> {
}

/// Returns the adjustment steps.
pub fn adjust_steps(&self, pref: LvaluePreference)
pub fn adjust_steps(&self, needs: Needs)
-> Vec<Adjustment<'tcx>> {
self.fcx.register_infer_ok_obligations(self.adjust_steps_as_infer_ok(pref))
self.fcx.register_infer_ok_obligations(self.adjust_steps_as_infer_ok(needs))
}

pub fn adjust_steps_as_infer_ok(&self, pref: LvaluePreference)
pub fn adjust_steps_as_infer_ok(&self, needs: Needs)
-> InferOk<'tcx, Vec<Adjustment<'tcx>>> {
let mut obligations = vec![];
let targets = self.steps.iter().skip(1).map(|&(ty, _)| ty)
.chain(iter::once(self.cur_ty));
let steps: Vec<_> = self.steps.iter().map(|&(source, kind)| {
if let AutoderefKind::Overloaded = kind {
self.fcx.try_overloaded_deref(self.span, source, pref)
self.fcx.try_overloaded_deref(self.span, source, needs)
.and_then(|InferOk { value: method, obligations: o }| {
obligations.extend(o);
if let ty::TyRef(region, mt) = method.sig.output().sty {
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_typeck/check/callee.rs
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use super::{Expectation, FnCtxt, LvaluePreference, TupleArgumentsFlag};
use super::{Expectation, FnCtxt, Needs, TupleArgumentsFlag};
use super::autoderef::Autoderef;
use super::method::MethodCallee;

Expand Down Expand Up @@ -96,7 +96,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// If the callee is a bare function or a closure, then we're all set.
match adjusted_ty.sty {
ty::TyFnDef(..) | ty::TyFnPtr(_) => {
let adjustments = autoderef.adjust_steps(LvaluePreference::NoPreference);
let adjustments = autoderef.adjust_steps(Needs::None);
self.apply_adjustments(callee_expr, adjustments);
return Some(CallStep::Builtin(adjusted_ty));
}
Expand All @@ -113,7 +113,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
infer::FnCall,
&closure_ty)
.0;
let adjustments = autoderef.adjust_steps(LvaluePreference::NoPreference);
let adjustments = autoderef.adjust_steps(Needs::None);
self.record_deferred_call_resolution(def_id, DeferredCallResolution {
call_expr,
callee_expr,
Expand Down Expand Up @@ -143,7 +143,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}

self.try_overloaded_call_traits(call_expr, adjusted_ty).map(|(autoref, method)| {
let mut adjustments = autoderef.adjust_steps(LvaluePreference::NoPreference);
let mut adjustments = autoderef.adjust_steps(Needs::None);
adjustments.extend(autoref);
self.apply_adjustments(callee_expr, adjustments);
CallStep::Overloaded(method)
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_typeck/check/coercion.rs
Expand Up @@ -60,7 +60,7 @@
//! sort of a minor point so I've opted to leave it for later---after all
//! we may want to adjust precisely when coercions occur.

use check::{Diverges, FnCtxt, LvaluePreference};
use check::{Diverges, FnCtxt, Needs};

use rustc::hir;
use rustc::hir::def_id::DefId;
Expand Down Expand Up @@ -409,9 +409,9 @@ impl<'f, 'gcx, 'tcx> Coerce<'f, 'gcx, 'tcx> {
return success(vec![], ty, obligations);
}

let pref = LvaluePreference::from_mutbl(mt_b.mutbl);
let needs = Needs::maybe_mut_place(mt_b.mutbl);
let InferOk { value: mut adjustments, obligations: o }
= autoderef.adjust_steps_as_infer_ok(pref);
= autoderef.adjust_steps_as_infer_ok(needs);
obligations.extend(o);
obligations.extend(autoderef.into_obligations());

Expand Down
10 changes: 5 additions & 5 deletions src/librustc_typeck/check/method/confirm.rs
Expand Up @@ -11,7 +11,7 @@
use super::{probe, MethodCallee};

use astconv::AstConv;
use check::{FnCtxt, LvalueOp, callee, LvaluePreference, PreferMutLvalue};
use check::{FnCtxt, LvalueOp, callee, Needs};
use hir::def_id::DefId;
use rustc::ty::subst::Substs;
use rustc::traits;
Expand Down Expand Up @@ -155,7 +155,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
let (_, n) = autoderef.nth(pick.autoderefs).unwrap();
assert_eq!(n, pick.autoderefs);

let mut adjustments = autoderef.adjust_steps(LvaluePreference::NoPreference);
let mut adjustments = autoderef.adjust_steps(Needs::None);

let mut target = autoderef.unambiguous_final_ty();

Expand Down Expand Up @@ -449,10 +449,10 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
.adjustments_mut()
.remove(expr.hir_id);
if let Some(mut adjustments) = previous_adjustments {
let pref = LvaluePreference::PreferMutLvalue;
let needs = Needs::MutPlace;
for adjustment in &mut adjustments {
if let Adjust::Deref(Some(ref mut deref)) = adjustment.kind {
if let Some(ok) = self.try_overloaded_deref(expr.span, source, pref) {
if let Some(ok) = self.try_overloaded_deref(expr.span, source, needs) {
let method = self.register_infer_ok_obligations(ok);
if let ty::TyRef(region, mt) = method.sig.output().sty {
*deref = OverloadedDeref {
Expand Down Expand Up @@ -505,7 +505,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
.ty;

let method = self.try_overloaded_lvalue_op(
expr.span, base_ty, arg_tys, PreferMutLvalue, 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")
Expand Down

0 comments on commit 2c4a75b

Please sign in to comment.