Skip to content

Commit 6ef79b0

Browse files
author
wickerwaka
committed
Fixes #16562
Detect ty_err in fixup_substs and return None instead of failing. In search_for_vtable return vtable_error in both early and non-early if fixup_substs returns None. This was asserting previously. I don't know anything about the early vs. non-early stages and whether this is significant or not. Reduced the amount of data being printed to the debug log in tydecode.rs. It was printing several megabytes of metadata. Added license text to test
1 parent b42e079 commit 6ef79b0

File tree

3 files changed

+56
-15
lines changed

3 files changed

+56
-15
lines changed

src/librustc/metadata/tydecode.rs

+19-7
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@ use std::rc::Rc;
2424
use std::str;
2525
use std::string::String;
2626
use std::uint;
27+
use std::cmp;
2728
use syntax::abi;
2829
use syntax::ast;
2930
use syntax::ast::*;
3031
use syntax::parse::token;
3132

33+
static DATA_TRUNCATE : uint = 32;
34+
3235
// Compact string representation for ty::t values. API ty_str &
3336
// parse_from_str. Extra parameters are for converting to/from def_ids in the
3437
// data buffer. Whatever format you choose should not contain pipe characters.
@@ -115,17 +118,26 @@ pub fn parse_state_from_data<'a>(data: &'a [u8], crate_num: ast::CrateNum,
115118
}
116119
}
117120

118-
fn data_log_string(data: &[u8], pos: uint) -> String {
121+
fn data_log_string(data: &[u8], pos: uint, max: uint) -> String {
119122
let mut buf = String::new();
123+
let end = match max {
124+
0u => data.len(),
125+
x => cmp::min( pos + x, data.len() )
126+
};
120127
buf.push_str("<<");
121-
for i in range(pos, data.len()) {
128+
for i in range(pos, end) {
122129
let c = data[i];
123130
if c > 0x20 && c <= 0x7F {
124131
buf.push_char(c as char);
125132
} else {
126133
buf.push_char('.');
127134
}
128135
}
136+
if end < data.len() {
137+
buf.push_str(
138+
format!( " ({} more bytes)", data.len() - end ).as_slice()
139+
);
140+
}
129141
buf.push_str(">>");
130142
buf
131143
}
@@ -142,35 +154,35 @@ pub fn parse_ty_closure_data(data: &[u8],
142154

143155
pub fn parse_ty_data(data: &[u8], crate_num: ast::CrateNum, pos: uint, tcx: &ty::ctxt,
144156
conv: conv_did) -> ty::t {
145-
debug!("parse_ty_data {}", data_log_string(data, pos));
157+
debug!("parse_ty_data {}", data_log_string(data, pos, DATA_TRUNCATE));
146158
let mut st = parse_state_from_data(data, crate_num, pos, tcx);
147159
parse_ty(&mut st, conv)
148160
}
149161

150162
pub fn parse_region_data(data: &[u8], crate_num: ast::CrateNum, pos: uint, tcx: &ty::ctxt,
151163
conv: conv_did) -> ty::Region {
152-
debug!("parse_region_data {}", data_log_string(data, pos));
164+
debug!("parse_region_data {}", data_log_string(data, pos, DATA_TRUNCATE));
153165
let mut st = parse_state_from_data(data, crate_num, pos, tcx);
154166
parse_region(&mut st, conv)
155167
}
156168

157169
pub fn parse_bare_fn_ty_data(data: &[u8], crate_num: ast::CrateNum, pos: uint, tcx: &ty::ctxt,
158170
conv: conv_did) -> ty::BareFnTy {
159-
debug!("parse_bare_fn_ty_data {}", data_log_string(data, pos));
171+
debug!("parse_bare_fn_ty_data {}", data_log_string(data, pos, DATA_TRUNCATE));
160172
let mut st = parse_state_from_data(data, crate_num, pos, tcx);
161173
parse_bare_fn_ty(&mut st, conv)
162174
}
163175

164176
pub fn parse_trait_ref_data(data: &[u8], crate_num: ast::CrateNum, pos: uint, tcx: &ty::ctxt,
165177
conv: conv_did) -> ty::TraitRef {
166-
debug!("parse_trait_ref_data {}", data_log_string(data, pos));
178+
debug!("parse_trait_ref_data {}", data_log_string(data, pos, DATA_TRUNCATE));
167179
let mut st = parse_state_from_data(data, crate_num, pos, tcx);
168180
parse_trait_ref(&mut st, conv)
169181
}
170182

171183
pub fn parse_substs_data(data: &[u8], crate_num: ast::CrateNum, pos: uint, tcx: &ty::ctxt,
172184
conv: conv_did) -> subst::Substs {
173-
debug!("parse_substs_data {}", data_log_string(data, pos));
185+
debug!("parse_substs_data {}", data_log_string(data, pos, DATA_TRUNCATE));
174186
let mut st = parse_state_from_data(data, crate_num, pos, tcx);
175187
parse_substs(&mut st, conv)
176188
}

src/librustc/middle/typeck/check/vtable.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -513,10 +513,9 @@ fn search_for_vtable(vcx: &VtableContext,
513513
is_early) {
514514
Some(ref substs) => (*substs).clone(),
515515
None => {
516-
assert!(is_early);
517516
// Bail out with a bogus answer
518517
return Some(vtable_error);
519-
}
518+
},
520519
};
521520

522521
debug!("The fixed-up substs are {} - \
@@ -565,12 +564,16 @@ fn fixup_substs(vcx: &VtableContext,
565564
let t = ty::mk_trait(tcx,
566565
id, substs,
567566
ty::region_existential_bound(ty::ReStatic));
568-
fixup_ty(vcx, span, t, is_early).map(|t_f| {
569-
match ty::get(t_f).sty {
570-
ty::ty_trait(ref inner) => inner.substs.clone(),
571-
_ => fail!("t_f should be a trait")
572-
}
573-
})
567+
match fixup_ty(vcx, span, t, is_early) {
568+
Some( t_f ) => {
569+
match ty::get(t_f).sty {
570+
ty::ty_trait(ref inner) => Some(inner.substs.clone()),
571+
ty::ty_err => None,
572+
_ => fail!("t_f should be a trait")
573+
}
574+
},
575+
None => None
576+
}
574577
}
575578

576579
fn fixup_ty(vcx: &VtableContext,

src/test/compile-fail/issue-16562.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
trait MatrixShape {}
12+
13+
struct Col<D, C> {
14+
data: D,
15+
col: C,
16+
}
17+
18+
// NB The `T` parameter is not necessary (it shouldn't be in the list), but it triggers the ICE
19+
impl<T, M: MatrixShape> Collection for Col<M, uint> {
20+
//~^ ERROR: cannot determine a type for this bounded type parameter: unconstrained type
21+
fn len(&self) -> uint {
22+
unimplemented!()
23+
}
24+
}
25+
26+
fn main() {}

0 commit comments

Comments
 (0)