|
11 | 11 | //! This query borrow-checks the MIR to (further) ensure it is not broken.
|
12 | 12 |
|
13 | 13 | use rustc::hir;
|
| 14 | +use rustc::hir::def::Def; |
14 | 15 | use rustc::hir::def_id::{DefId};
|
15 | 16 | use rustc::infer::{InferCtxt};
|
16 | 17 | use rustc::ty::{self, TyCtxt, ParamEnv};
|
@@ -1549,6 +1550,7 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
|
1549 | 1550 | }
|
1550 | 1551 | }
|
1551 | 1552 |
|
| 1553 | + // FIXME Instead of passing usize, Field should be passed |
1552 | 1554 | // End-user visible description of the `field_index`nth field of `base`
|
1553 | 1555 | fn describe_field(&self, base: &Lvalue, field_index: usize) -> String {
|
1554 | 1556 | match *base {
|
@@ -1600,7 +1602,20 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
|
1600 | 1602 | },
|
1601 | 1603 | ty::TyArray(ty, _) | ty::TySlice(ty) => {
|
1602 | 1604 | self.describe_field_from_ty(&ty, field_index)
|
1603 |
| - } |
| 1605 | + }, |
| 1606 | + ty::TyClosure(closure_def_id, _) => { |
| 1607 | + // Convert the def-id into a node-id. node-ids are only valid for |
| 1608 | + // the local code in the current crate, so this returns an `Option` in case |
| 1609 | + // the closure comes from another crate. But in that case we wouldn't |
| 1610 | + // be borrowck'ing it, so we can just unwrap: |
| 1611 | + let node_id = self.tcx.hir.as_local_node_id(closure_def_id).unwrap(); |
| 1612 | + let local_def = self.tcx.with_freevars(node_id, |fv| fv[field_index].def); |
| 1613 | + |
| 1614 | + match local_def { |
| 1615 | + Def::Local(local_node_id) => self.tcx.hir.name(local_node_id).to_string(), |
| 1616 | + _ => unreachable!() |
| 1617 | + } |
| 1618 | + } |
1604 | 1619 | _ => {
|
1605 | 1620 | // Might need a revision when the fields in trait RFC is implemented
|
1606 | 1621 | // (https://github.com/rust-lang/rfcs/pull/1546)
|
|
0 commit comments