Skip to content

Commit d543ae7

Browse files
author
Saleem Jaffer
committed
adding a bool field in BindingMode::BindByValue
1 parent 54479c6 commit d543ae7

File tree

13 files changed

+46
-30
lines changed

13 files changed

+46
-30
lines changed

src/librustc/middle/expr_use_visitor.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
828828
match bm {
829829
ty::BindByReference(..) =>
830830
mode.lub(BorrowingMatch),
831-
ty::BindByValue(..) => {
831+
ty::BindByValue{..} => {
832832
match copy_or_move(&self.mc, self.param_env, &cmt_pat, PatBindingMove) {
833833
Copy => mode.lub(CopyingMatch),
834834
Move(..) => mode.lub(MovingMatch),
@@ -877,7 +877,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
877877
delegate.borrow(pat.hir_id, pat.span, &cmt_pat, r, bk, RefBinding);
878878
}
879879
}
880-
ty::BindByValue(..) => {
880+
ty::BindByValue{..} => {
881881
let mode = copy_or_move(mc, param_env, &cmt_pat, PatBindingMove);
882882
debug!("walk_pat binding consuming pat");
883883
delegate.consume_pat(pat, &cmt_pat, mode);

src/librustc/middle/mem_categorization.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ impl MutabilityCategory {
344344
let bm = *tables.pat_binding_modes()
345345
.get(p.hir_id)
346346
.expect("missing binding mode");
347-
if bm == ty::BindByValue(hir::MutMutable) {
347+
if let ty::BindByValue{mutability: hir::MutMutable, ..} = bm {
348348
McDeclared
349349
} else {
350350
McImmutable

src/librustc/mir/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ impl<'tcx> LocalDecl<'tcx> {
876876
pub fn can_be_made_mutable(&self) -> bool {
877877
match self.is_user_variable {
878878
Some(ClearCrossCrate::Set(BindingForm::Var(VarBindingForm {
879-
binding_mode: ty::BindingMode::BindByValue(_),
879+
binding_mode: ty::BindingMode::BindByValue{..},
880880
opt_ty_info: _,
881881
opt_match_place: _,
882882
pat_span: _,
@@ -895,7 +895,7 @@ impl<'tcx> LocalDecl<'tcx> {
895895
pub fn is_nonref_binding(&self) -> bool {
896896
match self.is_user_variable {
897897
Some(ClearCrossCrate::Set(BindingForm::Var(VarBindingForm {
898-
binding_mode: ty::BindingMode::BindByValue(_),
898+
binding_mode: ty::BindingMode::BindByValue{..},
899899
opt_ty_info: _,
900900
opt_match_place: _,
901901
pat_span: _,

src/librustc/ty/binding.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,23 @@ use crate::hir::Mutability;
55
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
66
pub enum BindingMode {
77
BindByReference(Mutability),
8-
BindByValue(Mutability),
8+
BindByValue {
9+
coerced: bool,
10+
mutability: Mutability,
11+
},
912
}
1013

1114
CloneTypeFoldableAndLiftImpls! { BindingMode, }
1215

1316
impl BindingMode {
1417
pub fn convert(ba: BindingAnnotation) -> BindingMode {
1518
match ba {
16-
Unannotated => BindingMode::BindByValue(Mutability::MutImmutable),
17-
Mutable => BindingMode::BindByValue(Mutability::MutMutable),
19+
Unannotated => BindingMode::BindByValue{
20+
mutability: Mutability::MutImmutable, coerced: false
21+
},
22+
Mutable => BindingMode::BindByValue{
23+
mutability: Mutability::MutMutable, coerced: false
24+
},
1825
Ref => BindingMode::BindByReference(Mutability::MutImmutable),
1926
RefMut => BindingMode::BindByReference(Mutability::MutMutable),
2027
}
@@ -23,5 +30,5 @@ impl BindingMode {
2330

2431
impl_stable_hash_for!(enum self::BindingMode {
2532
BindByReference(mutability),
26-
BindByValue(mutability)
33+
BindByValue{ mutability, coerced },
2734
});

src/librustc_borrowck/borrowck/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
12521252
);
12531253
}
12541254
}
1255-
ty::BindByValue(..) => {
1255+
ty::BindByValue{..} => {
12561256
if let (Some(local_ty), is_implicit_self) = self.local_ty(hir_id) {
12571257
if let Some(msg) =
12581258
self.suggest_mut_for_immutable(local_ty, is_implicit_self) {
@@ -1285,7 +1285,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
12851285
borrowed_hir_id: hir::HirId,
12861286
binding_hir_id: hir::HirId) {
12871287
let let_span = self.tcx.hir().span_by_hir_id(binding_hir_id);
1288-
if let ty::BindByValue(..) = self.local_binding_mode(binding_hir_id) {
1288+
if let ty::BindByValue{..} = self.local_binding_mode(binding_hir_id) {
12891289
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(let_span) {
12901290
let (ty, is_implicit_self) = self.local_ty(binding_hir_id);
12911291
if is_implicit_self && snippet != "self" {

src/librustc_borrowck/borrowck/unused.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl<'a, 'tcx> UnusedMutCx<'a, 'tcx> {
4747
// for by-value bindings
4848
if let Some(&bm) = self.bccx.tables.pat_binding_modes().get(hir_id) {
4949
match bm {
50-
ty::BindByValue(hir::MutMutable) => {}
50+
ty::BindByValue{mutability: hir::MutMutable, ..} => {}
5151
_ => return,
5252
}
5353

src/librustc_mir/borrow_check/mutability_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
380380
}
381381

382382
ClearCrossCrate::Set(mir::BindingForm::Var(mir::VarBindingForm {
383-
binding_mode: ty::BindingMode::BindByValue(_),
383+
binding_mode: ty::BindingMode::BindByValue{..},
384384
opt_ty_info,
385385
..
386386
})) => Some(suggest_ampmut(

src/librustc_mir/build/matches/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1714,7 +1714,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
17141714

17151715
let tcx = self.hir.tcx();
17161716
let binding_mode = match mode {
1717-
BindingMode::ByValue => ty::BindingMode::BindByValue(mutability.into()),
1717+
BindingMode::ByValue => ty::BindingMode::BindByValue{
1718+
mutability: mutability.into(), coerced: false,
1719+
},
17181720
BindingMode::ByRef(_) => ty::BindingMode::BindByReference(mutability.into()),
17191721
};
17201722
debug!("declare_binding: user_ty={:?}", user_ty);

src/librustc_mir/build/mod.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -652,10 +652,14 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
652652
if let hir::PatKind::Binding(_, _, ident, _) = pat.node {
653653
decl.debug_name = ident.name;
654654
if let Some(&bm) = hir.tables.pat_binding_modes().get(pat.hir_id) {
655-
if bm == ty::BindByValue(hir::MutMutable) {
656-
decl.mutability = Mutability::Mut;
657-
} else {
658-
decl.mutability = Mutability::Not;
655+
match bm {
656+
ty::BindByReference(_) => { decl.mutability = Mutability::Not; },
657+
ty::BindByValue{mutability: hir::MutImmutable, ..} => {
658+
decl.mutability = Mutability::Not;
659+
},
660+
ty::BindByValue{mutability: hir::MutMutable, ..} => {
661+
decl.mutability = Mutability::Mut;
662+
},
659663
}
660664
} else {
661665
tcx.sess.delay_span_bug(pat.span, "missing binding mode");
@@ -906,7 +910,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
906910
if let Some(kind) = self_binding {
907911
Some(ClearCrossCrate::Set(BindingForm::ImplicitSelf(*kind)))
908912
} else {
909-
let binding_mode = ty::BindingMode::BindByValue(mutability.into());
913+
let binding_mode = ty::BindingMode::BindByValue{
914+
mutability: mutability.into(), coerced: false,
915+
};
910916
Some(ClearCrossCrate::Set(BindingForm::Var(VarBindingForm {
911917
binding_mode,
912918
opt_ty_info,

src/librustc_mir/hair/pattern/check_match.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,7 @@ fn check_for_bindings_named_same_as_variants(cx: &MatchVisitor<'_, '_>, pat: &Pa
304304
pat.walk(|p| {
305305
if let PatKind::Binding(_, _, ident, None) = p.node {
306306
if let Some(&bm) = cx.tables.pat_binding_modes().get(p.hir_id) {
307-
if bm != ty::BindByValue(hir::MutImmutable) {
308-
// Nothing to check.
307+
if let ty::BindByValue{mutability: hir::MutImmutable, coerced: _} = bm {
309308
return true;
310309
}
311310
let pat_ty = cx.tables.pat_ty(p);
@@ -580,7 +579,7 @@ fn check_legality_of_move_bindings(
580579
if let PatKind::Binding(_, _, _, ref sub) = p.node {
581580
if let Some(&bm) = cx.tables.pat_binding_modes().get(p.hir_id) {
582581
match bm {
583-
ty::BindByValue(..) => {
582+
ty::BindByValue{..} => {
584583
let pat_ty = cx.tables.node_type(p.hir_id);
585584
if !pat_ty.is_copy_modulo_regions(cx.tcx, cx.param_env, pat.span) {
586585
check_move(p, sub.as_ref().map(|p| &**p), span_vec);

src/librustc_mir/hair/pattern/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -567,9 +567,9 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
567567
let bm = *self.tables.pat_binding_modes().get(pat.hir_id)
568568
.expect("missing binding mode");
569569
let (mutability, mode) = match bm {
570-
ty::BindByValue(hir::MutMutable) =>
570+
ty::BindByValue{mutability: hir::MutMutable, ..} =>
571571
(Mutability::Mut, BindingMode::ByValue),
572-
ty::BindByValue(hir::MutImmutable) =>
572+
ty::BindByValue{mutability: hir::MutImmutable, ..} =>
573573
(Mutability::Not, BindingMode::ByValue),
574574
ty::BindByReference(hir::MutMutable) =>
575575
(Mutability::Not, BindingMode::ByRef(

src/librustc_typeck/check/_match.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
9898
def_bm = match def_bm {
9999
// If default binding mode is by value, make it `ref` or `ref mut`
100100
// (depending on whether we observe `&` or `&mut`).
101-
ty::BindByValue(_) =>
101+
ty::BindByValue{..} =>
102102
ty::BindByReference(inner_mutability),
103103

104104
// Once a `ref`, always a `ref`. This is because a `& &mut` can't mutate
@@ -132,7 +132,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
132132
// ```
133133
//
134134
// cc #46688
135-
def_bm = ty::BindByValue(hir::MutImmutable);
135+
def_bm = ty::BindByValue{mutability: hir::MutImmutable, coerced: false};
136136
}
137137

138138
// Lose mutability now that we know binding mode and discriminant type.
@@ -256,7 +256,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
256256
self.demand_eqtype_pat(pat.span, region_ty, local_ty, match_discrim_span);
257257
}
258258
// otherwise the type of x is the expected type T
259-
ty::BindByValue(_) => {
259+
ty::BindByValue{..} => {
260260
// As above, `T <: typeof(x)` is required but we
261261
// use equality, see (*) below.
262262
self.demand_eqtype_pat(pat.span, expected, local_ty, match_discrim_span);
@@ -648,7 +648,9 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
648648
self.check_pat_walk(
649649
&p,
650650
discrim_ty,
651-
ty::BindingMode::BindByValue(hir::Mutability::MutImmutable),
651+
ty::BindingMode::BindByValue{
652+
mutability: hir::Mutability::MutImmutable, coerced: false
653+
},
652654
Some(discrim.span),
653655
);
654656
all_pats_diverge &= self.diverges.get();

src/librustc_typeck/check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
10791079
fcx.check_pat_walk(
10801080
&arg.pat,
10811081
arg_ty,
1082-
ty::BindingMode::BindByValue(hir::Mutability::MutImmutable),
1082+
ty::BindingMode::BindByValue{mutability: hir::Mutability::MutImmutable, coerced: false},
10831083
None,
10841084
);
10851085

@@ -4876,7 +4876,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
48764876
self.check_pat_walk(
48774877
&local.pat,
48784878
t,
4879-
ty::BindingMode::BindByValue(hir::Mutability::MutImmutable),
4879+
ty::BindingMode::BindByValue{mutability: hir::Mutability::MutImmutable, coerced: false},
48804880
None,
48814881
);
48824882
let pat_ty = self.node_ty(local.pat.hir_id);

0 commit comments

Comments
 (0)