about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-05-20 20:39:15 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-05-20 20:39:15 -0700
commitaef1a9c57b2b21f3a227ead094d4d7add6f57522 (patch)
tree53a5795f2e8ab8e9691e0536cba52e758655c9ab
parentfd88e2b7291170d0dac536130307a8cc680c8294 (diff)
downloadrust-aef1a9c57b2b21f3a227ead094d4d7add6f57522.tar.gz
rust-aef1a9c57b2b21f3a227ead094d4d7add6f57522.zip
rustc: Prevant an out of bounds access in typeck
Closes #7092
-rw-r--r--src/librustc/middle/typeck/check/method.rs18
-rw-r--r--src/test/compile-fail/issue-7092.rs22
2 files changed, 29 insertions, 11 deletions
diff --git a/src/librustc/middle/typeck/check/method.rs b/src/librustc/middle/typeck/check/method.rs
index 839e3dd080a..9e8edfccd5b 100644
--- a/src/librustc/middle/typeck/check/method.rs
+++ b/src/librustc/middle/typeck/check/method.rs
@@ -555,17 +555,13 @@ impl<'a> LookupContext<'a> {
                                            param_ty: param_ty) {
         debug!("push_inherent_candidates_from_param(param_ty={:?})",
                param_ty);
-        self.push_inherent_candidates_from_bounds(
-            rcvr_ty,
-            self.fcx
-                .inh
-                .param_env
-                .type_param_bounds
-                .get(param_ty.idx)
-                .trait_bounds
-                .as_slice(),
-            restrict_to,
-            param_numbered(param_ty.idx));
+        let i = param_ty.idx;
+        match self.fcx.inh.param_env.type_param_bounds.as_slice().get(i) {
+            Some(b) => self.push_inherent_candidates_from_bounds(
+                            rcvr_ty, b.trait_bounds.as_slice(), restrict_to,
+                            param_numbered(param_ty.idx)),
+            None => {}
+        }
     }
 
 
diff --git a/src/test/compile-fail/issue-7092.rs b/src/test/compile-fail/issue-7092.rs
new file mode 100644
index 00000000000..bcecab80758
--- /dev/null
+++ b/src/test/compile-fail/issue-7092.rs
@@ -0,0 +1,22 @@
+// Copyright 2014 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.
+
+enum Whatever {
+}
+
+fn foo(x: Whatever) {
+    match x {
+        Some(field) => field.access(),
+        //~^ ERROR: mismatched types: expected `Whatever` but found
+        //~^^ ERROR: does not implement any method in scope named `access`
+    }
+}
+
+fn main(){}