}
}
- #[allow(dead_code)]
fn check_rvalue(&mut self, mir: &Mir<'tcx>, rv: &Rvalue<'tcx>, location: Location) {
let tcx = self.tcx();
match rv {
- Rvalue::Aggregate(ref ak, ref ops) => {
+ Rvalue::Aggregate(ak, ops) => {
match **ak {
// tuple rvalue field type is always the type of the op. Nothing to check here.
AggregateKind::Tuple => { },
_ => {
for (i, op) in ops.iter().enumerate() {
- let field_ty = if let Ok(field_ty) = self.aggregate_field_ty(ak, i, location) {
- field_ty
- } else {
- // TODO(nashenas88) log span_mirbug terr??
- continue;
+ let field_ty = match self.aggregate_field_ty(ak, i, location) {
+ Ok(field_ty) => field_ty,
+ Err(FieldAccessError::OutOfRange { field_count }) => {
+ span_mirbug!(
+ self,
+ rv,
+ "accessed field #{} but variant only has {}",
+ i,
+ field_count);
+ continue;
+ },
};
let op_ty = match op {
Operand::Consume(lv) => lv.ty(mir, tcx).to_ty(tcx),
Operand::Constant(c) => c.ty,
};
- if let Err(_terr) = self.sub_types(op_ty, field_ty, location.at_successor_within_block()) {
- // TODO(nashenas88) log span_mirbug terr??
+ if let Err(terr) = self.sub_types(op_ty, field_ty, location.at_successor_within_block()) {
+ span_mirbug!(
+ self,
+ rv,
+ "{:?} is not a subtype of {:?}: {:?}",
+ op_ty,
+ field_ty,
+ terr);
}
}
},
+++ /dev/null
-// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-//revisions: ast mir
-//[mir] compile-flags: -Z emit-end-regions -Z borrowck-mir -Z nll
-
-#![allow(unused_assignments)]
-
-struct Wrap<'a> { w: &'a mut u32 }
-
-fn foo() {
- let mut x = 22;
- let wrapper = Wrap { w: &mut x };
- //~^ ERROR cannot assign to `x` because it is borrowed (Mir) [E0506]
- //~^^ ERROR cannot use `x` because it was mutably borrowed (Mir) [E0503]
- x += 1; //[ast]~ ERROR cannot assign to `x` because it is borrowed [E0506]
- //[mir]~^ ERROR cannot assign to `x` because it is borrowed (Ast) [E0506]
- //[mir]~^^ ERROR cannot assign to `x` because it is borrowed (Mir) [E0506]
- //[mir]~^^^ ERROR cannot use `x` because it was mutably borrowed (Mir) [E0503]
- *wrapper.w += 1;
-}
-
-fn main() { }
\ No newline at end of file
--- /dev/null
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+//revisions: ast mir
+//[mir] compile-flags: -Z emit-end-regions -Z borrowck-mir -Z nll
+
+#![allow(unused_assignments)]
+
+struct Wrap<'a> { w: &'a mut u32 }
+
+fn foo() {
+ let mut x = 22;
+ let wrapper = Wrap { w: &mut x };
+ x += 1; //[ast]~ ERROR cannot assign to `x` because it is borrowed [E0506]
+ //[mir]~^ ERROR cannot assign to `x` because it is borrowed (Ast) [E0506]
+ //[mir]~^^ ERROR cannot assign to `x` because it is borrowed (Mir) [E0506]
+ //[mir]~^^^ ERROR cannot use `x` because it was mutably borrowed (Mir) [E0503]
+ *wrapper.w += 1;
+}
+
+fn main() { }
\ No newline at end of file