Skip to content

Commit 4f9ca63

Browse files
committed
---
yaml --- r: 83920 b: refs/heads/dist-snap c: 656c8f9 h: refs/heads/master v: v3
1 parent f75fcf2 commit 4f9ca63

File tree

9 files changed

+92
-103
lines changed

9 files changed

+92
-103
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 0983ebe5310d4eb6d289f636f7ed0536c08bbc0e
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 7238d5a141745b24d2b78c1bd212974c4335f5ce
9+
refs/heads/dist-snap: 656c8f91435df99b11bfe31be73eba6d8f391870
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/librustc/middle/privacy.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,6 @@ pub fn check_crate<'mm>(tcx: ty::ctxt,
245245
method_id: def_id,
246246
name: &ident) =
247247
|span, method_id, name| {
248-
// If the method is a default method, we need to use the def_id of
249-
// the default implementation.
250-
// Having to do this this is really unfortunate.
251-
let method_id = match tcx.provided_method_sources.find(&method_id) {
252-
None => method_id,
253-
Some(source) => source.method_id
254-
};
255-
256248
if method_id.crate == local_crate {
257249
let is_private = method_is_private(span, method_id.node);
258250
let container_id = local_method_container_id(span,

branches/dist-snap/src/librustc/middle/resolve.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,13 @@ pub struct NameBindings {
510510
value_def: Option<ValueNsDef>, //< Meaning in value namespace.
511511
}
512512

513+
/// Ways in which a trait can be referenced
514+
enum TraitReferenceType {
515+
TraitImplementation, // impl SomeTrait for T { ... }
516+
TraitDerivation, // trait T : SomeTrait { ... }
517+
TraitBoundingTypeParameter, // fn f<T:SomeTrait>() { ... }
518+
}
519+
513520
impl NameBindings {
514521
/// Creates a new module in this set of name bindings.
515522
pub fn define_module(@mut self,
@@ -3554,23 +3561,7 @@ impl Resolver {
35543561

35553562
// Resolve derived traits.
35563563
for traits.iter().advance |trt| {
3557-
match self.resolve_path(trt.path, TypeNS, true,
3558-
visitor) {
3559-
None =>
3560-
self.session.span_err(trt.path.span,
3561-
"attempt to derive a \
3562-
nonexistent trait"),
3563-
Some(def) => {
3564-
// Write a mapping from the trait ID to the
3565-
// definition of the trait into the definition
3566-
// map.
3567-
3568-
debug!("(resolving trait) found trait def: \
3569-
%?", def);
3570-
3571-
self.record_def(trt.ref_id, def);
3572-
}
3573-
}
3564+
self.resolve_trait_reference(*trt, visitor, TraitDerivation);
35743565
}
35753566

35763567
for (*methods).iter().advance |method| {
@@ -3821,22 +3812,31 @@ impl Resolver {
38213812
visitor: ResolveVisitor) {
38223813
match *type_parameter_bound {
38233814
TraitTyParamBound(tref) => {
3824-
self.resolve_trait_reference(tref, visitor)
3815+
self.resolve_trait_reference(tref, visitor, TraitBoundingTypeParameter)
38253816
}
38263817
RegionTyParamBound => {}
38273818
}
38283819
}
38293820

38303821
pub fn resolve_trait_reference(@mut self,
38313822
trait_reference: &trait_ref,
3832-
visitor: ResolveVisitor) {
3823+
visitor: ResolveVisitor,
3824+
reference_type: TraitReferenceType) {
38333825
match self.resolve_path(trait_reference.path, TypeNS, true, visitor) {
38343826
None => {
3835-
let idents = self.idents_to_str(trait_reference.path.idents);
3836-
self.session.span_err(trait_reference.path.span,
3837-
fmt!("attempt to implement an unknown trait `%s`", idents));
3827+
let path_str = self.idents_to_str(trait_reference.path.idents);
3828+
3829+
let usage_str = match reference_type {
3830+
TraitBoundingTypeParameter => "bound type parameter to",
3831+
TraitImplementation => "implement",
3832+
TraitDerivation => "derive"
3833+
};
3834+
3835+
let msg = fmt!("attempt to %s a nonexistent trait `%s`", usage_str, path_str);
3836+
self.session.span_err(trait_reference.path.span, msg);
38383837
}
38393838
Some(def) => {
3839+
debug!("(resolving trait) found trait def: %?", def);
38403840
self.record_def(trait_reference.ref_id, def);
38413841
}
38423842
}
@@ -3930,7 +3930,7 @@ impl Resolver {
39303930
let original_trait_refs;
39313931
match opt_trait_reference {
39323932
Some(trait_reference) => {
3933-
self.resolve_trait_reference(trait_reference, visitor);
3933+
self.resolve_trait_reference(trait_reference, visitor, TraitImplementation);
39343934

39353935
// Record the current set of trait references.
39363936
let mut new_trait_refs = ~[];

branches/dist-snap/src/librustc/middle/trans/meth.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -641,18 +641,16 @@ pub fn vtable_id(ccx: @mut CrateContext,
641641
-> mono_id {
642642
match origin {
643643
&typeck::vtable_static(impl_id, ref substs, sub_vtables) => {
644-
let psubsts = param_substs {
645-
tys: copy *substs,
646-
vtables: Some(sub_vtables),
647-
self_ty: None,
648-
self_vtable: None
649-
};
650-
651644
monomorphize::make_mono_id(
652645
ccx,
653646
impl_id,
647+
*substs,
648+
if sub_vtables.is_empty() {
649+
None
650+
} else {
651+
Some(sub_vtables)
652+
},
654653
None,
655-
&psubsts,
656654
None)
657655
}
658656

branches/dist-snap/src/librustc/middle/trans/monomorphize.rs

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,11 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
5050
fn_id=%s, \
5151
real_substs=%s, \
5252
vtables=%s, \
53-
self_vtable=%s, \
5453
impl_did_opt=%s, \
5554
ref_id=%?)",
5655
fn_id.repr(ccx.tcx),
5756
real_substs.repr(ccx.tcx),
5857
vtables.repr(ccx.tcx),
59-
self_vtable.repr(ccx.tcx),
6058
impl_did_opt.repr(ccx.tcx),
6159
ref_id);
6260

@@ -73,16 +71,7 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
7371
for real_substs.tps.iter().advance |s| { assert!(!ty::type_has_params(*s)); }
7472
for substs.iter().advance |s| { assert!(!ty::type_has_params(*s)); }
7573
let param_uses = type_use::type_uses_for(ccx, fn_id, substs.len());
76-
77-
let psubsts = @param_substs {
78-
tys: substs,
79-
vtables: vtables,
80-
self_ty: real_substs.self_ty,
81-
self_vtable: self_vtable
82-
};
83-
84-
let hash_id = make_mono_id(ccx, fn_id, impl_did_opt,
85-
&*psubsts,
74+
let hash_id = make_mono_id(ccx, fn_id, substs, vtables, impl_did_opt,
8675
Some(param_uses));
8776
if hash_id.params.iter().any_(
8877
|p| match *p { mono_precise(_, _) => false, _ => true }) {
@@ -91,10 +80,12 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
9180

9281
debug!("monomorphic_fn(\
9382
fn_id=%s, \
94-
psubsts=%s, \
83+
vtables=%s, \
84+
substs=%s, \
9585
hash_id=%?)",
9686
fn_id.repr(ccx.tcx),
97-
psubsts.repr(ccx.tcx),
87+
vtables.repr(ccx.tcx),
88+
substs.repr(ccx.tcx),
9889
hash_id);
9990

10091
match ccx.monomorphized.find(&hash_id) {
@@ -151,8 +142,8 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
151142
ast_map::node_struct_ctor(_, i, pt) => (pt, i.ident, i.span)
152143
};
153144

154-
let mono_ty = ty::subst_tps(ccx.tcx, psubsts.tys,
155-
psubsts.self_ty, llitem_ty);
145+
let mono_ty = ty::subst_tps(ccx.tcx, substs,
146+
real_substs.self_ty, llitem_ty);
156147
let llfty = type_of_fn_from_ty(ccx, mono_ty);
157148

158149
ccx.stats.n_monos += 1;
@@ -181,6 +172,13 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
181172
lldecl
182173
};
183174

175+
let psubsts = Some(@param_substs {
176+
tys: substs,
177+
vtables: vtables,
178+
self_ty: real_substs.self_ty,
179+
self_vtable: self_vtable
180+
});
181+
184182
let lldecl = match map_node {
185183
ast_map::node_item(i@@ast::item {
186184
node: ast::item_fn(ref decl, _, _, _, ref body),
@@ -194,7 +192,7 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
194192
body,
195193
d,
196194
no_self,
197-
Some(psubsts),
195+
psubsts,
198196
fn_id.node,
199197
[]);
200198
d
@@ -204,7 +202,7 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
204202
}
205203
ast_map::node_foreign_item(i, _, _, _) => {
206204
let d = mk_lldecl();
207-
foreign::trans_intrinsic(ccx, d, i, pt, psubsts, i.attrs,
205+
foreign::trans_intrinsic(ccx, d, i, pt, psubsts.get(), i.attrs,
208206
ref_id);
209207
d
210208
}
@@ -216,7 +214,7 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
216214
match v.node.kind {
217215
ast::tuple_variant_kind(ref args) => {
218216
trans_enum_variant(ccx, enum_item.id, v, /*bad*/copy *args,
219-
this_tv.disr_val, Some(psubsts), d);
217+
this_tv.disr_val, psubsts, d);
220218
}
221219
ast::struct_variant_kind(_) =>
222220
ccx.tcx.sess.bug("can't monomorphize struct variants"),
@@ -227,13 +225,13 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
227225
// XXX: What should the self type be here?
228226
let d = mk_lldecl();
229227
set_inline_hint_if_appr(/*bad*/copy mth.attrs, d);
230-
meth::trans_method(ccx, pt, mth, Some(psubsts), d);
228+
meth::trans_method(ccx, pt, mth, psubsts, d);
231229
d
232230
}
233231
ast_map::node_trait_method(@ast::provided(mth), _, pt) => {
234232
let d = mk_lldecl();
235233
set_inline_hint_if_appr(/*bad*/copy mth.attrs, d);
236-
meth::trans_method(ccx, /*bad*/copy *pt, mth, Some(psubsts), d);
234+
meth::trans_method(ccx, /*bad*/copy *pt, mth, psubsts, d);
237235
d
238236
}
239237
ast_map::node_struct_ctor(struct_def, _, _) => {
@@ -243,7 +241,7 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
243241
/*bad*/copy struct_def.fields,
244242
struct_def.ctor_id.expect("ast-mapped tuple struct \
245243
didn't have a ctor id"),
246-
Some(psubsts),
244+
psubsts,
247245
d);
248246
d
249247
}
@@ -322,36 +320,26 @@ pub fn normalize_for_monomorphization(tcx: ty::ctxt,
322320

323321
pub fn make_mono_id(ccx: @mut CrateContext,
324322
item: ast::def_id,
323+
substs: &[ty::t],
324+
vtables: Option<typeck::vtable_res>,
325325
impl_did_opt: Option<ast::def_id>,
326-
substs: &param_substs,
327326
param_uses: Option<@~[type_use::type_uses]>) -> mono_id {
328327
// FIXME (possibly #5801): Need a lot of type hints to get
329328
// .collect() to work.
330-
let substs_iter = substs.self_ty.iter().chain_(substs.tys.iter());
331-
let precise_param_ids: ~[(ty::t, Option<@~[mono_id]>)] = match substs.vtables {
329+
let precise_param_ids: ~[(ty::t, Option<@~[mono_id]>)] = match vtables {
332330
Some(vts) => {
333331
debug!("make_mono_id vtables=%s substs=%s",
334-
vts.repr(ccx.tcx), substs.tys.repr(ccx.tcx));
335-
let self_vtables = substs.self_vtable.map(|vtbl| @~[copy *vtbl]);
336-
let vts_iter = self_vtables.iter().chain_(vts.iter());
337-
vts_iter.zip(substs_iter).transform(|(vtable, subst)| {
332+
vts.repr(ccx.tcx), substs.repr(ccx.tcx));
333+
vts.iter().zip(substs.iter()).transform(|(vtable, subst)| {
338334
let v = vtable.map(|vt| meth::vtable_id(ccx, vt));
339335
(*subst, if !v.is_empty() { Some(@v) } else { None })
340336
}).collect()
341337
}
342-
None => substs_iter.transform(|subst| (*subst, None::<@~[mono_id]>)).collect()
338+
None => substs.iter().transform(|subst| (*subst, None::<@~[mono_id]>)).collect()
343339
};
344-
345-
346340
let param_ids = match param_uses {
347341
Some(ref uses) => {
348-
// param_uses doesn't include a use for the self type.
349-
// We just say it is fully used.
350-
let self_use =
351-
substs.self_ty.map(|_| type_use::use_repr|type_use::use_tydesc);
352-
let uses_iter = self_use.iter().chain_(uses.iter());
353-
354-
precise_param_ids.iter().zip(uses_iter).transform(|(id, uses)| {
342+
precise_param_ids.iter().zip(uses.iter()).transform(|(id, uses)| {
355343
if ccx.sess.no_monomorphic_collapse() {
356344
match copy *id {
357345
(a, b) => mono_precise(a, b)

branches/dist-snap/src/test/auxiliary/trait_default_method_xc_aux.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#[allow(default_methods)];
22

3-
pub struct Something { x: int }
4-
53
pub trait A {
64
fn f(&self) -> int;
75
fn g(&self) -> int { 10 }
@@ -13,10 +11,6 @@ impl A for int {
1311
fn f(&self) -> int { 10 }
1412
}
1513

16-
impl A for Something {
17-
fn f(&self) -> int { 10 }
18-
}
19-
2014
trait B<T> {
2115
fn thing<U>(&self, x: T, y: U) -> (T, U) { (x, y) }
2216
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2013 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+
12+
trait NewTrait : SomeNonExistentTrait {}
13+
//~^ ERROR attempt to derive a nonexistent trait `SomeNonExistentTrait`
14+
15+
impl SomeNonExistentTrait for int {}
16+
//~^ ERROR attempt to implement a nonexistent trait `SomeNonExistentTrait`
17+
18+
fn f<T:SomeNonExistentTrait>() {}
19+
//~^ ERROR attempt to bound type parameter to a nonexistent trait `SomeNonExistentTrait`
20+

branches/dist-snap/src/test/run-pass/bug-7183-generics.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ fn main() {
3939
assert_eq!(Some(Some(3)).hi(), ~"something!something!hello: 3");
4040
assert_eq!(None::<int>.hi(), ~"hello - none");
4141
42-
assert_eq!(Some(None::<int>).hi(), ~"something!hello - none");
43-
assert_eq!(Some(3).hi(), ~"something!hello: 3");
42+
// These fail because of a bug in monomorphization's ID generation.
43+
//assert_eq!(Some(None::<int>).hi(), ~"something!hello - none");
44+
//assert_eq!(Some(3).hi(), ~"something!hello: 3");
4445
}

0 commit comments

Comments
 (0)