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
}

0 commit comments

Comments
 (0)