Skip to content

Commit 800166c

Browse files
committed
rustc: remove LvaluePreference argument from Ty::builtin_deref.
1 parent 87990a1 commit 800166c

File tree

15 files changed

+45
-55
lines changed

15 files changed

+45
-55
lines changed

src/librustc/middle/mem_categorization.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
517517
// a bind-by-ref means that the base_ty will be the type of the ident itself,
518518
// but what we want here is the type of the underlying value being borrowed.
519519
// So peel off one-level, turning the &T into T.
520-
match base_ty.builtin_deref(false, ty::NoPreference) {
520+
match base_ty.builtin_deref(false) {
521521
Some(t) => t.ty,
522522
None => {
523523
debug!("By-ref binding of non-derefable type {:?}", base_ty);
@@ -1019,7 +1019,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
10191019
debug!("cat_deref: base_cmt={:?}", base_cmt);
10201020

10211021
let base_cmt_ty = base_cmt.ty;
1022-
let deref_ty = match base_cmt_ty.builtin_deref(true, ty::NoPreference) {
1022+
let deref_ty = match base_cmt_ty.builtin_deref(true) {
10231023
Some(mt) => mt.ty,
10241024
None => {
10251025
debug!("Explicit deref of non-derefable type: {:?}",

src/librustc/mir/tcx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl<'a, 'gcx, 'tcx> PlaceTy<'tcx> {
5252
match *elem {
5353
ProjectionElem::Deref => {
5454
let ty = self.to_ty(tcx)
55-
.builtin_deref(true, ty::LvaluePreference::NoPreference)
55+
.builtin_deref(true)
5656
.unwrap_or_else(|| {
5757
bug!("deref projection of non-dereferencable ty {:?}", self)
5858
})

src/librustc/ty/mod.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ pub use self::Variance::*;
1212
pub use self::AssociatedItemContainer::*;
1313
pub use self::BorrowKind::*;
1414
pub use self::IntVarValue::*;
15-
pub use self::LvaluePreference::*;
1615
pub use self::fold::TypeFoldable;
1716

1817
use hir::{map as hir_map, FreevarMap, TraitMap};
@@ -2099,21 +2098,6 @@ impl<'tcx> TyS<'tcx> {
20992098
}
21002099
}
21012100

2102-
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
2103-
pub enum LvaluePreference {
2104-
PreferMutLvalue,
2105-
NoPreference
2106-
}
2107-
2108-
impl LvaluePreference {
2109-
pub fn from_mutbl(m: hir::Mutability) -> Self {
2110-
match m {
2111-
hir::MutMutable => PreferMutLvalue,
2112-
hir::MutImmutable => NoPreference,
2113-
}
2114-
}
2115-
}
2116-
21172101
impl BorrowKind {
21182102
pub fn from_mutbl(m: hir::Mutability) -> BorrowKind {
21192103
match m {

src/librustc/ty/sty.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,18 +1514,12 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
15141514
///
15151515
/// The parameter `explicit` indicates if this is an *explicit* dereference.
15161516
/// Some types---notably unsafe ptrs---can only be dereferenced explicitly.
1517-
pub fn builtin_deref(&self, explicit: bool, pref: ty::LvaluePreference)
1518-
-> Option<TypeAndMut<'tcx>>
1519-
{
1517+
pub fn builtin_deref(&self, explicit: bool) -> Option<TypeAndMut<'tcx>> {
15201518
match self.sty {
15211519
TyAdt(def, _) if def.is_box() => {
15221520
Some(TypeAndMut {
15231521
ty: self.boxed_ty(),
1524-
mutbl: if pref == ty::PreferMutLvalue {
1525-
hir::MutMutable
1526-
} else {
1527-
hir::MutImmutable
1528-
},
1522+
mutbl: hir::MutImmutable,
15291523
})
15301524
},
15311525
TyRef(_, mt) => Some(mt),

src/librustc_mir/borrow_check/nll/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
397397
let base_ty = base.to_ty(tcx);
398398
match *pi {
399399
ProjectionElem::Deref => {
400-
let deref_ty = base_ty.builtin_deref(true, ty::LvaluePreference::NoPreference);
400+
let deref_ty = base_ty.builtin_deref(true);
401401
PlaceTy::Ty {
402402
ty: deref_ty.map(|t| t.ty).unwrap_or_else(|| {
403403
span_mirbug_and_err!(self, place, "deref of non-pointer {:?}", base_ty)

src/librustc_trans/abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ impl<'a, 'tcx> FnType<'tcx> {
674674
_ => bug!("FnType::new_vtable: non-pair self {:?}", self_arg)
675675
}
676676

677-
let pointee = self_arg.layout.ty.builtin_deref(true, ty::NoPreference)
677+
let pointee = self_arg.layout.ty.builtin_deref(true)
678678
.unwrap_or_else(|| {
679679
bug!("FnType::new_vtable: non-pointer self {:?}", self_arg)
680680
}).ty;

src/librustc_trans/mir/constant.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
740740
operand.llval
741741
}
742742
mir::CastKind::Unsize => {
743-
let pointee_ty = operand.ty.builtin_deref(true, ty::NoPreference)
743+
let pointee_ty = operand.ty.builtin_deref(true)
744744
.expect("consts: unsizing got non-pointer type").ty;
745745
let (base, old_info) = if !self.cx.type_is_sized(pointee_ty) {
746746
// Normally, the source is a thin pointer and we are
@@ -755,7 +755,7 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
755755
(operand.llval, None)
756756
};
757757

758-
let unsized_ty = cast_ty.builtin_deref(true, ty::NoPreference)
758+
let unsized_ty = cast_ty.builtin_deref(true)
759759
.expect("consts: unsizing got non-pointer target type").ty;
760760
let ptr_ty = self.cx.layout_of(unsized_ty).llvm_type(self.cx).ptr_to();
761761
let base = consts::ptrcast(base, ptr_ty);

src/librustc_trans/mir/operand.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
use llvm::ValueRef;
12-
use rustc::ty;
1312
use rustc::ty::layout::{self, Align, LayoutOf, TyLayout};
1413
use rustc::mir;
1514
use rustc_data_structures::indexed_vec::Idx;
@@ -100,7 +99,7 @@ impl<'a, 'tcx> OperandRef<'tcx> {
10099
}
101100

102101
pub fn deref(self, cx: &CodegenCx<'a, 'tcx>) -> PlaceRef<'tcx> {
103-
let projected_ty = self.layout.ty.builtin_deref(true, ty::NoPreference)
102+
let projected_ty = self.layout.ty.builtin_deref(true)
104103
.unwrap_or_else(|| bug!("deref of non-pointer {:?}", self)).ty;
105104
let (llptr, llextra) = match self.val {
106105
OperandValue::Immediate(llptr) => (llptr, ptr::null_mut()),

src/librustc_typeck/check/_match.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use rustc::hir::pat_util::EnumerateAndAdjustIterator;
1414
use rustc::infer;
1515
use rustc::infer::type_variable::TypeVariableOrigin;
1616
use rustc::traits::ObligationCauseCode;
17-
use rustc::ty::{self, Ty, TypeFoldable, LvaluePreference};
18-
use check::{FnCtxt, Expectation, Diverges};
17+
use rustc::ty::{self, Ty, TypeFoldable};
18+
use check::{FnCtxt, Expectation, Diverges, LvaluePreference};
1919
use check::coercion::CoerceMany;
2020
use util::nodemap::FxHashMap;
2121

@@ -500,7 +500,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
500500

501501
pub fn check_dereferencable(&self, span: Span, expected: Ty<'tcx>, inner: &hir::Pat) -> bool {
502502
if let PatKind::Binding(..) = inner.node {
503-
if let Some(mt) = self.shallow_resolve(expected).builtin_deref(true, ty::NoPreference) {
503+
if let Some(mt) = self.shallow_resolve(expected).builtin_deref(true) {
504504
if let ty::TyDynamic(..) = mt.ty.sty {
505505
// This is "x = SomeTrait" being reduced from
506506
// "let &x = &SomeTrait" or "let box x = Box<SomeTrait>", an error.

src/librustc_typeck/check/autoderef.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@
1010

1111
use astconv::AstConv;
1212

13-
use super::{FnCtxt, LvalueOp};
13+
use super::{FnCtxt, LvalueOp, LvaluePreference};
1414
use super::method::MethodCallee;
1515

1616
use rustc::infer::InferOk;
1717
use rustc::session::DiagnosticMessageId;
1818
use rustc::traits;
1919
use rustc::ty::{self, Ty, TraitRef};
2020
use rustc::ty::{ToPredicate, TypeFoldable};
21-
use rustc::ty::{LvaluePreference, NoPreference};
2221
use rustc::ty::adjustment::{Adjustment, Adjust, OverloadedDeref};
2322

2423
use syntax_pos::Span;
@@ -85,7 +84,7 @@ impl<'a, 'gcx, 'tcx> Iterator for Autoderef<'a, 'gcx, 'tcx> {
8584

8685
// Otherwise, deref if type is derefable:
8786
let (kind, new_ty) =
88-
if let Some(mt) = self.cur_ty.builtin_deref(self.include_raw_pointers, NoPreference) {
87+
if let Some(mt) = self.cur_ty.builtin_deref(self.include_raw_pointers) {
8988
(AutoderefKind::Builtin, mt.ty)
9089
} else {
9190
let ty = self.overloaded_deref_ty(self.cur_ty)?;
@@ -238,8 +237,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
238237
pub fn try_overloaded_deref(&self,
239238
span: Span,
240239
base_ty: Ty<'tcx>,
241-
pref: LvaluePreference)
240+
needs: Needs)
242241
-> Option<InferOk<'tcx, MethodCallee<'tcx>>> {
243-
self.try_overloaded_lvalue_op(span, base_ty, &[], pref, LvalueOp::Deref)
242+
self.try_overloaded_lvalue_op(span, base_ty, &[], needs, LvalueOp::Deref)
244243
}
245244
}

src/librustc_typeck/check/callee.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use super::{Expectation, FnCtxt, TupleArgumentsFlag};
11+
use super::{Expectation, FnCtxt, LvaluePreference, TupleArgumentsFlag};
1212
use super::autoderef::Autoderef;
1313
use super::method::MethodCallee;
1414

1515
use hir::def::Def;
1616
use hir::def_id::{DefId, LOCAL_CRATE};
1717
use rustc::{infer, traits};
18-
use rustc::ty::{self, TyCtxt, TypeFoldable, LvaluePreference, Ty};
18+
use rustc::ty::{self, TyCtxt, TypeFoldable, Ty};
1919
use rustc::ty::adjustment::{Adjustment, Adjust, AutoBorrow};
2020
use syntax::abi;
2121
use syntax::symbol::Symbol;

src/librustc_typeck/check/coercion.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
//! sort of a minor point so I've opted to leave it for later---after all
6161
//! we may want to adjust precisely when coercions occur.
6262
63-
use check::{Diverges, FnCtxt};
63+
use check::{Diverges, FnCtxt, LvaluePreference};
6464

6565
use rustc::hir;
6666
use rustc::hir::def_id::DefId;
@@ -69,8 +69,7 @@ use rustc::infer::type_variable::TypeVariableOrigin;
6969
use rustc::lint;
7070
use rustc::traits::{self, ObligationCause, ObligationCauseCode};
7171
use rustc::ty::adjustment::{Adjustment, Adjust, AutoBorrow};
72-
use rustc::ty::{self, LvaluePreference, TypeAndMut,
73-
Ty, ClosureSubsts};
72+
use rustc::ty::{self, TypeAndMut, Ty, ClosureSubsts};
7473
use rustc::ty::fold::TypeFoldable;
7574
use rustc::ty::error::TypeError;
7675
use rustc::ty::relate::RelateResult;

src/librustc_typeck/check/method/confirm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
use super::{probe, MethodCallee};
1212

1313
use astconv::AstConv;
14-
use check::{FnCtxt, LvalueOp, callee};
14+
use check::{FnCtxt, LvalueOp, callee, LvaluePreference, PreferMutLvalue};
1515
use hir::def_id::DefId;
1616
use rustc::ty::subst::Substs;
1717
use rustc::traits;
18-
use rustc::ty::{self, LvaluePreference, NoPreference, PreferMutLvalue, Ty};
18+
use rustc::ty::{self, Ty};
1919
use rustc::ty::subst::Subst;
2020
use rustc::ty::adjustment::{Adjustment, Adjust, AutoBorrow, OverloadedDeref};
2121
use rustc::ty::fold::TypeFoldable;
@@ -500,7 +500,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
500500
let base_ty = self.resolve_type_vars_if_possible(&base_ty);
501501

502502
// Need to deref because overloaded lvalue ops take self by-reference.
503-
let base_ty = base_ty.builtin_deref(false, NoPreference)
503+
let base_ty = base_ty.builtin_deref(false)
504504
.expect("lvalue op takes something that is not a ref")
505505
.ty;
506506

src/librustc_typeck/check/mod.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ type parameter).
7777
*/
7878

7979
pub use self::Expectation::*;
80+
use self::LvaluePreference::*;
8081
use self::autoderef::Autoderef;
8182
use self::callee::DeferredCallResolution;
8283
use self::coercion::{CoerceMany, DynamicCoerceMany};
@@ -95,7 +96,6 @@ use rustc::infer::type_variable::{TypeVariableOrigin};
9596
use rustc::middle::region;
9697
use rustc::ty::subst::{Kind, Subst, Substs};
9798
use rustc::traits::{self, FulfillmentContext, ObligationCause, ObligationCauseCode};
98-
use rustc::ty::{ParamTy, LvaluePreference, NoPreference, PreferMutLvalue};
9999
use rustc::ty::{self, Ty, TyCtxt, Visibility, ToPredicate};
100100
use rustc::ty::adjustment::{Adjust, Adjustment, AutoBorrow};
101101
use rustc::ty::fold::TypeFoldable;
@@ -368,6 +368,21 @@ impl<'a, 'gcx, 'tcx> Expectation<'tcx> {
368368
}
369369
}
370370

371+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
372+
pub enum LvaluePreference {
373+
PreferMutLvalue,
374+
NoPreference
375+
}
376+
377+
impl LvaluePreference {
378+
fn from_mutbl(m: hir::Mutability) -> Self {
379+
match m {
380+
hir::MutMutable => PreferMutLvalue,
381+
hir::MutImmutable => NoPreference,
382+
}
383+
}
384+
}
385+
371386
#[derive(Copy, Clone)]
372387
pub struct UnsafetyState {
373388
pub def: ast::NodeId,
@@ -2219,7 +2234,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
22192234
let ret_ty = method.sig.output();
22202235

22212236
// method returns &T, but the type as visible to user is T, so deref
2222-
ret_ty.builtin_deref(true, NoPreference).unwrap()
2237+
ret_ty.builtin_deref(true).unwrap()
22232238
}
22242239

22252240
fn lookup_indexing(&self,
@@ -3572,7 +3587,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
35723587
oprnd_t = self.structurally_resolved_type(expr.span, oprnd_t);
35733588
match unop {
35743589
hir::UnDeref => {
3575-
if let Some(mt) = oprnd_t.builtin_deref(true, NoPreference) {
3590+
if let Some(mt) = oprnd_t.builtin_deref(true) {
35763591
oprnd_t = mt.ty;
35773592
} else if let Some(ok) = self.try_overloaded_deref(
35783593
expr.span, oprnd_t, lvalue_pref) {
@@ -5023,7 +5038,7 @@ pub fn check_bounds_are_used<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
50235038
let lifetime_count = generics.lifetimes().count();
50245039

50255040
for leaf_ty in ty.walk() {
5026-
if let ty::TyParam(ParamTy {idx, ..}) = leaf_ty.sty {
5041+
if let ty::TyParam(ty::ParamTy {idx, ..}) = leaf_ty.sty {
50275042
debug!("Found use of ty param num {}", idx);
50285043
tps_used[idx as usize - lifetime_count] = true;
50295044
} else if let ty::TyError = leaf_ty.sty {

src/librustc_typeck/check/op.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
//! Code related to processing overloaded binary and unary operators.
1212
13-
use super::FnCtxt;
13+
use super::{FnCtxt, NoPreference, PreferMutLvalue};
1414
use super::method::MethodCallee;
15-
use rustc::ty::{self, Ty, TypeFoldable, NoPreference, PreferMutLvalue, TypeVariants};
15+
use rustc::ty::{self, Ty, TypeFoldable, TypeVariants};
1616
use rustc::ty::TypeVariants::{TyStr, TyRef};
1717
use rustc::ty::adjustment::{Adjustment, Adjust, AutoBorrow};
1818
use rustc::infer::type_variable::TypeVariableOrigin;

0 commit comments

Comments
 (0)