From 47c6db09ee35810005274017abcd0798d6978a47 Mon Sep 17 00:00:00 2001 From: Paul Daniel Faria Date: Sat, 11 Nov 2017 16:13:23 -0500 Subject: [PATCH] Remove attributes and test comments accidentally left behind, add in span_mirbugs --- src/librustc_mir/transform/type_check.rs | 29 +++++++++++++------ ...reference-carried-through-struct-field.rs} | 2 -- 2 files changed, 20 insertions(+), 11 deletions(-) rename src/test/compile-fail/{aggregate-rvalues-typeck.rs => nll/reference-carried-through-struct-field.rs} (87%) diff --git a/src/librustc_mir/transform/type_check.rs b/src/librustc_mir/transform/type_check.rs index 7a801d887fbb..96264222eaef 100644 --- a/src/librustc_mir/transform/type_check.rs +++ b/src/librustc_mir/transform/type_check.rs @@ -1056,28 +1056,39 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { } } - #[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); } } }, diff --git a/src/test/compile-fail/aggregate-rvalues-typeck.rs b/src/test/compile-fail/nll/reference-carried-through-struct-field.rs similarity index 87% rename from src/test/compile-fail/aggregate-rvalues-typeck.rs rename to src/test/compile-fail/nll/reference-carried-through-struct-field.rs index 99f3e461ec98..afde25408294 100644 --- a/src/test/compile-fail/aggregate-rvalues-typeck.rs +++ b/src/test/compile-fail/nll/reference-carried-through-struct-field.rs @@ -17,8 +17,6 @@ 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]