]> git.lizzy.rs Git - rust.git/commitdiff
Remove attributes and test comments accidentally left behind, add in span_mirbugs
authorPaul Daniel Faria <nashenas88@users.noreply.github.com>
Sat, 11 Nov 2017 21:13:23 +0000 (16:13 -0500)
committerNiko Matsakis <niko@alum.mit.edu>
Wed, 22 Nov 2017 08:51:54 +0000 (03:51 -0500)
src/librustc_mir/transform/type_check.rs
src/test/compile-fail/aggregate-rvalues-typeck.rs [deleted file]
src/test/compile-fail/nll/reference-carried-through-struct-field.rs [new file with mode: 0644]

index 7a801d887fbb016d641c671a3427e38a7266709e..96264222eaef439b7cb09bc7941bf137d17c34a5 100644 (file)
@@ -1056,28 +1056,39 @@ fn aggregate_field_ty(&mut self, ak: &Box<AggregateKind<'tcx>>, field: usize, lo
         }
     }
 
-    #[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/aggregate-rvalues-typeck.rs
deleted file mode 100644 (file)
index 99f3e46..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-// 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
diff --git a/src/test/compile-fail/nll/reference-carried-through-struct-field.rs b/src/test/compile-fail/nll/reference-carried-through-struct-field.rs
new file mode 100644 (file)
index 0000000..afde254
--- /dev/null
@@ -0,0 +1,27 @@
+// 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