rustc: Prevant an out of bounds access in typeck

Closes #7092
This commit is contained in:
Alex Crichton 2014-05-20 20:39:15 -07:00
parent fd88e2b729
commit aef1a9c57b
2 changed files with 29 additions and 11 deletions

View File

@ -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 => {}
}
}

View File

@ -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(){}