match proj.elem {
ProjectionElem::Deref =>
self.describe_field(&proj.base, field_index),
- ProjectionElem::Index(..) => {
- debug!("End-user description not implemented for field of projection {:?}",
- proj);
- format!("<index>{}", field_index)
- },
- ProjectionElem::ConstantIndex { .. } => {
- debug!("End-user description not implemented for field of projection {:?}",
- proj);
- format!("<constant_index>{}", field_index)
- },
ProjectionElem::Downcast(def, variant_index) =>
format!("{}", def.variants[variant_index].fields[field_index].name),
ProjectionElem::Field(_, field_type) =>
self.describe_field_from_ty(&field_type, field_index),
+ ProjectionElem::Index(..) | ProjectionElem::ConstantIndex { .. } =>
+ format!("{}", self.describe_field(&proj.base, field_index)),
ProjectionElem::Subslice { .. } => {
debug!("End-user description not implemented for field of projection {:?}",
proj);
_ => panic!("other case"),
}
}
+ // Field of index
+ {
+ struct F {x: u32, y: u32};
+ let mut v = &[F{x: 1, y: 2}, F{x: 3, y: 4}];
+ let _v = &mut v;
+ v[0].y;
+ //[ast]~^ ERROR cannot use `v[..].y` because it was mutably borrowed
+ //[mir]~^^ ERROR cannot use `v[..].y` because it was mutably borrowed (Ast)
+ //[mir]~| ERROR cannot use `v[..].y` because it was mutably borrowed (Mir)
+ //[mir]~| ERROR cannot use `(*v)` because it was mutably borrowed (Mir)
+ }
+ // Field of constant index
+ {
+ struct F {x: u32, y: u32};
+ let mut v = &[F{x: 1, y: 2}, F{x: 3, y: 4}];
+ let _v = &mut v;
+ match v {
+ &[_, F {x: ref xf, ..}] => println!("{}", xf),
+ //[mir]~^ ERROR cannot borrow `v[..].x` as immutable because it is also borrowed as mutable (Mir)
+ // No errors in AST
+ _ => panic!("other case")
+ }
+ }
}