Skip to content

Commit 6925c2f

Browse files
committed
---
yaml --- r: 33533 b: refs/heads/snap-stage3 c: a369a78 h: refs/heads/master i: 33531: 8d8d144 v: v3
1 parent 64359eb commit 6925c2f

File tree

7 files changed

+85
-9
lines changed

7 files changed

+85
-9
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: ed48e76e772b6684b9d5e4ce753c3f493c230d62
4+
refs/heads/snap-stage3: a369a7881f2196e359fb9d4cb20cf5d2bb0da6f8
55
refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/doc/tutorial-borrowed-ptr.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ is B, the function body. Both of the second two parameters `a` and `b`
698698
share the same lifetime, `r`, which is a lifetime parameter of
699699
`select_based_on_unit_circle()`. The caller will infer the
700700
intersection of these two lifetimes as the lifetime of the returned
701-
value, and hence the return value of `select()` will be assigned a
701+
value, and hence the return value of `shape()` will be assigned a
702702
lifetime of B. This will in turn lead to a compilation error, because
703703
`select_based_on_unit_circle()` is supposed to return a value with the
704704
lifetime `r`.

branches/snap-stage3/mk/tests.mk

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,13 @@ tidy:
141141
@$(call E, check: formatting)
142142
$(Q)find $(S)src -name '*.r[sc]' \
143143
| grep '^$(S)src/test' -v \
144-
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
144+
| xargs -n 10 python $(S)src/etc/tidy.py
145145
$(Q)find $(S)src/etc -name '*.py' \
146-
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
146+
| xargs -n 10 python $(S)src/etc/tidy.py
147147
$(Q)echo $(ALL_CS) \
148-
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
148+
| xargs -n 10 python $(S)src/etc/tidy.py
149149
$(Q)echo $(ALL_HS) \
150-
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
150+
| xargs -n 10 python $(S)src/etc/tidy.py
151151

152152
endif
153153

branches/snap-stage3/src/libstd/sort.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,6 @@ mod test_tim_sort {
921921

922922
#[test]
923923
#[should_fail]
924-
#[cfg(unix)]
925924
fn crash_test() {
926925
let rng = rand::Rng();
927926
let mut arr = do vec::from_fn(1000) |_i| {

branches/snap-stage3/src/rustc/middle/ty.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,11 @@ type ctxt =
387387
deriving_struct_methods: HashMap<ast::def_id,
388388
@~[typeck::method_origin]>,
389389

390+
// The outer vector here describes each enum variant, while the inner
391+
// nested vector describes each enum variant argument.
392+
deriving_enum_methods: HashMap<ast::def_id,
393+
@~[@~[typeck::method_origin]]>,
394+
390395
// A mapping from the def ID of a method that was automatically derived
391396
// to information about it.
392397
automatically_derived_methods: HashMap<ast::def_id, DerivedMethodInfo>,
@@ -959,6 +964,7 @@ fn mk_ctxt(s: session::Session,
959964
provided_method_sources: HashMap(),
960965
supertraits: HashMap(),
961966
deriving_struct_methods: HashMap(),
967+
deriving_enum_methods: HashMap(),
962968
automatically_derived_methods: HashMap(),
963969
automatically_derived_methods_for_impl: HashMap()}
964970
}

branches/snap-stage3/src/rustc/middle/typeck/deriving.rs

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,48 @@ impl DerivingChecker {
113113
tcx.deriving_struct_methods.insert(local_def(impl_id), field_info);
114114
}
115115

116+
fn check_deriving_for_enum(enum_def_id: def_id,
117+
enum_substs: &substs,
118+
trait_ref: @trait_ref,
119+
impl_id: node_id,
120+
impl_span: span) {
121+
let tcx = self.crate_context.tcx;
122+
let enum_methods = dvec::DVec();
123+
let variants = ty::substd_enum_variants(
124+
tcx, enum_def_id, enum_substs);
125+
for variants.each |enum_variant_info| {
126+
let variant_methods = dvec::DVec();
127+
for enum_variant_info.args.eachi |i, variant_arg_type| {
128+
match self.check_deriving_for_substructure_type(
129+
*variant_arg_type, trait_ref, impl_span) {
130+
Some(method_target_def_id) => {
131+
variant_methods.push(method_static(
132+
method_target_def_id));
133+
}
134+
None => {
135+
let trait_str = pprust::path_to_str(
136+
trait_ref.path, tcx.sess.parse_sess.interner);
137+
tcx.sess.span_err(impl_span,
138+
fmt!("cannot automatically derive \
139+
an implementation for `%s`: \
140+
argument %u of variant `%s` \
141+
does not implement the trait \
142+
`%s`",
143+
trait_str,
144+
i + 1,
145+
tcx.sess.str_of(
146+
enum_variant_info.name),
147+
trait_str));
148+
}
149+
}
150+
}
151+
enum_methods.push(@dvec::unwrap(move variant_methods));
152+
}
153+
154+
let enum_methods = @dvec::unwrap(move enum_methods);
155+
tcx.deriving_enum_methods.insert(local_def(impl_id), enum_methods);
156+
}
157+
116158
fn check_deriving(crate: @crate) {
117159
let tcx = self.crate_context.tcx;
118160
visit_crate(*crate, (), mk_simple_visitor(@{
@@ -123,8 +165,13 @@ impl DerivingChecker {
123165
let superty = ty::lookup_item_type(
124166
tcx, local_def(item.id)).ty;
125167
match ty::get(superty).sty {
126-
ty_enum(_def_id, _substs) => {
127-
// XXX: Handle enums.
168+
ty_enum(def_id, ref substs) => {
169+
self.check_deriving_for_enum(
170+
def_id,
171+
substs,
172+
trait_ref,
173+
item.id,
174+
item.span);
128175
}
129176
ty_class(def_id, ref substs) => {
130177
self.check_deriving_for_struct(
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
trait MyEq {
2+
pure fn eq(other: &self) -> bool;
3+
}
4+
5+
struct A {
6+
x: int
7+
}
8+
9+
enum B {
10+
C(A),
11+
D(A),
12+
E(A)
13+
}
14+
15+
impl B : MyEq;
16+
//~^ ERROR cannot automatically derive
17+
//~^^ ERROR cannot automatically derive
18+
//~^^^ ERROR cannot automatically derive
19+
20+
fn main() {
21+
let c = C(A { x: 15 });
22+
assert c.eq(&c);
23+
}
24+

0 commit comments

Comments
 (0)