Skip to content

Commit bb5e16b

Browse files
committed
rollup merge of #20554: huonw/mut-pattern
Conflicts: src/librustc_typeck/check/_match.rs
2 parents 0ca3a8c + bf6c007 commit bb5e16b

File tree

19 files changed

+92
-26
lines changed

19 files changed

+92
-26
lines changed

src/doc/reference.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3484,8 +3484,9 @@ fn main() {
34843484
34853485
```
34863486

3487-
Patterns can also dereference pointers by using the `&`, `box` symbols,
3488-
as appropriate. For example, these two matches on `x: &int` are equivalent:
3487+
Patterns can also dereference pointers by using the `&`, `&mut` and `box`
3488+
symbols, as appropriate. For example, these two matches on `x: &int` are
3489+
equivalent:
34893490

34903491
```
34913492
# let x = &3i;

src/libcore/str/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ impl<F> CharEq for F where F: FnMut(char) -> bool {
230230
impl<'a> CharEq for &'a [char] {
231231
#[inline]
232232
fn matches(&mut self, c: char) -> bool {
233-
self.iter().any(|&mut m| m.matches(c))
233+
self.iter().any(|&m| { let mut m = m; m.matches(c) })
234234
}
235235

236236
#[inline]

src/librustc/middle/cfg/construct.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
119119
}
120120

121121
ast::PatBox(ref subpat) |
122-
ast::PatRegion(ref subpat) |
122+
ast::PatRegion(ref subpat, _) |
123123
ast::PatIdent(_, _, Some(ref subpat)) => {
124124
let subpat_exit = self.pat(&**subpat, pred);
125125
self.add_node(pat.id, &[subpat_exit])

src/librustc/middle/check_match.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ fn construct_witness(cx: &MatchCheckCtxt, ctor: &Constructor,
473473
}
474474
}
475475

476-
ty::ty_rptr(_, ty::mt { ty, .. }) => {
476+
ty::ty_rptr(_, ty::mt { ty, mutbl }) => {
477477
match ty.sty {
478478
ty::ty_vec(_, Some(n)) => match ctor {
479479
&Single => {
@@ -493,7 +493,7 @@ fn construct_witness(cx: &MatchCheckCtxt, ctor: &Constructor,
493493

494494
_ => {
495495
assert_eq!(pats_len, 1);
496-
ast::PatRegion(pats.nth(0).unwrap())
496+
ast::PatRegion(pats.nth(0).unwrap(), mutbl)
497497
}
498498
}
499499
}
@@ -860,7 +860,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
860860
ast::PatTup(ref args) =>
861861
Some(args.iter().map(|p| &**p).collect()),
862862

863-
ast::PatBox(ref inner) | ast::PatRegion(ref inner) =>
863+
ast::PatBox(ref inner) | ast::PatRegion(ref inner, _) =>
864864
Some(vec![&**inner]),
865865

866866
ast::PatLit(ref expr) => {

src/librustc/middle/mem_categorization.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,8 +1235,10 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
12351235
}
12361236
}
12371237

1238-
ast::PatBox(ref subpat) | ast::PatRegion(ref subpat) => {
1239-
// @p1, ~p1, ref p1
1238+
ast::PatBox(ref subpat) | ast::PatRegion(ref subpat, _) => {
1239+
// box p1, &p1, &mut p1. we can ignore the mutability of
1240+
// PatRegion since that information is already contained
1241+
// in the type.
12401242
let subcmt = try!(self.cat_deref(pat, cmt, 0, false));
12411243
try!(self.cat_pattern_(subcmt, &**subpat, op));
12421244
}

src/librustc_trans/trans/_match.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ fn any_uniq_pat(m: &[Match], col: uint) -> bool {
683683
}
684684

685685
fn any_region_pat(m: &[Match], col: uint) -> bool {
686-
any_pat!(m, col, ast::PatRegion(_))
686+
any_pat!(m, col, ast::PatRegion(..))
687687
}
688688

689689
fn any_irrefutable_adt_pat(tcx: &ty::ctxt, m: &[Match], col: uint) -> bool {
@@ -1725,7 +1725,7 @@ fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
17251725
let llbox = Load(bcx, val);
17261726
bcx = bind_irrefutable_pat(bcx, &**inner, llbox, cleanup_scope);
17271727
}
1728-
ast::PatRegion(ref inner) => {
1728+
ast::PatRegion(ref inner, _) => {
17291729
let loaded_val = Load(bcx, val);
17301730
bcx = bind_irrefutable_pat(bcx, &**inner, loaded_val, cleanup_scope);
17311731
}

src/librustc_trans/trans/debuginfo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3442,7 +3442,7 @@ fn create_scope_map(cx: &CrateContext,
34423442
}
34433443
}
34443444

3445-
ast::PatBox(ref sub_pat) | ast::PatRegion(ref sub_pat) => {
3445+
ast::PatBox(ref sub_pat) | ast::PatRegion(ref sub_pat, _) => {
34463446
scope_map.insert(pat.id, scope_stack.last().unwrap().scope_metadata);
34473447
walk_pattern(cx, &**sub_pat, scope_stack, scope_map);
34483448
}

src/librustc_typeck/check/_match.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,16 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
192192
check_pat(pcx, &**inner, tcx.types.err);
193193
}
194194
}
195-
ast::PatRegion(ref inner) => {
195+
ast::PatRegion(ref inner, mutbl) => {
196196
let inner_ty = fcx.infcx().next_ty_var();
197197

198-
let mutbl =
199-
ty::deref(fcx.infcx().shallow_resolve(expected), true).map(|mt| mt.mutbl)
200-
.unwrap_or(ast::MutImmutable);
198+
// SNAP c894171 remove this `if`-`else` entirely after next snapshot
199+
let mutbl = if mutbl == ast::MutImmutable {
200+
ty::deref(fcx.infcx().shallow_resolve(expected), true)
201+
.map(|mt| mt.mutbl).unwrap_or(ast::MutImmutable);
202+
} else {
203+
mutbl
204+
};
201205

202206
let mt = ty::mt { ty: inner_ty, mutbl: mutbl };
203207
let region = fcx.infcx().next_region_var(infer::PatternRegion(pat.span));

src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2220,7 +2220,7 @@ fn name_from_pat(p: &ast::Pat) -> String {
22202220
PatTup(ref elts) => format!("({})", elts.iter().map(|p| name_from_pat(&**p))
22212221
.collect::<Vec<String>>().connect(", ")),
22222222
PatBox(ref p) => name_from_pat(&**p),
2223-
PatRegion(ref p) => name_from_pat(&**p),
2223+
PatRegion(ref p, _) => name_from_pat(&**p),
22242224
PatLit(..) => {
22252225
warn!("tried to get argument name from PatLit, \
22262226
which is silly in function arguments");

src/libsyntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ pub enum Pat_ {
572572
PatStruct(Path, Vec<Spanned<FieldPat>>, bool),
573573
PatTup(Vec<P<Pat>>),
574574
PatBox(P<Pat>),
575-
PatRegion(P<Pat>), // reference pattern
575+
PatRegion(P<Pat>, Mutability), // reference pattern
576576
PatLit(P<Expr>),
577577
PatRange(P<Expr>, P<Expr>),
578578
/// [a, b, ..i, y, z] is represented as:

0 commit comments

Comments
 (0)