File tree 3 files changed +36
-12
lines changed
3 files changed +36
-12
lines changed Original file line number Diff line number Diff line change @@ -242,16 +242,17 @@ fn lookup_vtable(vcx: &VtableContext,
242
242
// bounds to see if they include the trait we are looking for.
243
243
let vtable_opt = match ty:: get ( ty) . sty {
244
244
ty:: ty_param( param_ty { idx : n, ..} ) => {
245
- let type_param_bounds: & [ @ty:: TraitRef ] =
246
- vcx. param_env
247
- . type_param_bounds
248
- . get ( n)
249
- . trait_bounds
250
- . as_slice ( ) ;
251
- lookup_vtable_from_bounds ( vcx, span,
252
- type_param_bounds,
253
- param_numbered ( n) ,
254
- trait_ref)
245
+ let env_bounds = & vcx. param_env . type_param_bounds ;
246
+ if env_bounds. len ( ) > n {
247
+ let type_param_bounds: & [ @ty:: TraitRef ] =
248
+ env_bounds. get ( n) . trait_bounds . as_slice ( ) ;
249
+ lookup_vtable_from_bounds ( vcx, span,
250
+ type_param_bounds,
251
+ param_numbered ( n) ,
252
+ trait_ref)
253
+ } else {
254
+ None
255
+ }
255
256
}
256
257
257
258
ty:: ty_self( _) => {
Original file line number Diff line number Diff line change @@ -393,8 +393,9 @@ pub fn ty_to_str(cx: &ctxt, typ: t) -> ~str {
393
393
ty_param( param_ty { idx : id, def_id : did} ) => {
394
394
let ident = match cx. ty_param_defs . borrow ( ) . find ( & did. node ) {
395
395
Some ( def) => token:: get_ident ( def. ident ) . get ( ) . to_str ( ) ,
396
- // This should not happen...
397
- None => format ! ( "BUG[{:?}]" , id)
396
+ // This can only happen when a type mismatch error happens and
397
+ // the actual type has more type parameters than the expected one.
398
+ None => format ! ( "<generic \\ #{}>" , id)
398
399
} ;
399
400
if !cx. sess . verbose ( ) {
400
401
ident
Original file line number Diff line number Diff line change
1
+ // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2
+ // file at the top-level directory of this distribution and at
3
+ // http://rust-lang.org/COPYRIGHT.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6
+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7
+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8
+ // option. This file may not be copied, modified, or distributed
9
+ // except according to those terms.
10
+
11
+ // Regression test for #13466
12
+
13
+ pub fn main ( ) {
14
+ // The expected arm type `Option<T>` has one type parameter, while
15
+ // the actual arm `Result<T, E>` has two. typeck should not be
16
+ // tricked into looking up a non-existing second type parameter.
17
+ let _x: uint = match Some ( 1 u) {
18
+ //~^ ERROR mismatched types: expected `uint` but found `<generic #0>`
19
+ Ok ( u) => u, //~ ERROR mismatched types: expected `std::option::Option<uint>`
20
+ Err ( e) => fail ! ( e) //~ ERROR mismatched types: expected `std::option::Option<uint>`
21
+ } ;
22
+ }
You can’t perform that action at this time.
0 commit comments