Skip to content

Commit 32f4736

Browse files
committed
---
yaml --- r: 160659 b: refs/heads/master c: 1217b82 h: refs/heads/master i: 160657: 4f8942d 160655: 15f728a v: v3
1 parent db9f855 commit 32f4736

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 91b88c54c2d2af73bcf23d383b4d5d524d222b14
2+
refs/heads/master: 1217b829e85ec4720ba9a1c43c173d4015eae651
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: c9f6d696420107f82304b992cf623b806995fe18
55
refs/heads/try: 225de0d60f8ca8dcc62ab2fd8818ebbda4b58cfe

trunk/src/librustc/middle/mem_categorization.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,28 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
410410
}
411411

412412
fn pat_ty(&self, pat: &ast::Pat) -> McResult<Ty<'tcx>> {
413-
self.typer.node_ty(pat.id)
413+
let tcx = self.typer.tcx();
414+
let base_ty = self.typer.node_ty(pat.id);
415+
// FIXME (Issue #18207): This code detects whether we are
416+
// looking at a `ref x`, and if so, figures out what the type
417+
// *being borrowed* is. But ideally we would put in a more
418+
// fundamental fix to this conflated use of the node id.
419+
let ret_ty = match pat.node {
420+
ast::PatIdent(ast::BindByRef(_), _, _) => {
421+
// a bind-by-ref means that the base_ty will be the type of the ident itself,
422+
// but what we want here is the type of the underlying value being borrowed.
423+
// So peel off one-level, turning the &T into T.
424+
base_ty.map(|t| {
425+
ty::deref(t, false).unwrap_or_else(|| {
426+
panic!("encountered BindByRef with non &-type");
427+
}).ty
428+
})
429+
}
430+
_ => base_ty,
431+
};
432+
debug!("pat_ty(pat={}) base_ty={} ret_ty={}",
433+
pat.repr(tcx), base_ty.repr(tcx), ret_ty.repr(tcx));
434+
ret_ty
414435
}
415436

416437
pub fn cat_expr(&self, expr: &ast::Expr) -> McResult<cmt<'tcx>> {

0 commit comments

Comments
 (0)