Skip to content

Commit 47c6db0

Browse files
Nashenas88nikomatsakis
authored andcommitted
Remove attributes and test comments accidentally left behind, add in span_mirbugs
1 parent fe32df9 commit 47c6db0

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

src/librustc_mir/transform/type_check.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,28 +1056,39 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
10561056
}
10571057
}
10581058

1059-
#[allow(dead_code)]
10601059
fn check_rvalue(&mut self, mir: &Mir<'tcx>, rv: &Rvalue<'tcx>, location: Location) {
10611060
let tcx = self.tcx();
10621061
match rv {
1063-
Rvalue::Aggregate(ref ak, ref ops) => {
1062+
Rvalue::Aggregate(ak, ops) => {
10641063
match **ak {
10651064
// tuple rvalue field type is always the type of the op. Nothing to check here.
10661065
AggregateKind::Tuple => { },
10671066
_ => {
10681067
for (i, op) in ops.iter().enumerate() {
1069-
let field_ty = if let Ok(field_ty) = self.aggregate_field_ty(ak, i, location) {
1070-
field_ty
1071-
} else {
1072-
// TODO(nashenas88) log span_mirbug terr??
1073-
continue;
1068+
let field_ty = match self.aggregate_field_ty(ak, i, location) {
1069+
Ok(field_ty) => field_ty,
1070+
Err(FieldAccessError::OutOfRange { field_count }) => {
1071+
span_mirbug!(
1072+
self,
1073+
rv,
1074+
"accessed field #{} but variant only has {}",
1075+
i,
1076+
field_count);
1077+
continue;
1078+
},
10741079
};
10751080
let op_ty = match op {
10761081
Operand::Consume(lv) => lv.ty(mir, tcx).to_ty(tcx),
10771082
Operand::Constant(c) => c.ty,
10781083
};
1079-
if let Err(_terr) = self.sub_types(op_ty, field_ty, location.at_successor_within_block()) {
1080-
// TODO(nashenas88) log span_mirbug terr??
1084+
if let Err(terr) = self.sub_types(op_ty, field_ty, location.at_successor_within_block()) {
1085+
span_mirbug!(
1086+
self,
1087+
rv,
1088+
"{:?} is not a subtype of {:?}: {:?}",
1089+
op_ty,
1090+
field_ty,
1091+
terr);
10811092
}
10821093
}
10831094
},

src/test/compile-fail/aggregate-rvalues-typeck.rs renamed to src/test/compile-fail/nll/reference-carried-through-struct-field.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ struct Wrap<'a> { w: &'a mut u32 }
1717
fn foo() {
1818
let mut x = 22;
1919
let wrapper = Wrap { w: &mut x };
20-
//~^ ERROR cannot assign to `x` because it is borrowed (Mir) [E0506]
21-
//~^^ ERROR cannot use `x` because it was mutably borrowed (Mir) [E0503]
2220
x += 1; //[ast]~ ERROR cannot assign to `x` because it is borrowed [E0506]
2321
//[mir]~^ ERROR cannot assign to `x` because it is borrowed (Ast) [E0506]
2422
//[mir]~^^ ERROR cannot assign to `x` because it is borrowed (Mir) [E0506]

0 commit comments

Comments
 (0)