Skip to content

Commit 18eb58b

Browse files
committed
---
yaml --- r: 162594 b: refs/heads/try c: 1217b82 h: refs/heads/master v: v3
1 parent a26087d commit 18eb58b

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
@@ -2,7 +2,7 @@
22
refs/heads/master: 9146a919b616e39e528e4d7100d16eef52f1f852
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cafe2966770ff377aad6dd9fd808e68055587c58
5-
refs/heads/try: 91b88c54c2d2af73bcf23d383b4d5d524d222b14
5+
refs/heads/try: 1217b829e85ec4720ba9a1c43c173d4015eae651
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/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)